home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import urllib2
- import libxml2
- from lphelper import unicode_for_libxml2
-
- def noerr(ctx, str):
- pass
-
- libxml2.registerErrorHandler(noerr, None)
-
- class LaunchpadError(Exception):
-
- def __str__(self):
- return 'Something went wrong'
-
-
- def __repr__(self):
- t = self.__class__.__name__
- if t == 'LaunchpadError':
- t = ''
- else:
- t = ' %s' % t
- return '<LaunchpadError%s>' % t
-
-
- def value(self):
-
- try:
- return self.msg
- except:
- return None
-
-
- value = property(value)
-
-
- class LaunchpadURLError(LaunchpadError, urllib2.URLError):
-
- def __init__(self, msg, url = None):
- self.msg = msg
- self.url = url
-
-
- def __str__(self):
- if not self.url:
- pass
- return '\n * message: %s\n * url: %s' % (self.msg, 'unknown')
-
-
-
- class LaunchpadInternalServerError(LaunchpadError):
-
- def __init__(self, url):
- self.url = url
-
-
- def __str__(self):
- return '\n * message: An internal server error occurred. Please try again later.\n * url: %s' % self.url
-
-
-
- class LaunchpadLoginError(LaunchpadError):
-
- def __init__(self, url, msg = ''):
- self.url = url
- self.msg = msg
-
-
- def __str__(self):
- if self.msg:
- m = ' %s' % self.msg.strip()
- else:
- m = ''
- return '\n * message: To continue, you must log in to Launchpad.%s\n * url: %s' % (m, self.url)
-
-
-
- class LaunchpadLoginFailed(LaunchpadLoginError):
-
- def __init__(self, url):
- self.url = url
-
-
- def __str__(self):
- return 'Login failed: The email address and password do not match.\n * url: %s' % self.url
-
-
-
- class LaunchpadNotAllowedError(LaunchpadLoginError):
- pass
-
-
- class PythonLaunchpadBugsError(Exception):
-
- def __str__(self):
- return 'Something went wrong'
-
-
- def __repr__(self):
- t = self.__class__.__name__
- if t == 'PythonLaunchpadBugsError':
- t = ''
- else:
- t = ' %s' % t
- return '<PythonLaunchpadBugsError%s>' % t
-
-
-
- class PythonLaunchpadBugsValueError(PythonLaunchpadBugsError, ValueError):
-
- def __init__(self, values = { }, url = '', msg = ''):
- self.values = values
- if not url:
- pass
- self.url = 'unknown'
- self.msg = msg
-
-
- def __str__(self):
- errors = ''
- msg = ''
- if self.values:
- l = len(self.values)
- if l == 1:
- errors = '\nThere is %s error\n' % l
- else:
- errors = '\nThere are %s errors\n' % len(self.values)
- for i, k in self.values.iteritems():
- errors += ' * %s: %s\n' % (i, k)
-
- errors.rstrip('\n')
-
- if self.msg:
- msg = '\n%s' % self.msg
-
- r = 'There is a problem with the information you entered. Please fix it and try again.%s%s' % (errors, msg)
- return r.rstrip('\n')
-
-
-
- class PythonLaunchpadBugsIOError(PythonLaunchpadBugsError, IOError):
-
- def __init__(self, msg):
- self.msg = msg
-
-
- def __str__(self):
- return self.msg
-
-
-
- class PythonLaunchpadBugsRuntimeError(PythonLaunchpadBugsError, RuntimeError):
-
- def __init__(self, msg):
- self.msg = msg
-
-
- def __str__(self):
- msg = ' * %s' % self.msg.lstrip(' *')
- return 'The following error occured while using python-launchpad-bugs. Please report this error with as much information as possible.\n\t%s' % msg
-
-
-
- class PythonLaunchpadBugsParsingError(PythonLaunchpadBugsError, AssertionError):
-
- def __init__(self, path, url = None):
- self.path = path
- if not url:
- pass
- self.url = 'unknown url'
-
-
- def __str__(self):
- return 'Error while parsing %s (%s)' % (self.path, self.url)
-
-
-
- class PythonLaunchpadBugsXMLParsingError(PythonLaunchpadBugsParsingError):
-
- def __init__(self, path, xml, url = None):
- PythonLaunchpadBugsParsingError.__init__(self, path, url)
- self.xml = xml
-
-
- def __str__(self):
- return 'Wrong XPath-Expr while parsing %s (%s)' % (self.path, self.url)
-
-
-
- def choose_LaunchpadError(value, url):
- if value == 'login failed':
- return LaunchpadLoginError(url)
- if value == 500:
- return LaunchpadInternalServerError(url)
- if value == 404:
- return LaunchpadURLError('Page not found', url)
- if value == 403:
- return LaunchpadNotAllowedError(url)
- return LaunchpadURLError(value, url)
-
- (UNKNOWNERROR, VALUEERROR, RUNTIMEERROR) = range(3)
-
- def _parse_page(text):
- guess_type = UNKNOWNERROR
- errors = { }
- t = libxml2.htmlParseDoc(unicode_for_libxml2(text), 'UTF-8')
- e = t.xpathEval('//tr[@class="error"]')
- for i in e:
- msg = ''
- m = i.xpathEval('td/div[@class="message"]')
- if m:
- msg = m[0].content
-
- m = i.xpathEval('td/div/input | td/div/textarea')
- if not m:
- raise AssertionError
- val = m[0].prop('name')
- errors[val] = msg
-
- return (guess_type, errors)
-
-
- def choose_pylpbugsError(error_type = UNKNOWNERROR, values = { }, text = '', url = ''):
- errors = { }
- if text:
- (guess_type, errors) = _parse_page(text)
- if not error_type:
- error_type = guess_type
-
-
- values.update(errors)
- if error_type == VALUEERROR:
- return PythonLaunchpadBugsValueError(values, url)
- if error_type == RUNTIMEERROR and msg:
- return PythonLaunchpadBugsRuntimeError(msg)
- return PythonLaunchpadBugsError
-
-
- def parse_error(cond, path, xml = None, url = '', msg = '', error_type = UNKNOWNERROR):
- if not cond:
- if error_type:
- if error_type == VALUEERROR:
- raise PythonLaunchpadBugsValueError(url = url, msg = msg)
- error_type == VALUEERROR
- if error_type == RUNTIMEERROR and msg:
- raise PythonLaunchpadBugsRuntimeError(msg)
- msg
- raise PythonLaunchpadBugsError
- error_type
- if xml is None:
- raise PythonLaunchpadBugsParsingError(path, url)
- xml is None
- raise PythonLaunchpadBugsXMLParsingError(path, xml, url)
- cond
-
-