Skip to content

Commit

Permalink
Code improvements for nemo
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Feb 9, 2017
1 parent f1fa902 commit 521e389
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 14 additions & 2 deletions MyCapytain/resolvers/cts/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from MyCapytain.common.reference import URN, Reference
from MyCapytain.common.utils import xmlparser
from MyCapytain.errors import InvalidURN
from MyCapytain.errors import InvalidURN, UnknownObjectError
from MyCapytain.resolvers.prototypes import Resolver
from MyCapytain.resources.collections.cts import TextInventory, TextGroup, Work, Citation, Text as InventoryText, \
Translation, Edition
Expand Down Expand Up @@ -167,7 +167,19 @@ def __getText__(self, urn):
if not isinstance(urn, URN):
urn = URN(urn)
if len(urn) != 5:
raise InvalidURN
if len(urn) == 4:
urn, reference = urn.upTo(URN.WORK), str(urn.reference)
urn = [
t.id
for t in self.__texts__
if t.id.startswith(str(urn)) and isinstance(t, Edition) and not print(t.id)
]
if len(urn) > 0:
urn = URN(urn[0])
else:
raise UnknownObjectError
else:
raise InvalidURN

text = self.inventory[str(urn)]

Expand Down
7 changes: 5 additions & 2 deletions MyCapytain/resources/texts/encodings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class TEIResource(InteractiveTextualNode):
:cvar EXPORT_TO: List of exportable supported formats
:cvar DEFAULT_EXPORT: Default export (Plain/PrototypeText)
"""
EXPORT_TO = [Mimetypes.PYTHON.ETREE, Mimetypes.XML.Std, Mimetypes.PYTHON.NestedDict, Mimetypes.PLAINTEXT]
EXPORT_TO = [
Mimetypes.PYTHON.ETREE, Mimetypes.XML.Std,
Mimetypes.PYTHON.NestedDict, Mimetypes.PLAINTEXT, Mimetypes.XML.TEI
]
DEFAULT_EXPORT = Mimetypes.PLAINTEXT

def __init__(self, resource, **kwargs):
Expand Down Expand Up @@ -76,7 +79,7 @@ def __export__(self, output=Mimetypes.PLAINTEXT, exclude=None, _preformatted=Fal
# Exports the whole resource as a LXML object
return self.resource

elif output == Mimetypes.XML.Std:
elif output == Mimetypes.XML.Std or output == Mimetypes.XML.TEI:
# Exports the whole resource formatted as XML but as string object
return tostring(self.resource, encoding=str)

Expand Down

0 comments on commit 521e389

Please sign in to comment.