summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2018-12-21 23:32:57 +0100
committerAndrej Shadura <andrew.shadura@collabora.co.uk>2018-12-21 23:32:57 +0100
commit39df62a7ef6190474a584fea2aeb224680855d9c (patch)
treea13c4f8c306e2333af6202e2c8cce076ac32a58e
parentee6e7db472fa510e1a39000b4df26767f981f81d (diff)
parent99e02a493e5bca767e53f0b473cd9f54dfc432ca (diff)
Update upstream source from tag 'upstream/1.2'
Update to upstream version '1.2' with Debian dir 3def5fb79f6b77f953d399a59ee3eb777943bf88
-rw-r--r--.gitignore14
-rw-r--r--PKG-INFO46
-rw-r--r--README.md33
-rw-r--r--README.rst (renamed from README.txt)4
-rw-r--r--frozendict.egg-info/PKG-INFO46
-rw-r--r--frozendict.egg-info/SOURCES.txt9
-rw-r--r--frozendict.egg-info/dependency_links.txt1
-rw-r--r--frozendict.egg-info/top_level.txt1
-rw-r--r--frozendict/__init__.py55
-rw-r--r--setup.cfg5
-rw-r--r--setup.py6
11 files changed, 158 insertions, 62 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index ede3225..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,14 +0,0 @@
-# Compiled stuff
-*.pyc
-*.pyo
-doc/_build
-
-# Crap created by version control
-.orig
-.rej
-
-# OS X
-.DS_Store
-
-# Other *nix:es
-.~
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..5354194
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,46 @@
+Metadata-Version: 1.0
+Name: frozendict
+Version: 1.2
+Summary: An immutable dictionary
+Home-page: https://github.com/slezica/python-frozendict
+Author: Santiago Lezica
+Author-email: slezica89@gmail.com
+License: MIT License
+Description: ==========
+ frozendict
+ ==========
+
+ ``frozendict`` is an immutable wrapper around dictionaries that implements the
+ complete mapping interface. It can be used as a drop-in replacement for
+ dictionaries where immutability is desired.
+
+ Of course, this is ``python``, and you can still poke around the object's
+ internals if you want.
+
+ The ``frozendict`` constructor mimics ``dict``, and all of the expected
+ interfaces (``iter``, ``len``, ``repr``, ``hash``, ``getitem``) are provided.
+ Note that a ``frozendict`` does not guarantee the immutability of its values, so
+ the utility of ``hash`` method is restricted by usage.
+
+ The only difference is that the ``copy()`` method of ``frozendict`` takes
+ variable keyword arguments, which will be present as key/value pairs in the new,
+ immutable copy.
+
+ Example shell usage:
+
+ .. code-block:: python
+
+ from frozendict import frozendict
+
+ fd = frozendict({ 'hello': 'World' })
+
+ print fd
+ # <frozendict {'hello': 'World'}>
+
+ print fd['hello']
+ # 'World'
+
+ print fd.copy(another='key/value')
+ # <frozendict {'hello': 'World', 'another': 'key/value'}>
+
+Platform: UNKNOWN
diff --git a/README.md b/README.md
deleted file mode 100644
index a213312..0000000
--- a/README.md
+++ /dev/null
@@ -1,33 +0,0 @@
-frozendict
-==========
-
-`frozendict` is an immutable wrapper around dictionaries that implements the
-complete mapping interface. It can be used as a drop-in replacement for
-dictionaries where immutability is desired.
-
-Of course, this is `python`, and you can still poke around the object's
-internals if you want.
-
-The `frozendict` constructor mimics `dict`, and all of the expected
-interfaces (`iter`, `len`, `repr`, `hash`, `getitem`) are provided.
-Note that a `frozendict` does not guarantee the immutability of its values, so
-the utility of `hash` method is restricted by usage.
-
-The only difference is that the `copy()` method of `frozendict` takes
-variable keyword arguments, which will be present as key/value pairs in the new,
-immutable copy.
-
-Example shell usage:
-
- from frozendict import frozendict
-
- fd = frozendict({ 'hello': 'World' })
-
- print fd
- # <frozendict {'hello': 'World'}>
-
- print fd['hello']
- # 'World'
-
- print fd.copy(another='key/value')
- # <frozendict {'hello': 'World', 'another': 'key/value'}>
diff --git a/README.txt b/README.rst
index 133645e..133a0b1 100644
--- a/README.txt
+++ b/README.rst
@@ -18,7 +18,9 @@ The only difference is that the ``copy()`` method of ``frozendict`` takes
variable keyword arguments, which will be present as key/value pairs in the new,
immutable copy.
-Example shell usage::
+Example shell usage:
+
+.. code-block:: python
from frozendict import frozendict
diff --git a/frozendict.egg-info/PKG-INFO b/frozendict.egg-info/PKG-INFO
new file mode 100644
index 0000000..5354194
--- /dev/null
+++ b/frozendict.egg-info/PKG-INFO
@@ -0,0 +1,46 @@
+Metadata-Version: 1.0
+Name: frozendict
+Version: 1.2
+Summary: An immutable dictionary
+Home-page: https://github.com/slezica/python-frozendict
+Author: Santiago Lezica
+Author-email: slezica89@gmail.com
+License: MIT License
+Description: ==========
+ frozendict
+ ==========
+
+ ``frozendict`` is an immutable wrapper around dictionaries that implements the
+ complete mapping interface. It can be used as a drop-in replacement for
+ dictionaries where immutability is desired.
+
+ Of course, this is ``python``, and you can still poke around the object's
+ internals if you want.
+
+ The ``frozendict`` constructor mimics ``dict``, and all of the expected
+ interfaces (``iter``, ``len``, ``repr``, ``hash``, ``getitem``) are provided.
+ Note that a ``frozendict`` does not guarantee the immutability of its values, so
+ the utility of ``hash`` method is restricted by usage.
+
+ The only difference is that the ``copy()`` method of ``frozendict`` takes
+ variable keyword arguments, which will be present as key/value pairs in the new,
+ immutable copy.
+
+ Example shell usage:
+
+ .. code-block:: python
+
+ from frozendict import frozendict
+
+ fd = frozendict({ 'hello': 'World' })
+
+ print fd
+ # <frozendict {'hello': 'World'}>
+
+ print fd['hello']
+ # 'World'
+
+ print fd.copy(another='key/value')
+ # <frozendict {'hello': 'World', 'another': 'key/value'}>
+
+Platform: UNKNOWN
diff --git a/frozendict.egg-info/SOURCES.txt b/frozendict.egg-info/SOURCES.txt
new file mode 100644
index 0000000..e2395f1
--- /dev/null
+++ b/frozendict.egg-info/SOURCES.txt
@@ -0,0 +1,9 @@
+LICENSE.txt
+MANIFEST.in
+README.rst
+setup.py
+frozendict/__init__.py
+frozendict.egg-info/PKG-INFO
+frozendict.egg-info/SOURCES.txt
+frozendict.egg-info/dependency_links.txt
+frozendict.egg-info/top_level.txt \ No newline at end of file
diff --git a/frozendict.egg-info/dependency_links.txt b/frozendict.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/frozendict.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/frozendict.egg-info/top_level.txt b/frozendict.egg-info/top_level.txt
new file mode 100644
index 0000000..302328f
--- /dev/null
+++ b/frozendict.egg-info/top_level.txt
@@ -0,0 +1 @@
+frozendict
diff --git a/frozendict/__init__.py b/frozendict/__init__.py
index 0af9dee..399948a 100644
--- a/frozendict/__init__.py
+++ b/frozendict/__init__.py
@@ -1,31 +1,64 @@
import collections
import operator
import functools
+import sys
+
+
+try:
+ from collections import OrderedDict
+except ImportError: # python < 2.7
+ OrderedDict = NotImplemented
+
+
+iteritems = getattr(dict, 'iteritems', dict.items) # py2-3 compatibility
+
class frozendict(collections.Mapping):
+ """
+ An immutable wrapper around dictionaries that implements the complete :py:class:`collections.Mapping`
+ interface. It can be used as a drop-in replacement for dictionaries where immutability is desired.
+ """
+
+ dict_cls = dict
def __init__(self, *args, **kwargs):
- self.__dict = dict(*args, **kwargs)
- self.__hash = None
+ self._dict = self.dict_cls(*args, **kwargs)
+ self._hash = None
def __getitem__(self, key):
- return self.__dict[key]
+ return self._dict[key]
+
+ def __contains__(self, key):
+ return key in self._dict
def copy(self, **add_or_replace):
- return frozendict(self, **add_or_replace)
+ return self.__class__(self, **add_or_replace)
def __iter__(self):
- return iter(self.__dict)
+ return iter(self._dict)
def __len__(self):
- return len(self.__dict)
+ return len(self._dict)
def __repr__(self):
- return '<frozendict %s>' % repr(self.__dict)
+ return '<%s %r>' % (self.__class__.__name__, self._dict)
def __hash__(self):
- if self.__hash is None:
- hashes = map(hash, self.items())
- self.__hash = functools.reduce(operator.xor, hashes, 0)
+ if self._hash is None:
+ h = 0
+ for key, value in iteritems(self._dict):
+ h ^= hash((key, value))
+ self._hash = h
+ return self._hash
+
+
+class FrozenOrderedDict(frozendict):
+ """
+ A frozendict subclass that maintains key order
+ """
+
+ dict_cls = OrderedDict
+
- return self.__hash
+if OrderedDict is NotImplemented:
+ del FrozenOrderedDict
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..861a9f5
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_build =
+tag_date = 0
+tag_svn_revision = 0
+
diff --git a/setup.py b/setup.py
index 223d507..78628f6 100644
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,8 @@
-from distutils.core import setup
+from setuptools import setup
setup(
name = 'frozendict',
- version = '0.4',
+ version = '1.2',
url = 'https://github.com/slezica/python-frozendict',
author = 'Santiago Lezica',
@@ -12,5 +12,5 @@ setup(
license = 'MIT License',
description = 'An immutable dictionary',
- long_description = open('README.txt').read()
+ long_description = open('README.rst').read()
)