Skip to content

Commit

Permalink
Improving Codacy score
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Dec 6, 2016
1 parent b40072f commit 4b7e029
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 84 deletions.
18 changes: 9 additions & 9 deletions MyCapytain/common/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def __model__():

def __regexp__(self, subreference):
""" Split components of subreference
:param subreference: A subreference
:type subreference: str
:rtype: List.<Tuple>
Expand Down Expand Up @@ -453,8 +453,8 @@ def __gt__(self, other):
.. warning:: Does not take into account the passage !
:Example:
>>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
>>> b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1")
>>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
>>> b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1")
>>> (a > b) == True
"""
return len(self) > len(other)
Expand All @@ -470,9 +470,9 @@ def __lt__(self, other):
.. warning:: Does not take into account the passage !
:Example:
>>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
>>> b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1")
>>> (b < a) == True #
>>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
>>> b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1")
>>> (b < a) == True
"""
return len(self) < len(other)

Expand All @@ -485,8 +485,8 @@ def __eq__(self, other):
:returns: Equality between other and self
:Example:
>>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
>>> b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1")
>>> a = URN(urn="urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.1")
>>> b = URN(urn="urn:cts:latinLit:phi1294.phi002:1.1")
>>> (b == a) == False
"""
return isinstance(other, type(self)) and str(self) == str(other)
Expand Down Expand Up @@ -858,7 +858,7 @@ def fill(self, passage=None, xpath=None):
replacement = r"\1\2'" + passage + "'"

return REFERENCE_REPLACER.sub(replacement, xpath)
else:
else:
if isinstance(passage, Reference):
passage = passage.list or passage.start.list
elif passage is None:
Expand Down
7 changes: 6 additions & 1 deletion MyCapytain/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def normalize(string):


