forked from emiddell/dashi
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49e10c1
commit 3ac00f4
Showing
2 changed files
with
5 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,4 @@ | ||
|
||
|
||
from collections import MutableMapping | ||
|
||
class OrderedDict(MutableMapping): | ||
""" | ||
a dictionary that keeps tracks of the order in which | ||
keys are added | ||
based on: http://code.activestate.com/recipes/496761 | ||
""" | ||
|
||
def __init__(self, data=None): | ||
self._keys = [] | ||
self._data = {} | ||
|
||
if data is not None: | ||
if hasattr(data, 'items'): # dictionary | ||
items = list(data.items()) | ||
else: # list of tuples | ||
items = list(data) | ||
for i in range(len(items)): | ||
length = len(items[i]) | ||
if length != 2: | ||
raise ValueError('dictionary update sequence element ' | ||
'#%d has length %d; 2 is required' % (i, length)) | ||
self._keys.append(items[i][0]) | ||
self._data[items[i][0]] = items[i][1] | ||
|
||
def __len__(self): | ||
return len(self._keys) | ||
|
||
|
||
def __setitem__(self, key, value): | ||
if key not in self._data: | ||
self._keys.append(key) | ||
self._data[key] = value | ||
|
||
|
||
def __getitem__(self, key): | ||
return self._data[key] | ||
|
||
|
||
def __delitem__(self, key): | ||
del self._data[key] | ||
self._keys.remove(key) | ||
|
||
|
||
def keys(self): | ||
return list(self._keys) | ||
|
||
def __iter__(self): | ||
for key in self._keys: | ||
yield key | ||
|
||
def __repr__(self): | ||
result = [] | ||
for key in self._keys: | ||
result.append('%s: %s' % (repr(key), repr(self._data[key]))) | ||
if len(self._keys) < 4: | ||
return ''.join(['{', ', '.join(result), '}']) | ||
else: | ||
return ''.join(['{', ',\n '.join(result), '}']) | ||
|
||
|
||
|
||
def copy(self): | ||
copyDict = OrderedDict() | ||
copyDict._data = self._data.copy() | ||
copyDict._keys = self._keys[:] | ||
return copyDict | ||
|
||
# Python 3 dictionaries remember insertion order | ||
OrderedDict = dict | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,10 @@ | |
|
||
setup( | ||
name = "pydashi", | ||
version = "1.0.0", | ||
version = "2.0.0a0", | ||
author = "The dashi developers", | ||
author_email = "[email protected]", | ||
python_requires = '>=3', | ||
description = ("TODO"), | ||
license = "LGPL", | ||
#keywords = "histograms fitting ", | ||
|
@@ -17,6 +18,6 @@ | |
"Topic :: Scientific/Engineering", | ||
"Intended Audience :: Science/Research", | ||
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", | ||
"Programming Language :: Python :: 2.7" | ||
"Programming Language :: Python :: 3" | ||
], | ||
) |