1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
import re
class WikibaseException(Exception):
"""Generic base class for Wikibase API errors"""
def __init__(self, err):
self.error = err
def __repr__(self):
return self.__unicode__()
def __str__(self):
return self.__unicode__()
def __unicode__(self):
return self.error
class WikibaseAccountError(WikibaseException):
def __init__(self, user, error):
self.user = user
self.error = error
def __unicode__(self):
return "User '%s' had error: %s" % (self.user, self.error)
class WikibaseAPIError(WikibaseException):
def __init__(self, code, info, action):
self.code = code
self.info = info
self.action = action
def __unicode__(self):
return "Wikibase server returned error for action '%s': %s" % (
self.action, self.code)
class MissingEntityError(WikibaseException):
def __init__(self, id=None, title=None, info=None):
self.what = "Entity"
self.id = id
self.title = title
if info:
found_id = re.search("\(Invalid id: (.*)\)", info)
if found_id:
self.id = found_id.groups()[0]
found_title = re.search("\(Invalid title: (.*)\)", info)
if found_title:
self.title = found_title.groups()[0]
def __unicode__(self):
if self.id:
return "Couldn't find %s with id: %s" % (self.what, self.id)
elif self.title:
return "Couldn't find %s with title: %s" % (self.what, self.title)
else:
return "Couldn't find %s (unknown)" % self.what
class MissingItemError(MissingEntityError):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.what = "Item"
class MissingPropertyError(MissingEntityError):
pass
class APITimeoutError(WikibaseException):
def __init__(self, query):
self.query
def __unicode__(self):
return "HTTP (or HTTPS) request timed out: %s" % self.query
|