pydicti
-------
|Tests| |Coverage| |Version| |License|
Installation
~~~~~~~~~~~~
You can install the newest version of *pydicti* from PyPI_:
.. code:: bash
pip install pydicti
Alternatively, you can just take the file ``pydicti.py`` and redistribute
it with your application.
.. _PyPI: https://pypi.python.org/pypi/pydicti/
Overview
~~~~~~~~
- ``class dicti``: default case insensitive dictionary type
- ``class odicti``: ordered case insensitive dictionary type
- ``def build_dicti``: create a case insensitive dictionary class
- ``def Dicti``: create a case insensitive copy of a dictionary
dicti
=====
Objects of type ``dicti`` are dictionaries that feature case insensitive
item access:
.. code:: python
>>> d = dicti(Hello='foo', world='bar')
>>> d['heLLO']
'foo'
>>> 'WOrld' in d
True
Internally however, the keys retain their original case:
.. code:: python
>>> sorted(d.keys())
['Hello', 'world']
odicti
======
The type ``odicti`` instanciates order-preserving case insensitive
dictionaries:
.. code:: python
>>> odicti(zip('abc', range(3)))
Dicti(OrderedDict([('a', 0), ('b', 1), ('c', 2)]))
build_dicti
===========
With ``build_dicti`` you can create custom case insensitive dictionaries.
This function is what is used to create the ``pydicti.dicti`` and
``pydicti.odicti`` types. Note that calling ``build_dicti`` several times
with the same argument will result in identical types:
.. code:: python
>>> build_dicti(dict) is dicti
True
>>> build_dicti(OrderedDict) is odicti
True
``build_dicti`` uses subclassing to inherit the semantics of the given base
dictionary type:
.. code:: python
>>> issubclass(odicti, OrderedDict)
True
Dicti
=====
The function ``Dicti`` is convenient for creating case insensitive
copies of dictionary instances:
.. code:: python
>>> o = OrderedDict(zip('abcdefg', range(7)))
>>> oi = Dicti(o)
>>> type(oi) is odicti
True
JSON
~~~~
The subclassing approach allows to plug your dictionary instance into
places where typechecking with ``isinstance`` is used, like in the json_
module:
.. code:: python
>>> import json
>>> d == json.loads(json.dumps(d), object_hook=dicti)
True
.. _json: http://docs.python.org/3.3/library/json.html
You can use ``json.loads(s, object_pairs_hook=odicti)`` to
deserialize ordered dictionaries.
Pitfalls
~~~~~~~~
The equality comparison tries preserves the semantics of the base type as
well as reflexitivity. This has impact on the transitivity of the
comparison operator:
.. code:: python
>>> i = dicti(oi)
>>> roi = odicti(reversed(list(oi.items())))
>>> roi == i and i == oi
True
>>> oi != roi and roi != oi # NOT transitive!
True
>>> oi == i and i == oi # reflexive
True
The `coercion rules`_ in python allow this to work pretty well when
performing comparisons between types that are subclasses of each other. Be
careful otherwise, however.
.. _`coercion rules`: http://docs.python.org/2/reference/datamodel.html#coercion-rules
License
~~~~~~~
Copyright © 2013 Thomas Gläßle <t_glaessle@gmx.de>
This work is free. You can redistribute it and/or modify it under the
terms of the Do What The Fuck You Want To Public License, Version 2, as
published by Sam Hocevar. See the COPYING file for more details.
This program is free software. It comes without any warranty, to the
extent permitted by applicable law.
.. Badges:
.. |Version| image:: https://img.shields.io/pypi/v/pydicti.svg
:target: https://pypi.python.org/pypi/pydicti
:alt: Latest Version
.. |Tests| image:: https://github.com/coldfix/pydicti/workflows/Tests/badge.svg
:target: https://github.com/coldfix/pydicti/actions?query=Tests
:alt: Test Status
.. |Coverage| image:: https://codecov.io/gh/coldfix/pydicti/branch/master/graph/badge.svg?token=7FEGhE9UVI
:target: https://codecov.io/gh/coldfix/pydicti
:alt: Coverage
.. |License| image:: https://img.shields.io/pypi/l/pydicti.svg
:target: https://github.com/coldfix/pydicti/blob/master/COPYING
:alt: License
CHANGELOG
~~~~~~~~~
1.2.0
=====
Date: 15.12.2022
- add type hints
1.1.6
=====
Date: 04.11.2021
- update the badges on the landing page
1.1.5
=====
Date: 04.11.2021
- maintenance release for testing automatic releases using GitHub Actions
1.1.4
=====
Date: 17.10.2020
- use ``str.casefold()`` on python3
- make normalization function a parameter of ``build_dict``, so that
user-defined normalization functions can be passed
1.1.3
=====
Date: 28.06.2019
- avoid key recomputation in ``__setitem__``
1.1.2
=====
Date: 28.06.2019
- leave item order invariant under assignment in odicti (#2)
- leave key case invariant under assignment
1.1.1
=====
Date: 25.03.2019
- fix deprecated MutableMapping import (error on py38)
1.1.0
=====
Date: 19.03.2019
- drop py2.6 support
- fix version number in long_description
1.0.0
=====
Date: 19.03.2019
- make str representation more dict-like
- misc cleanup
0.0.6
=====
Date: 08.09.2016
- fix UnicodeDecodeError in setup when UTF-8 is not the default encoding
0.0.5
=====
Date: 18.05.2016
- fix pickling on py 3.5
- the 'name' parameter to build_dicti can now be a qualname
0.0.4
=====
Date: 01.02.2014
- add coverage reports
- use more extensive unit tests
- add support for pickle
0.0.3
=====
Date: 26.01.2014
- add support for python26
- make dependency on ``OrderedDict`` optional
- migrate to setuptools in order to use testing commands
- support `ordereddict.OrderedDict`_ as fallback
.. _`ordereddict.OrderedDict`: https://pypi.python.org/pypi/ordereddict/1.1
0.0.2
=====
Date: 29.12.2013
- fix ``dicti.pop``
- support ``deepcopy(dicti)``
- make nosetest automatically execute the doctests
Raw data
{
"_id": null,
"home_page": "https://github.com/coldfix/pydicti",
"name": "pydicti",
"maintainer": "",
"docs_url": null,
"requires_python": ">=2.7",
"maintainer_email": "",
"keywords": "",
"author": "Thomas Gl\u00e4\u00dfle",
"author_email": "t_glaessle@gmx.de",
"download_url": "https://files.pythonhosted.org/packages/67/f8/7568ef672b6161d46b154afbcfb680bf06e420789d494290acd91162664e/pydicti-1.2.0.tar.gz",
"platform": null,
"description": "pydicti\n-------\n|Tests| |Coverage| |Version| |License|\n\nInstallation\n~~~~~~~~~~~~\n\nYou can install the newest version of *pydicti* from PyPI_:\n\n.. code:: bash\n\n pip install pydicti\n\nAlternatively, you can just take the file ``pydicti.py`` and redistribute\nit with your application.\n\n.. _PyPI: https://pypi.python.org/pypi/pydicti/\n\n\nOverview\n~~~~~~~~\n\n- ``class dicti``: default case insensitive dictionary type\n- ``class odicti``: ordered case insensitive dictionary type\n- ``def build_dicti``: create a case insensitive dictionary class\n- ``def Dicti``: create a case insensitive copy of a dictionary\n\ndicti\n=====\n\nObjects of type ``dicti`` are dictionaries that feature case insensitive\nitem access:\n\n.. code:: python\n\n >>> d = dicti(Hello='foo', world='bar')\n >>> d['heLLO']\n 'foo'\n >>> 'WOrld' in d\n True\n\nInternally however, the keys retain their original case:\n\n.. code:: python\n\n >>> sorted(d.keys())\n ['Hello', 'world']\n\nodicti\n======\n\nThe type ``odicti`` instanciates order-preserving case insensitive\ndictionaries:\n\n.. code:: python\n\n >>> odicti(zip('abc', range(3)))\n Dicti(OrderedDict([('a', 0), ('b', 1), ('c', 2)]))\n\n\nbuild_dicti\n===========\n\nWith ``build_dicti`` you can create custom case insensitive dictionaries.\nThis function is what is used to create the ``pydicti.dicti`` and\n``pydicti.odicti`` types. Note that calling ``build_dicti`` several times\nwith the same argument will result in identical types:\n\n.. code:: python\n\n >>> build_dicti(dict) is dicti\n True\n >>> build_dicti(OrderedDict) is odicti\n True\n\n``build_dicti`` uses subclassing to inherit the semantics of the given base\ndictionary type:\n\n.. code:: python\n\n >>> issubclass(odicti, OrderedDict)\n True\n\nDicti\n=====\n\nThe function ``Dicti`` is convenient for creating case insensitive\ncopies of dictionary instances:\n\n.. code:: python\n\n >>> o = OrderedDict(zip('abcdefg', range(7)))\n >>> oi = Dicti(o)\n >>> type(oi) is odicti\n True\n\n\nJSON\n~~~~\n\nThe subclassing approach allows to plug your dictionary instance into\nplaces where typechecking with ``isinstance`` is used, like in the json_\nmodule:\n\n.. code:: python\n\n >>> import json\n >>> d == json.loads(json.dumps(d), object_hook=dicti)\n True\n\n.. _json: http://docs.python.org/3.3/library/json.html\n\nYou can use ``json.loads(s, object_pairs_hook=odicti)`` to\ndeserialize ordered dictionaries.\n\n\nPitfalls\n~~~~~~~~\n\nThe equality comparison tries preserves the semantics of the base type as\nwell as reflexitivity. This has impact on the transitivity of the\ncomparison operator:\n\n.. code:: python\n\n >>> i = dicti(oi)\n >>> roi = odicti(reversed(list(oi.items())))\n >>> roi == i and i == oi\n True\n >>> oi != roi and roi != oi # NOT transitive!\n True\n >>> oi == i and i == oi # reflexive\n True\n\nThe `coercion rules`_ in python allow this to work pretty well when\nperforming comparisons between types that are subclasses of each other. Be\ncareful otherwise, however.\n\n.. _`coercion rules`: http://docs.python.org/2/reference/datamodel.html#coercion-rules\n\n\nLicense\n~~~~~~~\n\nCopyright \u00a9 2013 Thomas Gl\u00e4\u00dfle <t_glaessle@gmx.de>\n\nThis work is free. You can redistribute it and/or modify it under the\nterms of the Do What The Fuck You Want To Public License, Version 2, as\npublished by Sam Hocevar. See the COPYING file for more details.\n\nThis program is free software. It comes without any warranty, to the\nextent permitted by applicable law.\n\n\n.. Badges:\n\n.. |Version| image:: https://img.shields.io/pypi/v/pydicti.svg\n :target: https://pypi.python.org/pypi/pydicti\n :alt: Latest Version\n\n.. |Tests| image:: https://github.com/coldfix/pydicti/workflows/Tests/badge.svg\n :target: https://github.com/coldfix/pydicti/actions?query=Tests\n :alt: Test Status\n\n.. |Coverage| image:: https://codecov.io/gh/coldfix/pydicti/branch/master/graph/badge.svg?token=7FEGhE9UVI\n :target: https://codecov.io/gh/coldfix/pydicti\n :alt: Coverage\n\n.. |License| image:: https://img.shields.io/pypi/l/pydicti.svg\n :target: https://github.com/coldfix/pydicti/blob/master/COPYING\n :alt: License\n\nCHANGELOG\n~~~~~~~~~\n\n1.2.0\n=====\nDate: 15.12.2022\n\n- add type hints\n\n\n1.1.6\n=====\nDate: 04.11.2021\n\n- update the badges on the landing page\n\n\n1.1.5\n=====\nDate: 04.11.2021\n\n- maintenance release for testing automatic releases using GitHub Actions\n\n\n1.1.4\n=====\nDate: 17.10.2020\n\n- use ``str.casefold()`` on python3\n- make normalization function a parameter of ``build_dict``, so that\n user-defined normalization functions can be passed\n\n\n1.1.3\n=====\nDate: 28.06.2019\n\n- avoid key recomputation in ``__setitem__``\n\n\n1.1.2\n=====\nDate: 28.06.2019\n\n- leave item order invariant under assignment in odicti (#2)\n- leave key case invariant under assignment\n\n\n1.1.1\n=====\nDate: 25.03.2019\n\n- fix deprecated MutableMapping import (error on py38)\n\n\n1.1.0\n=====\nDate: 19.03.2019\n\n- drop py2.6 support\n- fix version number in long_description\n\n\n1.0.0\n=====\nDate: 19.03.2019\n\n- make str representation more dict-like\n- misc cleanup\n\n\n0.0.6\n=====\nDate: 08.09.2016\n\n- fix UnicodeDecodeError in setup when UTF-8 is not the default encoding\n\n\n0.0.5\n=====\nDate: 18.05.2016\n\n- fix pickling on py 3.5\n- the 'name' parameter to build_dicti can now be a qualname\n\n\n0.0.4\n=====\nDate: 01.02.2014\n\n- add coverage reports\n- use more extensive unit tests\n- add support for pickle\n\n\n0.0.3\n=====\nDate: 26.01.2014\n\n- add support for python26\n- make dependency on ``OrderedDict`` optional\n- migrate to setuptools in order to use testing commands\n- support `ordereddict.OrderedDict`_ as fallback\n\n.. _`ordereddict.OrderedDict`: https://pypi.python.org/pypi/ordereddict/1.1\n\n0.0.2\n=====\nDate: 29.12.2013\n\n- fix ``dicti.pop``\n- support ``deepcopy(dicti)``\n- make nosetest automatically execute the doctests\n\n\n\n",
"bugtrack_url": null,
"license": "WTFPL",
"summary": "Case insensitive derivable dictionary",
"version": "1.2.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "faaf07f366cfe3576219a26f15bae452",
"sha256": "afbf33c5dfa6699974e1f6c8035a592020f6942ad5b613e12a6fc1ce2707606d"
},
"downloads": -1,
"filename": "pydicti-1.2.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "faaf07f366cfe3576219a26f15bae452",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=2.7",
"size": 8892,
"upload_time": "2022-12-15T10:02:09",
"upload_time_iso_8601": "2022-12-15T10:02:09.607969Z",
"url": "https://files.pythonhosted.org/packages/b1/1e/3748943bc7651ceefb9666760043e5c556d07b4bde09a35989f837e99270/pydicti-1.2.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "8f9d5f1aa7fe2b4e2edf2947df0ecddd",
"sha256": "32d59407b3229b22702910bd10f53d46c330481b5aea7cce076630d661be9d1e"
},
"downloads": -1,
"filename": "pydicti-1.2.0.tar.gz",
"has_sig": false,
"md5_digest": "8f9d5f1aa7fe2b4e2edf2947df0ecddd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7",
"size": 10048,
"upload_time": "2022-12-15T10:02:11",
"upload_time_iso_8601": "2022-12-15T10:02:11.197970Z",
"url": "https://files.pythonhosted.org/packages/67/f8/7568ef672b6161d46b154afbcfb680bf06e420789d494290acd91162664e/pydicti-1.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-15 10:02:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "coldfix",
"github_project": "pydicti",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "pydicti"
}