diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2013-05-20 19:28:35 +0200 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2013-05-20 19:35:16 +0200 |
commit | 68910f6797e7e5a2e0d8e5b966861f9df0523e42 (patch) | |
tree | b4d99995d8d6584dfbc4f57382612dfae762a280 /mediagoblin/plugins/piwigo/tools.py | |
parent | d6c3375a781efd13a185b67e0f084c460c1e3cc6 (diff) | |
download | mediagoblin-68910f6797e7e5a2e0d8e5b966861f9df0523e42.tar.lz mediagoblin-68910f6797e7e5a2e0d8e5b966861f9df0523e42.tar.xz mediagoblin-68910f6797e7e5a2e0d8e5b966861f9df0523e42.zip |
piwigo: Add PwgError class.
This allows to return piwigo xml errors.
Those can also be matched into html error codes.
Diffstat (limited to 'mediagoblin/plugins/piwigo/tools.py')
-rw-r--r-- | mediagoblin/plugins/piwigo/tools.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mediagoblin/plugins/piwigo/tools.py b/mediagoblin/plugins/piwigo/tools.py index f060e9f8..30bb4b97 100644 --- a/mediagoblin/plugins/piwigo/tools.py +++ b/mediagoblin/plugins/piwigo/tools.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +from collections import namedtuple import logging import six @@ -27,6 +28,9 @@ from mediagoblin.tools.response import Response _log = logging.getLogger(__name__) +PwgError = namedtuple("PwgError", ["code", "msg"]) + + class PwgNamedArray(list): def __init__(self, l, item_name, as_attrib=()): self.item_name = item_name @@ -74,9 +78,17 @@ def _fill_element(el, data): def response_xml(result): r = ET.Element("rsp") r.set("stat", "ok") - _fill_element(r, result) + status = None + if isinstance(result, PwgError): + r.set("stat", "fail") + err = ET.SubElement(r, "err") + err.set("code", str(result.code)) + err.set("msg", result.msg) + status = result.code + else: + _fill_element(r, result) return Response(ET.tostring(r, encoding="utf-8", xml_declaration=True), - mimetype='text/xml') + mimetype='text/xml', status=status) class CmdTable(object): |