Finished initial translation of tweepy's documents to Korean.
authorpinkrabbit412 <pinkrabbit412@daum.net>
Tue, 19 Nov 2019 15:30:30 +0000 (00:30 +0900)
committerpinkrabbit412 <pinkrabbit412@daum.net>
Tue, 19 Nov 2019 15:30:30 +0000 (00:30 +0900)
Information image file named 'How to add translated documents' has uploaded to tweepy discord.

docs/en_US/.gitignore
docs/en_US/conf.py
docs/en_US/make.bat
docs/ko_KR/TRANSLATORS_ko_KR.txt [new file with mode: 0644]
tweepy/binder.py
tweepy/cursor.py
tweepy/parsers.py

index 9c5f57827018f6a0435036d9515314e34604b9fe..e35d8850c9688b1ce82711694692cc574a799396 100644 (file)
@@ -1 +1 @@
-_build
\ No newline at end of file
+_build
index ed8c909197386629a7d34096a506704d33597c8c..7c121f66ccd8df1187c4c25254ba60fde94e97e9 100644 (file)
@@ -56,8 +56,7 @@ release = __version__
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
-locale_dirs = ['locales']
-language = None
+#language = None
 
 # There are two options for replacing |today|: either, you set today to some
 # non-false value, then it is used:
index 1a93dda1bea778ead553092c251e3c19dbd9ebe1..10adbcd817741353e5ee9fa7c27624b6fd3ac645 100644 (file)
@@ -9,8 +9,6 @@ if NOT "%PAPER%" == "" (
        set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
 )
 
-pause
-
 if "%1" == "" goto help
 
 if "%1" == "help" (
@@ -113,4 +111,3 @@ results in %BUILDDIR%/doctest/output.txt.
 )
 
 :end
-pause
diff --git a/docs/ko_KR/TRANSLATORS_ko_KR.txt b/docs/ko_KR/TRANSLATORS_ko_KR.txt
new file mode 100644 (file)
index 0000000..d55ba6f
--- /dev/null
@@ -0,0 +1,16 @@
+# TRANSLATORS of tweepy's documents.
+# Language: Korean (Korea, Republic of)
+
+# Please write down your name at below,
+# <GitHub Username> (<@GitHub ID>)
+# <GitHub Profile URL> forms.
+# If you don't have Username, please write GitHub ID twice.
+
+악동분홍토끼(@pinkrabbit412)
+https://github.com/pinkrabbit412
+
+thdkrhk99 (@thdkrhk99)
+https://github.com/thdkrhk99
+
+ifeve (@ifeve)
+https://github.com/ifeve
\ No newline at end of file
index 7d352a6ac0451bc02c4d5444b1c651a2bb8cff10..846cfbf35ed76ab4206e46038fd9b9b1862cb50d 100644 (file)
@@ -55,6 +55,7 @@ def bind_api(**config):
                                                  api.wait_on_rate_limit)
             self.wait_on_rate_limit_notify = kwargs.pop('wait_on_rate_limit_notify',
                                                         api.wait_on_rate_limit_notify)
+            self.return_cursors = kwargs.pop('return_cursors', False)
             self.parser = kwargs.pop('parser', api.parser)
             self.session.headers = kwargs.pop('headers', {})
             self.build_parameters(args, kwargs)
@@ -233,7 +234,8 @@ def bind_api(**config):
                     raise TweepError(error_msg, resp, api_code=api_error_code)
 
             # Parse the response payload
-            result = self.parser.parse(self, resp.text)
+            self.return_cursors = self.return_cursors or 'cursor' in self.session.params
+            result = self.parser.parse(self, resp.text, return_cursors=self.return_cursors)
 
             # Store result into cache if one is available.
             if self.use_cache and self.api.cache and self.method == 'GET' and result:
@@ -253,7 +255,10 @@ def bind_api(**config):
 
     # Set pagination mode
     if 'cursor' in APIMethod.allowed_param:
-        _call.pagination_mode = 'cursor'
+        if APIMethod.payload_type == 'direct_message':
+            _call.pagination_mode = 'dm_cursor'
+        else:
+            _call.pagination_mode = 'cursor'
     elif 'max_id' in APIMethod.allowed_param:
         if 'since_id' in APIMethod.allowed_param:
             _call.pagination_mode = 'id'
