# Path: memsource/models.py
# class BaseModel(dict):
# class User(BaseModel):
# class Authentication(BaseModel):
# class Client(BaseModel):
# class Domain(BaseModel):
# class Language(BaseModel):
# class Project(BaseModel):
# class Job(BaseModel):
# class JobPart(BaseModel):
# class TranslationMemory(BaseModel):
# class AsynchronousRequest(BaseModel):
# class AsynchronousResponse(BaseModel):
# class Segment(BaseModel):
# class SegmentSearchResult(BaseModel):
# class Analysis(BaseModel):
# class MxliffUnit(BaseModel):
# class TermBase(BaseModel):
#     def __getattr__(self, key):
#     def _iso8601_to_datetime(self, source):
#     def date_created(self):
#     def __init__(self, source):
#     def is_complete(self):
#     def has_error(self):


from memsource import models
from lxml import objectify


class MxliffParser(object):
    """
    Parse xliff file of Memsource.
    """

    def parse(self, resource: {'XML file content as bytes': bytes}):
        root = objectify.fromstring(resource)
        memsource_namespace = root.nsmap['m']

        def to_memsouce_key(s: str) -> str:
            return '{{{}}}{}'.format(memsource_namespace, s)

        self.score_key = to_memsouce_key('score')
        self.gloss_score_key = to_memsouce_key('gross-score')
        self.tunit_metadata_key = to_memsouce_key('tunit-metadata')
        self.mark_key = to_memsouce_key('mark')
        self.type_key = to_memsouce_key('type')
        self.content_key = to_memsouce_key('content')

        return [
            self.parse_group(group) for group in root.file.body.getchildren()
        ]


# Path: memsource/models.py
# class BaseModel(dict):
# class User(BaseModel):
# class Authentication(BaseModel):
# class Client(BaseModel):
# class Domain(BaseModel):
# class Language(BaseModel):
# class Project(BaseModel):
# class Job(BaseModel):
# class JobPart(BaseModel):
# class TranslationMemory(BaseModel):
# class AsynchronousRequest(BaseModel):
# class AsynchronousResponse(BaseModel):
# class Segment(BaseModel):
# class SegmentSearchResult(BaseModel):
# class Analysis(BaseModel):
# class MxliffUnit(BaseModel):
# class TermBase(BaseModel):
#     def __getattr__(self, key):
#     def _iso8601_to_datetime(self, source):
#     def date_created(self):
#     def __init__(self, source):
#     def is_complete(self):
#     def has_error(self):


# Path: memsource/lib/mxliff.py
from memsource import models
from lxml import objectify



class MxliffParser(object):
    """
    Parse xliff file of Memsource.
    """

    def parse(self, resource: {'XML file content as bytes': bytes}):
        root = objectify.fromstring(resource)
        memsource_namespace = root.nsmap['m']

        def to_memsouce_key(s: str) -> str:
            return '{{{}}}{}'.format(memsource_namespace, s)

        self.score_key = to_memsouce_key('score')
        self.gloss_score_key = to_memsouce_key('gross-score')
        self.tunit_metadata_key = to_memsouce_key('tunit-metadata')
        self.mark_key = to_memsouce_key('mark')
        self.type_key = to_memsouce_key('type')
        self.content_key = to_memsouce_key('content')

        return [
            self.parse_group(group) for group in root.file.body.getchildren()
        ]


    def parse_group(self, group: objectify.ObjectifiedElement) -> models.MxliffUnit: