# Path: memsource/lib/mxliff.py
# 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:
#         # 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)
# 
#     def parse_tunit_metadata(self, trans_unit: objectify.ObjectifiedElement) -> list:
#         tunit_metadata = getattr(trans_unit, self.tunit_metadata_key, None)
# 
#         # There is no meta data.
#         if tunit_metadata is None:
#             return []
# 
#         return [{
#             'id': mark.attrib['id'],
#             'type': getattr(mark, self.type_key).text,
#             'content': getattr(mark, self.content_key).text,
#         } for mark in getattr(tunit_metadata, self.mark_key)]
# 
# 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):


import unittest
import os.path
from memsource.lib.mxliff import MxliffParser
from memsource import models
        self.assertIsInstance(mxliff_units[0], models.MxliffUnit)

        self.assertEqual(mxliff_units[0], {
            'id': 'fj4ewiofj3qowjfw:0',
            'score': 0.0,
            'gross_score': 0.0,
            'source': 'Hello World.',
            'target': None,
            'machine_trans': None,
            'memsource_tm': None,
            'tunit_metadata': [],
        })

        self.assertIsInstance(mxliff_units[1], models.MxliffUnit)
        self.assertEqual(mxliff_units[1], {
            'id': 'fj4ewiofj3qowjfw:1',
            'score': 1.01,
            'gross_score': 1.01,
            'source': 'This library wraps Memsoruce API for Python.',
            'target': 'このライブラリはMemsourceのAPIをPython用にラップしています。',
            'machine_trans': 'This is machine translation.',
            'memsource_tm': 'This is memsource translation memory.',
            'tunit_metadata': [],
        })

    def test_parse_with_meta(self):
        mxliff_units = MxliffParser().parse(self.mxliff_text_meta)

        self.assertEqual(len(mxliff_units), 1)


# Path: memsource/lib/mxliff.py
# 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:
#         # 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)
# 
#     def parse_tunit_metadata(self, trans_unit: objectify.ObjectifiedElement) -> list:
#         tunit_metadata = getattr(trans_unit, self.tunit_metadata_key, None)
# 
#         # There is no meta data.
#         if tunit_metadata is None:
#             return []
# 
#         return [{
#             'id': mark.attrib['id'],
#             'type': getattr(mark, self.type_key).text,
#             'content': getattr(mark, self.content_key).text,
#         } for mark in getattr(tunit_metadata, self.mark_key)]
# 
# 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: test/lib/mxliff/test_mxliff_parser.py
import unittest
import os.path
from memsource.lib.mxliff import MxliffParser
from memsource import models

        self.assertIsInstance(mxliff_units[0], models.MxliffUnit)

        self.assertEqual(mxliff_units[0], {
            'id': 'fj4ewiofj3qowjfw:0',
            'score': 0.0,
            'gross_score': 0.0,
            'source': 'Hello World.',
            'target': None,
            'machine_trans': None,
            'memsource_tm': None,
            'tunit_metadata': [],
        })

        self.assertIsInstance(mxliff_units[1], models.MxliffUnit)
        self.assertEqual(mxliff_units[1], {
            'id': 'fj4ewiofj3qowjfw:1',
            'score': 1.01,
            'gross_score': 1.01,
            'source': 'This library wraps Memsoruce API for Python.',
            'target': 'このライブラリはMemsourceのAPIをPython用にラップしています。',
            'machine_trans': 'This is machine translation.',
            'memsource_tm': 'This is memsource translation memory.',
            'tunit_metadata': [],
        })

    def test_parse_with_meta(self):
        mxliff_units = MxliffParser().parse(self.mxliff_text_meta)

        self.assertEqual(len(mxliff_units), 1)


        self.assertIsInstance(mxliff_units[0], models.MxliffUnit)