pydu/docs/index.rst

164 lines
3.1 KiB
ReStructuredText
Raw Normal View History

2017-10-06 15:59:14 +00:00
.. pydu documentation master file, created by
2017-10-06 15:45:29 +00:00
sphinx-quickstart on Fri Oct 6 23:05:59 2017.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
2017-10-06 15:59:14 +00:00
pydu documentation
2017-10-06 15:45:29 +00:00
===================
About
-----
2017-10-06 15:59:14 +00:00
**pydu** (python library) is a library of useful data structures and utils
2017-10-06 15:45:29 +00:00
for Python 2 and 3, which collected from open source projects and created by
contributors.
It is with Python versions from **2.7 to 3.6**.
2017-10-06 15:59:14 +00:00
The pydu documentation you're reading is distributed as a single HTML page.
2017-10-06 15:45:29 +00:00
Data Structures
===============
Dict
----
2017-10-06 15:59:14 +00:00
.. class:: pydu.structures.AttrDict(seq=None, **kwargs)
2017-10-06 15:45:29 +00:00
A AttrDict object is like a dictionary except `obj.foo` can be used
in addition to `obj['foo']`.
2017-10-06 15:59:14 +00:00
>>> from pydu.structures import AttrDict
>>> o = AttrDict(a=1)
o.a
1
>>> o['a']
1
>>> o.a = 2
>>> o['a']
2
>>> del o.a
>>> o.a
Traceback (most recent call last):
...
AttributeError: 'a'
>>> from pydu.structures import AttrDict
>>> o = AttrDict(a=1)
o.a
1
>>> o['a']
1
>>> o.a = 2
>>> o['a']
2
>>> del o.a
>>> o.a
Traceback (most recent call last):
...
AttributeError: 'a'
>>> from pydu.structures import AttrDict
2017-10-06 15:45:29 +00:00
>>> o = AttrDict(a=1)
o.a
1
>>> o['a']
1
>>> o.a = 2
>>> o['a']
2
>>> del o.a
>>> o.a
Traceback (most recent call last):
...
AttributeError: 'a'
2017-10-06 15:59:14 +00:00
.. class:: pydu.structures.CaseInsensitiveDict(data=None, **kwargs)
2017-10-06 15:45:29 +00:00
A case-insensitive ``dict``-like object.
Implements all methods and operations of ``collections.MutableMapping``
as well as dict's ``copy``. Also provides ``lower_items``.
All keys are expected to be strings. The structure remembers the
case of the last key to be set, and ``iter(instance)``, ``keys()``,
``items()``, ``iterkeys()``, and ``iteritems()`` will contain
2017-10-06 15:59:14 +00:00
case-sensitive keys.
>>> from pydu.structures import CaseInsensitiveDict
>>> cid = CaseInsensitiveDict()
>>> cid['Accept'] = 'application/json'
>>> cid['aCCEPT'] == 'application/json'
True
>>> list(cid) == ['Accept']
True
case-sensitive keys.
>>> from pydu.structures import CaseInsensitiveDict
>>> cid = CaseInsensitiveDict()
>>> cid['Accept'] = 'application/json'
>>> cid['aCCEPT'] == 'application/json'
True
>>> list(cid) == ['Accept']
True
2017-10-06 15:45:29 +00:00
case-sensitive keys.
2017-10-06 15:59:14 +00:00
>>> from pydu.structures import CaseInsensitiveDict
2017-10-06 15:45:29 +00:00
>>> cid = CaseInsensitiveDict()
>>> cid['Accept'] = 'application/json'
>>> cid['aCCEPT'] == 'application/json'
True
>>> list(cid) == ['Accept']
True
2017-10-06 15:59:14 +00:00
.. class:: pydu.structures.LookupDict(name=None)
2017-10-06 15:45:29 +00:00
Dictionary lookup object.
2017-10-06 15:59:14 +00:00
>>> from pydu.structures import LookupDict
>>> d = LookupDict()
>>> d['key']
None
>>> d['key'] = 1
>>> d['key']
1
>>> from pydu.structures import LookupDict
>>> d = LookupDict()
>>> d['key']
None
>>> d['key'] = 1
>>> d['key']
1
>>> from pydu.structures import LookupDict
2017-10-06 15:45:29 +00:00
>>> d = LookupDict()
>>> d['key']
None
>>> d['key'] = 1
>>> d['key']
1
Utils
=====