# 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
        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:
        # Because we cannot write 'group.trans-unit'.
        trans_unit = getattr(group, 'trans-unit')
        source = {
            'id': trans_unit.attrib['id'],
            'score': float(trans_unit.attrib[self.score_key]),
            'gross_score': float(trans_unit.attrib[self.gloss_score_key]),
            'source': trans_unit.source.text,
            'target': trans_unit.target.text,
            'tunit_metadata': self.parse_tunit_metadata(trans_unit),
        }

        for alt_trans in getattr(trans_unit, 'alt-trans'):
            # machine-trans, memsource-tm -> machine_trans, memsource_tm
            source[alt_trans.attrib['origin'].replace('-', '_')] = alt_trans.target.text


# 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

        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:
        # Because we cannot write 'group.trans-unit'.
        trans_unit = getattr(group, 'trans-unit')
        source = {
            'id': trans_unit.attrib['id'],
            'score': float(trans_unit.attrib[self.score_key]),
            'gross_score': float(trans_unit.attrib[self.gloss_score_key]),
            'source': trans_unit.source.text,
            'target': trans_unit.target.text,
            'tunit_metadata': self.parse_tunit_metadata(trans_unit),
        }

        for alt_trans in getattr(trans_unit, 'alt-trans'):
            # machine-trans, memsource-tm -> machine_trans, memsource_tm
            source[alt_trans.attrib['origin'].replace('-', '_')] = alt_trans.target.text


        return models.MxliffUnit(source)