Skip to content

Commit

Permalink
(CtsReference) Added a condition on __new__() to deal with tuple in c…
Browse files Browse the repository at this point in the history
…ase of picle.load
  • Loading branch information
PonteIneptique committed Aug 30, 2018
1 parent 6f0c245 commit 6511558
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions MyCapytain/common/reference/_capitains_cts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from copy import copy
from typing import Optional, List, Union
from typing import Optional, List, Union, Tuple
from lxml.etree import _Element

from MyCapytain.common.constants import Mimetypes, get_graph, RDF_NAMESPACES, XPATH_NAMESPACES
Expand Down Expand Up @@ -114,8 +114,21 @@ class CtsReference(BaseReference):
>>> ref = CtsReference('1.2.3')
"""

def __new__(cls, reference: str):
if "-" not in reference:
def __new__(cls, reference: Union[str, Tuple[str, Optional[str]]]):
# pickle.load will try to feed the tuple back !
if isinstance(reference, tuple):
if reference[1]:
o = BaseReference.__new__(
CtsReference,
CtsSinglePassageId(reference[0]),
CtsSinglePassageId(reference[1])
)
else:
o = BaseReference.__new__(
CtsReference,
CtsSinglePassageId(reference[0])
)
elif "-" not in reference:
o = BaseReference.__new__(CtsReference, CtsSinglePassageId(reference))
else:
_start, _end = tuple(reference.split("-"))
Expand Down

0 comments on commit 6511558

Please sign in to comment.