pydu/docs/compat.rst

82 lines
1.8 KiB
ReStructuredText
Raw Normal View History

2017-11-05 04:00:49 +00:00
Compat
------
2017-11-02 14:53:10 +00:00
2017-11-18 02:27:14 +00:00
.. py:data:: pydu.compat.PY2
Specify current Python interpreter is Python 2 or 3.
2017-12-07 14:20:56 +00:00
.. py:function:: pydu.compat.urlib(base, url, allow_fragments=True)
Same to ``urllib`` on PY2 or ``urllib.request`` on PY3.
.. py:function:: pydu.compat.urlparse(base, url, allow_fragments=True)
Same to ``urlparse`` on PY2 or ``urllib.parse`` on PY3.
2017-11-18 02:27:14 +00:00
.. py:function:: pydu.compat.urljoin(base, url, allow_fragments=True)
Same to ``urlparse.urljoin`` on PY2 or ``urllib.parse.urljoin`` on PY3.
.. py:function:: pydu.compat.iterkeys(d)
Return an iter object of dictionary keys.
.. py:function:: pydu.compat.itervalues(d)
Return an iter object of dictionary values.
.. py:function:: pydu.compat.iteritems(d)
Return an iter object of dictionary items.
.. py:data:: pydu.compat.text_type
The text type is ``unicode`` on PY2 or ``str`` on PY3.
.. py:data:: pydu.compat.string_types
The string types are ``(str, unicode)`` on PY2 or ``(str,)`` on PY3.
.. py:data:: pydu.compat.strbytes_types
The strbytes(string bytes) types are ``(str, unicode, bytes)`` on PY2 or ``(str, bytes)`` on PY3.
2017-11-18 02:27:14 +00:00
.. py:data:: pydu.compat.numeric_types
The numeric types are ``(int, long)`` on PY2 or ``(int,)`` on PY3.
2017-12-14 11:58:15 +00:00
.. py:function:: pydu.compat.imap(function, sequence, *sequence_1)
2017-11-18 02:27:14 +00:00
Same to ``itertools.imap`` on PY2 or ``map`` on PY3.
2017-12-14 11:57:35 +00:00
.. py:function:: pydu.compat.cmp(x, y)
2017-12-07 14:20:56 +00:00
Same to ``cmp`` on PY2, but implement on PY3.
2017-11-18 02:27:14 +00:00
.. py:function:: pydu.compat.has_next_attr(x)
An implementation independent way of checking for next attribute.
2017-11-12 18:25:30 +00:00
.. py:function:: pydu.compat.is_iterable(x)
2017-11-02 14:53:10 +00:00
An implementation independent way of checking for iterables.
2017-11-05 04:05:15 +00:00
>>> from pydu.compat import is_iterable
2017-11-02 14:53:10 +00:00
>>> is_iterable([])
True
>>> is_iterable(1)
False