supermutes


Namesupermutes JSON
Version 0.2.5 PyPI version JSON
download
home_pagehttps://github.com/alexcouper/supermutes
SummaryA collection of super mutables
upload_time2014-05-07 23:54:53
maintainerNone
docs_urlNone
authorAlex Couper
requires_pythonNone
licenseUNKNOWN
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            supermutes
==========

This library works with python 2.6, 2.7 and 3.2.

It defines three kinds of mutables.

dot
---

The ``dot`` module contains classes that allow dot-notation to be used for
when accessing a ``list`` or ``dict`` object.

eg::

    >>  from supermutes.dot import dotify
    >>  d = dotify({'a':[1, 2, 3, 4, 5], 'b': {'c': 5}})
    >>  d.a._0
    1
    >>  d.b.c
    5
    >>  d.c = {'f': 9}
    >>  d.c.f
    9

readonly
--------

The ``readonly`` module contains classes that transform ``dict`` and ``list``
objects into ones that cannot have any values changed on them.

eg::

    >>  from supermutes.readonly import readonly
    >>  r = readonly({'a':[1, 2, 3, 4, 5], 'b': {'c': 5}})
    >>  r
    {'a': [1, 2, 3, 4, 5], 'b': {'c': 5}}
    >>  r['a'].append(5)
    supermutes.readonly.ReadOnlyClassException: Cannot write to object.
    >> r['b']['d'] = 6
    supermutes.readonly.ReadOnlyClassException: Cannot write to object.

A decorator function is also available for readonly objects. It will
readonly-fy the output of the decorated function/method

eg::

    from supermutes.decorators import return_readonly

    @return_readonly
    def get_list():
        return ['12']


OrderedDefaultDict
------------------

The ``ordered`` module contains the ``OrderedDefaultDict`` class. It is an
implementation that is meant to be the child of an ``OrderedDict`` and a
``defaultdict`` from the python standard library.


Creating Sub Classes
--------------------

Upon declaration of a sub class of any of the supermutes, that class will be
set as the defacto class for recursively changing data sets.

To reset the classes back to the original set, use the ``reset_mapping`` method
inside the module

eg::

    >>> from supermutes.dot import DotDict, DotList, reset_mapping
    >>> class MySubClass(DotDict): pass
    >>> d = MySubClass({'a': {'b': {'c': 3}}})
    >>> d.a.b
    {'c': 3}
    >>> d.a.b.__class__
    <class '__main__.MySubClass'>
    >>> f = DotList([1, {}])
    >>> f[1].__class__
    <class '__main__.MySubClass'>
    >>> reset_mapping()
    >>> f = DotList([1, {}])
    >>> f[1].__class__
    <class 'supermutes.dot.DotDict'>


Writing your own ``Supermutable``
---------------------------------

If you would like to contribute, and write a supermutable that behaves in a
particular fashion, just try to follow these guidelines:

    * It should inherit from the mutable type that it is adapting (eg ``dict``
      ``list`` etc.)
    * It should also inherit from ``base.SuperMutable``. This takes care of
      all of the registering of any subclasses so that for example, all sub
      dicts added to the SuperMutable are changed accordingly. See example.py
      for a working sample.


Building
--------

After cloning the repo::

    $ pip install -r test-requirements.txt
    $ nosetests