index 1803c37406969dc6e3741acd77aaa96b8eea4736..2a3d950ea0d30d8923027145a56bc34e5ca8504d 100644 (file)
@@ -13,6 +13,8 @@ class Cursor(object):
         if hasattr(method, 'pagination_mode'):
             if method.pagination_mode == 'cursor':
                 self.iterator = CursorIterator(method, *args, **kwargs)
+            elif method.pagination_mode == 'dm_cursor':
+                self.iterator = DMCursorIterator(method, *args, **kwargs)
             elif method.pagination_mode == 'id':
                 self.iterator = IdIterator(method, *args, **kwargs)
             elif method.pagination_mode == 'page':
@@ -87,6 +89,28 @@ class CursorIterator(BaseIterator):
         return data
 
 
+class DMCursorIterator(BaseIterator):
+
+    def __init__(self, method, *args, **kwargs):
+        BaseIterator.__init__(self, method, *args, **kwargs)
+        self.next_cursor = self.kwargs.pop('cursor', None)
+        self.page_count = 0
+
+    def next(self):
+        if self.next_cursor == -1 or (self.limit and self.page_count == self.limit):
+            raise StopIteration
+        data = self.method(cursor=self.next_cursor, return_cursors=True, *self.args, **self.kwargs)
+        self.page_count += 1
+        if isinstance(data, tuple):
+            data, self.next_cursor = data
+        else:
+            self.next_cursor = -1
+        return data
+
+    def prev(self):
+        raise TweepError('This method does not allow backwards pagination')
+
+
 class IdIterator(BaseIterator):
 
     def __init__(self, method, *args, **kwargs):
@@ -193,6 +217,8 @@ class ItemIterator(BaseIterator):
         if self.current_page is None or self.page_index == len(self.current_page) - 1:
             # Reached end of current page, get the next page...
             self.current_page = self.page_iterator.next()
+            while len(self.current_page) == 0:
+                self.current_page = self.page_iterator.next()
             self.page_index = -1
         self.page_index += 1
         self.num_tweets += 1
index 70fd978ea62d6929dcdf274b25c411c6eae0aef8..7d09f636d723bea2cb496fa8a7e5b2f3d8a184ab 100644 (file)
@@ -10,7 +10,7 @@ from tweepy.models import ModelFactory
 
 class Parser(object):
 
-    def parse(self, method, payload):
+    def parse(self, method, payload, *args, **kwargs):
         """
         Parse the response payload and return the result.
         Returns a tuple that contains the result data and the cursors
@@ -32,7 +32,7 @@ class RawParser(Parser):
     def __init__(self):
         pass
 
-    def parse(self, method, payload):
+    def parse(self, method, payload, *args, **kwargs):
         return payload
 
     def parse_error(self, payload):
@@ -43,20 +43,20 @@ class JSONParser(Parser):
 
     payload_format = 'json'
 
-    def parse(self, method, payload):
+    def parse(self, method, payload, return_cursors=False):
         try:
             json = json_lib.loads(payload)
         except Exception as e:
             raise TweepError('Failed to parse JSON payload: %s' % e)
 
-        needs_cursors = 'cursor' in method.session.params
-        if needs_cursors and isinstance(json, dict) \
-                and 'previous_cursor' in json \
-                and 'next_cursor' in json:
-            cursors = json['previous_cursor'], json['next_cursor']
-            return json, cursors
-        else:
-            return json
+        if return_cursors and isinstance(json, dict):
+            if 'next_cursor' in json:
+                if 'previous_cursor' in json:
+                    cursors = json['previous_cursor'], json['next_cursor']
+                    return json, cursors
+                else:
+                    return json, json['next_cursor']
+        return json
 
     def parse_error(self, payload):
         error_object = json_lib.loads(payload)
@@ -79,7 +79,7 @@ class ModelParser(JSONParser):
         JSONParser.__init__(self)
         self.model_factory = model_factory or ModelFactory
 
-    def parse(self, method, payload):
+    def parse(self, method, payload, return_cursors=False):
         try:
             if method.payload_type is None:
                 return
@@ -88,7 +88,7 @@ class ModelParser(JSONParser):
             raise TweepError('No model for this payload type: '
                              '%s' % method.payload_type)
 
-        json = JSONParser.parse(self, method, payload)
+        json = JSONParser.parse(self, method, payload, return_cursors=return_cursors)
         if isinstance(json, tuple):
             json, cursors = json
         else: