Skip to content

Commit

Permalink
Merge pull request #70 from Capitains/0.1.0dev
Browse files Browse the repository at this point in the history
Release 0.1.0
  • Loading branch information
PonteIneptique committed Mar 10, 2016
2 parents bde13d6 + 75738c3 commit efe64d3
Show file tree
Hide file tree
Showing 29 changed files with 4,121 additions and 747 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
*.pyc
.idea
build
env
src
env2

# Setuptools distribution folder.
/dist/
Expand Down
19 changes: 15 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ language: python
python:
- "2.7"
- "3.4"
# command to install dependencies
install:
- "pypy"
- "pypy3"

install:
- pip install -r requirements.txt
- pip install coveralls

# command to run tests
script:
script:
- coverage run --source=MyCapytain setup.py test

matrix:
allow_failures:
- python: pypy
- python: pypy3

after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then coveralls; fi

branches:
only:
- master
- master
- 0.1.0dev
2 changes: 1 addition & 1 deletion MyCapytain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"""

__name__ = "MyCapytain"
__version__ = "0.0.9"
__version__ = "0.1.0"
__all__ = ["common", "endpoints", "resources"]
46 changes: 23 additions & 23 deletions MyCapytain/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@
from collections import defaultdict, OrderedDict
from past.builtins import basestring
from builtins import range, object
from copy import copy


class Metadatum(object):
""" Metadatum object represent a single field of metadata
""" Metadatum object represent a single field of metadata
:param name: Name of the field
:type name: basestring
:param children: List of tuples, where first element is the key, and second the value
:type children: List
:Example:
:Example:
>>> a = Metadatum(name="label", [("lat", "Amores"), ("fre", "Les Amours")])
>>> print(a["lat"]) # == "Amores"
Expand All @@ -48,9 +47,9 @@ def __init__(self, name, children=None):
def __getitem__(self, key):
""" Add an iterable access method
Int typed key access to the *n* th registered key in the instance.
Int typed key access to the *n* th registered key in the instance.
If string based key does not exist, see for a default.
:param key: Key of wished value
:type key: basestring, tuple, int
:returns: An element of children whose index is key
Expand All @@ -61,7 +60,7 @@ def __getitem__(self, key):
>>> a = Metadatum(name="label", [("lat", "Amores"), ("fre", "Les Amours")])
>>> print(a["lat"]) # Amores
>>> print(a[("lat", "fre")]) # Amores, Les Amours
>>> print(a[0]) # Amores
>>> print(a[0]) # Amores
>>> print(a["dut"]) # Amores
"""
Expand All @@ -84,7 +83,7 @@ def __getitem__(self, key):

def __setitem__(self, key, value):
""" Register index key and value for the instance
:param key: Index key(s) for the metadata
:type key: basestring, list, tuple
:param value: Values for the metadata
Expand Down Expand Up @@ -130,7 +129,7 @@ def setDefault(self, key):
:returns: Default key
:raises: `ValueError` If key is not registered
:Example:
:Example:
>>> a = Metadatum(name="label", [("lat", "Amores"), ("fre", "Les Amours")])
>>> a.setDefault("fre")
>>> print(a["eng"]) # == "Les Amours"
Expand Down Expand Up @@ -178,23 +177,21 @@ def __getstate__(self):
default=self.default
)

@staticmethod
def __setstate__(dic):
def __setstate__(self, dic):
""" Unpickling method
:param value:
:return:
"""
self = Metadatum(name=dic["name"])
self.name = dic["name"]
self.children = OrderedDict(dic["langs"])
self.default = dic["default"]
return self



class Metadata(object):
"""
"""
A metadatum aggregation object provided to centralize metadata
:param key: A metadata field name
:type key: List.<basestring>
Expand All @@ -217,7 +214,7 @@ def __init__(self, keys=None):

def __getitem__(self, key):
""" Add a quick access system through getitem on the instance
:param key: Index key representing a set of metadatum
:type key: basestring, int, tuple
:returns: An element of children whose index is key
Expand Down Expand Up @@ -250,7 +247,7 @@ def __getitem__(self, key):

def __setitem__(self, key, value):
""" Set a new metadata field
:param key: Name of metadatum field
:type key: basestring, tuple
:param value: Metadum dictionary
Expand Down Expand Up @@ -316,7 +313,8 @@ def __add__(self, other):
>>> b = Metadata(name="title")
>>> a + b == Metadata(name=["label", "title"])
"""
result = copy(self)
from copy import deepcopy
result = deepcopy(self)
for metadata_key, metadatum in other:
if metadata_key in self.__keys:
for key, value in metadatum:
Expand Down Expand Up @@ -354,11 +352,13 @@ def __getstate__(self):

def __setstate__(self, dic):
""" Unpickling method
:param value:
:param dic: Dictionary with request valied
:return:
"""
self.metadata = defaultdict(Metadatum)

self.metadata = {
key: Metadatum.__setstate__(value) for key, value in dic.items()
}
self.__keys = list(dic.keys())
self.__keys = []
for key, value in dic.items():
self.__keys.append(key)
self.metadata[key] = getattr(Metadatum(name=value["name"]), "__setstate__")(value)
return self
Loading

0 comments on commit efe64d3

Please sign in to comment.