88
99from .base import BaseApi
1010
11+
1112class NoNonPaginatedVersionError (Exception ):
1213 """Raised when a non-paginated of a paginated-only method is called."""
1314
15+
1416def endpoint (endpoint_url ):
1517 """Decorator for API methods. Denotes the URL endpoint."""
18+
1619 @wrapt .decorator
1720 def wrapper (method , instance , args , kwargs ):
1821 return instance .request (endpoint_url , * method (* args , ** kwargs ))
22+
1923 return wrapper
2024
25+
2126def get_default_data (** kwargs ):
2227 """Returns a POST data dict using default values."""
2328 limit = kwargs .get ('limit' , 20 )
@@ -29,7 +34,8 @@ def get_default_data(**kwargs):
2934 raise TypeError ("`offset` must be int" )
3035 if not direction in ('asc' , 'desc' ):
3136 raise ValueError ("`direction` must be one of 'asc', 'desc'" )
32- return { 'limit' : limit , 'offset' : offset , 'direction' : direction }
37+ return {'limit' : limit , 'offset' : offset , 'direction' : direction }
38+
3339
3440class PaginatedMethod :
3541 """Object representing a method that has a POST paginated version (with
@@ -38,6 +44,7 @@ class PaginatedMethod:
3844 if it were a method. The POST version is accessed by calling the `verbose`
3945 attribute.
4046 """
47+
4148 def __init__ (self , method : Callable , verbose_only : bool = False ):
4249 self ._method = method
4350 self ._verbose_only = verbose_only
@@ -55,6 +62,7 @@ def verbose(self, *args, **kwargs):
5562 data = get_default_data (** kwargs )
5663 return self .__call__ (* args , data = data , __verbose = True )
5764
65+
5866class Api (BaseApi ):
5967 """API version 1"""
6068
@@ -64,14 +72,18 @@ def __init__(self, *args):
6472 super ().__init__ (* args )
6573 self .pages_since = PaginatedMethod (self ._pages_since )
6674 self .page_revisions = PaginatedMethod (self ._page_revisions )
67- self .forum_threads_since = PaginatedMethod (self ._forum_threads_since ,
68- True )
75+ self .forum_threads_since = PaginatedMethod (
76+ self ._forum_threads_since , True
77+ )
6978 self .thread_posts = PaginatedMethod (self ._thread_posts )
70- self .thread_posts_since = PaginatedMethod (self ._thread_posts_since ,
71- True )
79+ self .thread_posts_since = PaginatedMethod (
80+ self ._thread_posts_since , True
81+ )
7282 self .wikidotuser_pages = PaginatedMethod (self ._wikidotuser_pages )
7383 self .wikidotuser_posts = PaginatedMethod (self ._wikidotuser_posts )
74- self .wikidotuser_revisions = PaginatedMethod (self ._wikidotuser_revisions )
84+ self .wikidotuser_revisions = PaginatedMethod (
85+ self ._wikidotuser_revisions
86+ )
7587 self .tags_pages = PaginatedMethod (self ._tags_pages , True )
7688
7789 def verbose (self , method : Callable , * args , ** kwargs ):
@@ -107,8 +119,9 @@ def paginated_generator():
107119 offset : int = data ['offset' ]
108120 direction : str = data ['direction' ]
109121 while True :
110- result = method .verbose (* args , limit = limit , offset = offset ,
111- direction = direction )
122+ result = method .verbose (
123+ * args , limit = limit , offset = offset , direction = direction
124+ )
112125 yield result
113126 if length < data ['limit' ]:
114127 return
@@ -262,14 +275,18 @@ def tag_pages(self, tag: str):
262275 return tag , None
263276
264277 @endpoint ("tag/pages" )
265- def _tags_pages (self , tags : Union [List [int ], List [str ]], operator : str = 'and' , * , data ):
278+ def _tags_pages (
279+ self , tags : Union [List [int ], List [str ]], operator : str = 'and' , * , data
280+ ):
266281 """
267282 str[] `tags`: A list of tag names.
268283 int[] `tags`: A list of SCUTTLE tag IDs.
269284 str `operator`: 'and' or 'or'; defines how tags are combined.
270285 """
271286 if isinstance (tags , str ):
272- raise TypeError ("`tags` must be a list of at least one tag; use tag_pages() for a single tag name" )
287+ raise TypeError (
288+ "`tags` must be a list of at least one tag; use tag_pages() for a single tag name"
289+ )
273290 data ['operator' ] = operator
274291 if all (isinstance (tag , str ) for tag in tags ):
275292 data ['names' ] = tags
0 commit comments