6 Represents a collection of items that can be queried via the API. This is
7 an abstract base class that should be extended
10 TIMESTAMP = re.compile(r"[0-9]{4}-?[0-9]{2}-?[0-9]{2}T?" +
11 r"[0-9]{2}:?[0-9]{2}:?[0-9]{2}Z?")
13 A regular expression for matching the API's timestamp format.
16 DIRECTIONS = {'newer', 'older'}
18 A set of potential direction names.
21 def __init__(self, session):
24 session : `mw.api.Session`
25 An api session to use for post & get.
27 self.session = session
29 def _check_direction(self, direction):
33 direction = str(direction)
35 assert direction in {None} | self.DIRECTIONS, \
36 "Direction must be one of {0}".format(self.DIRECTIONS)
40 def _check_timestamp(self, timestamp):
44 timestamp = str(timestamp)
46 if not self.TIMESTAMP.match(timestamp):
48 "{0} is not formatted like ".format(repr(timestamp)) +
49 "a MediaWiki timestamp."
54 def _items(self, items, none=True, levels=None, type=lambda val: val):
56 if none and items is None:
59 items = {str(type(item)) for item in items}
61 if levels is not None:
62 levels = {str(level) for level in levels}
64 assert len(items - levels) == 0, \
65 "items {0} not in levels {1}".format(
66 items - levels, levels)
68 return "|".join(items)