``supermutes`` has a build job at http://travis-ci.org/alexcouper/supermutes
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alexcouper/supermutes",
    "name": "supermutes",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Alex Couper",
    "author_email": "info@alexcouper.com",
    "download_url": "https://files.pythonhosted.org/packages/3f/dd/e392bad8476734ec489278c24047c19feaf3ba8e04a7219b5520e6112b1b/supermutes-0.2.5.tar.gz",
    "platform": "UNKNOWN",
    "description": "supermutes\n==========\n\nThis library works with python 2.6, 2.7 and 3.2.\n\nIt defines three kinds of mutables.\n\ndot\n---\n\nThe ``dot`` module contains classes that allow dot-notation to be used for\nwhen accessing a ``list`` or ``dict`` object.\n\neg::\n\n    >>  from supermutes.dot import dotify\n    >>  d = dotify({'a':[1, 2, 3, 4, 5], 'b': {'c': 5}})\n    >>  d.a._0\n    1\n    >>  d.b.c\n    5\n    >>  d.c = {'f': 9}\n    >>  d.c.f\n    9\n\nreadonly\n--------\n\nThe ``readonly`` module contains classes that transform ``dict`` and ``list``\nobjects into ones that cannot have any values changed on them.\n\neg::\n\n    >>  from supermutes.readonly import readonly\n    >>  r = readonly({'a':[1, 2, 3, 4, 5], 'b': {'c': 5}})\n    >>  r\n    {'a': [1, 2, 3, 4, 5], 'b': {'c': 5}}\n    >>  r['a'].append(5)\n    supermutes.readonly.ReadOnlyClassException: Cannot write to object.\n    >> r['b']['d'] = 6\n    supermutes.readonly.ReadOnlyClassException: Cannot write to object.\n\nA decorator function is also available for readonly objects. It will\nreadonly-fy the output of the decorated function/method\n\neg::\n\n    from supermutes.decorators import return_readonly\n\n    @return_readonly\n    def get_list():\n        return ['12']\n\n\nOrderedDefaultDict\n------------------\n\nThe ``ordered`` module contains the ``OrderedDefaultDict`` class. It is an\nimplementation that is meant to be the child of an ``OrderedDict`` and a\n``defaultdict`` from the python standard library.\n\n\nCreating Sub Classes\n--------------------\n\nUpon declaration of a sub class of any of the supermutes, that class will be\nset as the defacto class for recursively changing data sets.\n\nTo reset the classes back to the original set, use the ``reset_mapping`` method\ninside the module\n\neg::\n\n    >>> from supermutes.dot import DotDict, DotList, reset_mapping\n    >>> class MySubClass(DotDict): pass\n    >>> d = MySubClass({'a': {'b': {'c': 3}}})\n    >>> d.a.b\n    {'c': 3}\n    >>> d.a.b.__class__\n    <class '__main__.MySubClass'>\n    >>> f = DotList([1, {}])\n    >>> f[1].__class__\n    <class '__main__.MySubClass'>\n    >>> reset_mapping()\n    >>> f = DotList([1, {}])\n    >>> f[1].__class__\n    <class 'supermutes.dot.DotDict'>\n\n\nWriting your own ``Supermutable``\n---------------------------------\n\nIf you would like to contribute, and write a supermutable that behaves in a\nparticular fashion, just try to follow these guidelines:\n\n    * It should inherit from the mutable type that it is adapting (eg ``dict``\n      ``list`` etc.)\n    * It should also inherit from ``base.SuperMutable``. This takes care of\n      all of the registering of any subclasses so that for example, all sub\n      dicts added to the SuperMutable are changed accordingly. See example.py\n      for a working sample.\n\n\nBuilding\n--------\n\nAfter cloning the repo::\n\n    $ pip install -r test-requirements.txt\n    $ nosetests\n\n``supermutes`` has a build job at http://travis-ci.org/alexcouper/supermutes",
    "bugtrack_url": null,
    "license": "UNKNOWN",
    "summary": "A collection of super mutables",
    "version": "0.2.5",
    "project_urls": {
        "Download": "UNKNOWN",
        "Homepage": "https://github.com/alexcouper/supermutes"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3fdde392bad8476734ec489278c24047c19feaf3ba8e04a7219b5520e6112b1b",
                "md5": "63ca1d73f9850cbdcd40b6ab5eb3fa4b",
                "sha256": "c4a3f9699c48df241d08eab218796e3056af78fafcf41bc2b0ddfe23d64831e4"
            },
            "downloads": -1,
            "filename": "supermutes-0.2.5.tar.gz",
            "has_sig": false,
            "md5_digest": "63ca1d73f9850cbdcd40b6ab5eb3fa4b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5335,
            "upload_time": "2014-05-07T23:54:53",
            "upload_time_iso_8601": "2014-05-07T23:54:53.436467Z",
            "url": "https://files.pythonhosted.org/packages/3f/dd/e392bad8476734ec489278c24047c19feaf3ba8e04a7219b5520e6112b1b/supermutes-0.2.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2014-05-07 23:54:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alexcouper",
    "github_project": "supermutes",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "supermutes"
}
        
Elapsed time: 0.44387s