X-Git-Url: https://projects.mako.cc/source/mw/blobdiff_plain/fb328c2757462c9a7ea8ee85075b5c1b68e5d396..a3beb96fcd7fb3397867e72f842cc6784c689a82:/src/mw/api.py diff --git a/src/mw/api.py b/src/mw/api.py index 135c2a1..0946782 100644 --- a/src/mw/api.py +++ b/src/mw/api.py @@ -1,6 +1,6 @@ ### # mw - VCS-like nonsense for MediaWiki websites -# Copyright (C) 2009 Ian Weller +# Copyright (C) 2010 Ian Weller # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -13,8 +13,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# with this program. If not, see . ### import cookielib @@ -24,7 +23,9 @@ from StringIO import StringIO import urllib import urllib2 + class API(object): + def __init__(self, api_url): self.api_url = api_url self.cookiejar = cookielib.CookieJar() @@ -43,7 +44,10 @@ class API(object): data = gzipper.read() else: data = response.read() - return json.loads(data) + the_data = json.loads(data) + if 'error' in the_data.keys(): + raise APIError(the_data['error']['info']) + return def limits(self, low, high): if self._high_limits == None: @@ -56,3 +60,24 @@ class API(object): return high else: return low + + +class APIError(Exception): + + def __init__(self, info): + self.info = info + + def __str__(self): + return self.info + + +def pagename_to_filename(name): + name = name.replace(' ', '_') + name = name.replace('/', '!') + return name + + +def filename_to_pagename(name): + name = name.replace('!', '/') + name = name.replace('_', ' ') + return name