-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for tweepy.parsers
#723
Open
chuckoy
wants to merge
1
commit into
tweepy:master
Choose a base branch
from
chuckoy:master
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -814,3 +814,83 @@ example, ``tweepy.error.TweepError`` is available as ``tweepy.TweepError``. | |
|
||
Inherits from :exc:`TweepError`, so ``except TweepError`` will | ||
catch a ``RateLimitError`` too. | ||
|
||
:mod:`tweepy.parsers` --- Parsers | ||
================================= | ||
|
||
Any :class:`Parser` object (and those that inherit from it) should be assigned to an instance of ``tweepy.API``. | ||
|
||
.. class:: Parser() | ||
|
||
This class is the base class from which all other parsers inherit from. Any inheriting class should implement its two methods (i.e., :func:`parse(method, payload)` and :func:`parse_error(payload)`). | ||
|
||
.. method:: Parser.parse(method, payload) | ||
|
||
Abstract method to be implemented by inheriting classes. Throws a ``NotImplementedError`` when not overriden. | ||
|
||
.. method:: Parser.parse(payload) | ||
|
||
Abstract method to be implemented by inheriting classes. Throws a ``NotImplementedError`` when not overriden. | ||
|
||
.. class:: RawParser() | ||
|
||
Bases: :class:`Parser` | ||
|
||
An implementation of :class:`Parser` that simply returns the payload without doing any processing on the payload. | ||
|
||
.. method:: RawParser.parse(method, payload) | ||
|
||
Returns ``payload`` without doing anything. | ||
|
||
:param method: Not used in this implementation. | ||
:param payload: The message passed to the parser to process. | ||
|
||
:rtype: Whatever the class of ``payload`` was upon being passed. | ||
|
||
.. method:: RawParser.parse_error(payload) | ||
|
||
Returns ``payload`` without doing anything. | ||
|
||
:param payload: The message passed to the parser to process. | ||
|
||
:rtype: Whatever the class of ``payload`` was upon being passed. | ||
|
||
.. class:: JSONParser() | ||
|
||
Bases: :class:`Parser` | ||
|
||
An implementation of :class:`Parser`` used for parsing :class:`JSON` payloads. It tries to import the :class:`simplejson` library. If it fails, it imports the :class:`json` library. If that fails as well, it will try to import the :class:`simplejson` library from ``django.utils``. If that fails too, an :exc:`ImportError` is thrown. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This description needs to be updated as simplejson isn't used anymore. |
||
|
||
.. method:: JSONParser.parse(method, payload) | ||
|
||
Returns the ``payload`` object after being parsed by the :class:`JSON` library imported during construction. If 'cursor' was set in the session's parameters (i.e., paginated results), it will return the tuple ``(payload, cursors)``, where ``cursors`` is itself a tuple containing ``(previous_cursor, next_cursor)``, to be used for navigating the results. Raises a :exc:`TweepError` if the :class:`JSON` library fails to parse ``payload``. | ||
|
||
:param method: Not used in this implementation. | ||
:param payload: A :class:`JSON`-encoded message to be parsed by the method. | ||
|
||
:rtype: Depending on the payload, either a :class:`JSON`-decoded message or a tuple containing the :class:`JSON`-decoded message and the ``cursors`` used for navigating. | ||
|
||
.. method:: JSONParser.parse_error(payload) | ||
|
||
Returns a tuple containing the reason for the error and the error code thrown by the :class:`API` to be used for debugging. If there is more than one error code, the error codes will be grouped as a list. | ||
|
||
:param payload: A :class:`JSON`-encoded :class:`dict` containing the error message and code. | ||
|
||
:rtype: A tuple | ||
|
||
.. class:: ModelParser(model_factory=None) | ||
|
||
Bases: :class:`JSONParser` | ||
|
||
An implementation of :class:`Parser` used to variably parse a ``payload`` depending on which :class:`Model`'s :func:`parse()` method is appropriate. | ||
|
||
:param model_factory: The factory to be used for creating instances of model. Defaults to :class:`ModelFactory`. | ||
|
||
.. method:: ModelParser.parse(method, payload) | ||
|
||
Returns the ``payload`` object after being parsed first by the :class:`JSON` library imported during construction and then by the :func:`parse()` method of the model specified in ``method.payload_type`` if ``method.payload_list`` is not set. If ``method.payload_list`` is set, the function instead parses it with the :func:`parse_list()` method of the model. Returns the result if ``cursors`` was not set but returns a tuple of ``(result, cursors)`` if it was set. | ||
|
||
:param method: Specifies which model of the model_factory's :func:`parse()` method to call via ``method.payload_type`` and whether or not the payload is a list via ``method.payload_list`` | ||
:param payload: A :class:`JSON`-encoded message to be parsed by the method. | ||
|
||
:rtype Depends on the result returned by the model specified by :func:`method.payload_type.parse()` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.