1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from werkzeug
.exceptions
import MethodNotAllowed
20 from werkzeug
.wrappers
import BaseResponse
22 from mediagoblin
.meddleware
.csrf
import csrf_exempt
23 from mediagoblin
.tools
.response
import render_404
24 from .tools
import CmdTable
, PwgNamedArray
, response_xml
27 _log
= logging
.getLogger(__name__
)
30 @CmdTable("pwg.session.login", True)
31 def pwg_login(request
):
32 username
= request
.form
.get("username")
33 password
= request
.form
.get("password")
34 _log
.info("Login for %r/%r...", username
, password
)
35 _log
.warn("login: %s %r %r", request
.method
,
36 request
.args
, request
.form
)
40 @CmdTable("pwg.session.logout")
41 def pwg_logout(request
):
46 @CmdTable("pwg.getVersion")
47 def pwg_getversion(request
):
48 _log
.info("getversion")
52 @CmdTable("pwg.categories.getList")
53 def pwg_categories_getList(request
):
54 catlist
= ({'id': -29711},)
56 'categories': PwgNamedArray(
74 if request
.method
not in ("GET", "POST"):
75 _log
.error("Method %r not supported", request
.method
)
76 raise MethodNotAllowed()
78 func
= CmdTable
.find_func(request
)
80 _log
.warn("wsphp: Unhandled %s %r %r", request
.method
,
81 request
.args
, request
.form
)
82 return render_404(request
)
84 result
= func(request
)
86 if isinstance(result
, BaseResponse
):
89 return response_xml(result
)