def xmlparser(xml, objectify=True):
""" Parse xml
""" Parse xml
:param xml: XML element
:type xml: Union[text_type, lxml.etree._Element]
Expand Down Expand Up @@ -333,6 +333,11 @@ def passageLoop(parent, new_tree, xpath1, xpath2=None, preceding_siblings=False,


class OrderedDefaultDict(OrderedDict):
""" Extension of Default Dict that makes an OrderedDefaultDict
:param default_factory__: Default class to initiate
"""

def __init__(self, default_factory=None, *args, **kwargs):
super(OrderedDefaultDict, self).__init__(*args, **kwargs)
self.default_factory = default_factory
Expand Down
9 changes: 9 additions & 0 deletions MyCapytain/errors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# -*- coding: utf-8 -*-
"""
.. module:: MyCapytain.errors
:synopsis: MyCapytain errors
.. moduleauthor:: Thibault Clérice <leponteineptique@gmail.com>
"""


class DuplicateReference(SyntaxWarning):
Expand Down
9 changes: 8 additions & 1 deletion MyCapytain/resolvers/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
__author__ = 'thibault'
"""
.. module:: MyCapytain.resolvers
:synopsis: Resolver objects
.. moduleauthor:: Thibault Clérice <leponteineptique@gmail.com>
"""
8 changes: 8 additions & 0 deletions MyCapytain/resolvers/cts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
.. module:: MyCapytain.resolvers.cts
:synopsis: Resolver objects for CTS environments
.. moduleauthor:: Thibault Clérice <leponteineptique@gmail.com>
"""
2 changes: 1 addition & 1 deletion MyCapytain/resolvers/cts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

from MyCapytain.resolvers.prototypes import Resolver
from MyCapytain.resources.texts.api.cts import Text, Passage
from MyCapytain.resources.texts.api.cts import Text
from MyCapytain.resources.collections.cts import TextInventory
from MyCapytain.retrievers.cts5 import CTS

Expand Down
10 changes: 10 additions & 0 deletions MyCapytain/resolvers/prototypes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
"""
.. module:: MyCapytain.resolvers.prototypes
:synopsis: Resolver Prototype
.. moduleauthor:: Thibault Clérice <leponteineptique@gmail.com>
"""


class Resolver(object):
""" Resolver provide a native python API which returns python objects.
Expand Down
8 changes: 4 additions & 4 deletions MyCapytain/resources/collections/cts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Citation(CitationPrototype):
escape = re.compile('(")')

def __str__(self):
""" Returns a string text inventory version of the object
""" Returns a string text inventory version of the object
:Example:
>>> a = Citation(name="book", xpath="/tei:TEI/tei:body/tei:text/tei:div", scope="/tei:div[@n=\"1\"]")
Expand Down Expand Up @@ -116,8 +116,8 @@ def xpathDict(xml, xpath, children, parents, **kwargs):

class Text(cts.Text):
""" Represents a CTS Text
..automethod:: __str__
..automethod:: __str__
"""
def __init__(self, **kwargs):
super(Text, self).__init__(**kwargs)
Expand Down Expand Up @@ -363,7 +363,7 @@ def export(self, output=Mimetypes.PYTHON.ETREE, domain=""):
return super(Work, self).export(output, domain)

def parse(self, resource):
""" Parse a resource
""" Parse a resource
:param resource: Element rerpresenting a work
:param type: basestring, etree._Element
Expand Down
27 changes: 27 additions & 0 deletions MyCapytain/resources/prototypes/cts/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,21 @@ class Text(CTSCollection):
:type resource: Any
:param urn: Identifier of the Text
:type urn: str
:param parents: Item parents of the current collection
:type parents: [CTSCollection]
:param subtype: Subtype of the object (Edition, Translation)
:type subtype: str
"""

DC_TITLE = "label"

@property
def TEXT_URI(self):
""" Ontology URI of the text
:return: CTS Ontology Edition or Translation object
:rtype: str
"""
return RDF_PREFIX["cts"] + self.subtype

def __init__(self, resource=None, urn=None, parents=None, subtype="Edition"):
Expand Down Expand Up @@ -215,10 +224,28 @@ def editions(self):


def Edition(resource=None, urn=None, parents=None):
""" Represents a CTS Edition
:param resource: Resource representing the TextInventory
:type resource: Any
:param urn: Identifier of the Text
:type urn: str
:param parents: Item parents of the current collection
:type parents: [CTSCollection]
"""
return Text(resource=resource, urn=urn, parents=parents, subtype="Edition")


def Translation(resource=None, urn=None, parents=None):
""" Represents a CTS Translation
:param resource: Resource representing the TextInventory
:type resource: Any
:param urn: Identifier of the Text
:type urn: str
:param parents: Item parents of the current collection
:type parents: [CTSCollection]
"""
return Text(resource=resource, urn=urn, parents=parents, subtype="Translation")


Expand Down
37 changes: 28 additions & 9 deletions MyCapytain/resources/prototypes/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""
from past.builtins import basestring
from MyCapytain.common.reference import URN, Reference, Citation, NodeId
from six import text_type
from MyCapytain.common.reference import URN, Citation, NodeId
from MyCapytain.common.metadata import Metadata
from MyCapytain.common.utils import Mimetypes
from MyCapytain.resources.prototypes.metadata import Collection
Expand All @@ -35,17 +35,28 @@ def __init__(self, identifier=None, metadata=None):

@property
def text(self):
""" String representation of the text
:return: String representation of the text
:rtype: text_type
"""
return self.export(output=Mimetypes.PLAINTEXT, exclude=self.default_exclude)

@property
def id(self):
""" Identifier of the text
:return: Identifier of the text
:rtype: text_type
"""
return self.__identifier__

@property
def about(self):
""" Metadata information about the text
:return: Collection object with metadata about the text
:rtype Collection:
"""
return self.__about__

Expand All @@ -66,6 +77,7 @@ def metadata(self):
""" Metadata information about the text
:return: Collection object with metadata about the text
:rtype: Metadata
"""
return self.about.metadata

Expand All @@ -92,7 +104,7 @@ def default_export(self, output=Mimetypes.JSON.DTS, exclude=None):
"""
raise NotImplementedError

def export(self, output=None, exclude=None):
def export(self, output=None, exclude=None, **kwargs):
""" Export the collection item in the Mimetype required.
..note:: If current implementation does not have special mimetypes, reuses default_export method
Expand Down Expand Up @@ -135,7 +147,9 @@ def __init__(self, identifier=None, citation=None, **kwargs):

@property
def citation(self):
"""
""" Citation Object of the Text
:return: Citation Object of the Text
:rtype: Citation
"""
return self.__citation__
Expand Down Expand Up @@ -191,7 +205,7 @@ def getReffs(self, level=1, reference=None):
:type level: Int
:param passage: Subreference (optional)
:type passage: Reference
:rtype: List.basestring
:rtype: [text_type]
:returns: List of levels
"""
raise NotImplementedError()
Expand Down Expand Up @@ -277,6 +291,11 @@ def last(self):

@property
def childIds(self):
""" Identifiers of children
:return: Identifiers of children
:rtype: [str]
"""
if self.__childIds__ is None:
self.__childIds__ = self.getReffs()
return self.__childIds__
Expand All @@ -285,7 +304,7 @@ def childIds(self):
def firstId(self):
""" First child of current Passage
:rtype: Node
:rtype: str
:returns: First passage node Information
"""
if self.childIds is not None:
Expand All @@ -299,7 +318,7 @@ def firstId(self):
def lastId(self):
""" Last child of current Passage
:rtype: Node
:rtype: str
:returns: Last passage Node representation
"""
if self.childIds is not None:
Expand Down Expand Up @@ -356,7 +375,7 @@ def urn(self, value):
:raises: *TypeError* when the value is not URN compatible
"""
if isinstance(value, basestring):
if isinstance(value, text_type):
value = URN(value)
elif not isinstance(value, URN):
raise TypeError()
Expand All @@ -369,7 +388,7 @@ def getValidReff(self, level=1, reference=None):
:type level: Int
:param passage: Subreference (optional)
:type passage: Reference
:rtype: List.basestring
:rtype: List.text_type
:returns: List of levels
"""
raise NotImplementedError()
Expand Down
2 changes: 1 addition & 1 deletion MyCapytain/resources/texts/api/cts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from MyCapytain.common.metadata import Metadata
from MyCapytain.common.utils import xmlparser, NS
from MyCapytain.common.reference import Citation, URN, Reference
from MyCapytain.common.reference import URN, Reference
from MyCapytain.resources.collections import cts as CTSCollection
from MyCapytain.resources.prototypes import text as prototypes
from MyCapytain.resources.texts.encodings import TEIResource
Expand Down

0 comments on commit 4b7e029

Please sign in to comment.