コード例 #1
0
 def test_load_i18n(self):
     instance = UDLGBuilder.build(self.lucas)
     with allure.step('write i18n'):
         block = self.lucas_i18n.read().encode(sys.getfilesystemencoding())
         instance.load_i18n(block)
         with allure.step('check'):
             self.assertEqual(
                 instance.data.records[30].members[3],
                 u"::I:: gotta go actually. "
                 u"(d6012f9c-fe53-48b6-bffb-b20d10ff86bc)".encode('utf-8')
             )
             self.assertEqual(
                 instance.data.records[30].members[7],
                 u'::F**k:: Что за чёрт? Пойду я отсюда. '
                 u'go-go-go.'.encode('utf-8')
             )
     with allure.step('check it once more'):
         stream = io.BytesIO(instance.to_bin())
         instance = UDLGBuilder.build(stream=stream)
         self.assertEqual(
             instance.data.records[30].members[3],
             u"::I:: gotta go actually. "
             u"(d6012f9c-fe53-48b6-bffb-b20d10ff86bc)".encode('utf-8')
         )
         self.assertEqual(
             instance.data.records[30].members[7],
             u'::F**k:: Что за чёрт? Пойду я отсюда. '
             u'go-go-go.'.encode('utf-8')
         )
コード例 #2
0
 def test_length_prefixed_string_modify(self):
     instance = UDLGBuilder.build(self.lucas)
     with allure.step('modify string'):
         entry_1 = instance.data.records[5].members[2]
         entry_1.set("::Another:: string to set. Юникод")
         entry_2 = instance.data.records[6].members[3]
         entry_2.set('::Another:: set string (=. И Юникод')
     with allure.step('check'):
         #: still binary object string
         self.assertIsInstance(entry_1, records.BinaryObjectString)
         self.assertEqual(
             entry_1.value,
             "::Another:: string to set. Юникод".encode('utf-8')
         )
         self.assertIsInstance(entry_2, records.BinaryObjectString)
         self.assertEqual(
             entry_2.value,
             '::Another:: set string (=. И Юникод'.encode('utf-8')
         )
         instance_from = UDLGBuilder.build(io.BytesIO(instance.to_bin()))
         entry_1 = instance_from.data.records[5].members[2]
         entry_2 = instance_from.data.records[6].members[3]
         self.assertEqual(
             entry_1, "::Another:: string to set. Юникод".encode('utf-8')
         )
         self.assertEqual(
             entry_2, '::Another:: set string (=. И Юникод'.encode('utf-8')
         )
コード例 #3
0
    def test_load_i18n(self):
        instance = UDLGBuilder.build(self.lucas)

        block = self.lucas_i18n.read()
        instance.load_i18n(block)

        self.assertEqual(
            instance.data.records[30].members[3],
            u"::I:: gotta go actually. "
            u"(d6012f9c-fe53-48b6-bffb-b20d10ff86bc)".encode('utf-8')
        )
        self.assertEqual(
            instance.data.records[30].members[7],
            u'::F**k:: Что за чёрт? Пойду я отсюда. '
            u'go-go-go.'.encode('utf-8')
        )

        stream = io.BytesIO(instance.to_bin())
        instance = UDLGBuilder.build(stream=stream)
        self.assertEqual(
            instance.data.records[30].members[3],
            u"::I:: gotta go actually. "
            u"(d6012f9c-fe53-48b6-bffb-b20d10ff86bc)".encode('utf-8')
        )
        self.assertEqual(
            instance.data.records[30].members[7],
            u'::F**k:: Что за чёрт? Пойду я отсюда. '
            u'go-go-go.'.encode('utf-8')
        )
コード例 #4
0
 def test_udlg_convert_to_bin(self):
     instance = UDLGBuilder.build(self.lucas)
     with allure.step('check'):
         self.assertEqual(instance.data.header.record_type,
                          enums.RecordTypeEnum.SerializedStreamHeader)
     with allure.step('to bin'):
         binary_data = instance.to_bin()
         self.assertIsInstance(binary_data, bytearray)
         self.assertEqual(len(binary_data), self.lucas.tell())
     with allure.step('from bin'):
         stream = io.BytesIO(binary_data)
         instance_from = UDLGBuilder.build(stream=stream)
         self.assertEqual(instance.data.count, instance_from.data.count)
コード例 #5
0
def apply(entry, cache, opts):
    with closing(open(entry.path, 'rb')) as stream:
        store_path = os.path.join(
            opts.output_dir,
            entry.path.split(opts.dialogs_dir)[-1][1:]).replace('\\', '/')
        i18n_path = os.path.join(opts.i18n_dir,
                                 entry.path.split(
                                     opts.dialogs_dir)[-1][1:]).replace(
                                         '\\', '/') + '.txt'
        store_entry_path, store_entry = store_path.rsplit('/', 1)
        if not os.path.exists(store_entry_path):
            os.makedirs(store_entry_path)

        try:
            i18n_block = open(i18n_path, 'rb').read()
        except OSError:
            logger.error("Can not access i18n file: %s, skipping", i18n_path)
            return
        i18n_cache_digest = md5(i18n_block).hexdigest()
        if cache.get(i18n_path, '') != i18n_cache_digest:
            print("Processing: %s" % entry.path)
            u = UDLGBuilder.build(stream)
            u.load_i18n(i18n_block)
            open(store_path, 'wb').write(u.to_bin())
        else:
            print("Skipping `%s`, already processed" % entry.path)
        cache[i18n_path] = i18n_cache_digest
コード例 #6
0
ファイル: dump_json.py プロジェクト: sthalik/udlg
def unpack(entry, opts):
    with closing(open(entry.path, 'rb')) as stream:
        store_path = os.path.join(opts.output_dir,
                                  entry.path.split(opts.dialogs_dir)[-1][1:])
        i18n_path, file_name = store_path.rsplit('/', 1)
        if not os.path.exists(i18n_path):
            os.makedirs(i18n_path)
        file_name = file_name.replace('.udlg', '.json')
        store_path = os.path.join(i18n_path, file_name)
        if not (opts.skip_processed and os.path.exists(store_path)):
            print("Processing: %s" % entry.path)
            u = UDLGBuilder.build(stream)
            open(store_path, 'w').write(json.dumps(u.to_dict()))
        else:
            print("Skipping: %s" % entry.path)
コード例 #7
0
def inspect(entry, health, opts):
    with closing(open(entry.path, 'rb')) as stream:
        if opts.use_health_cache and entry.path in health:
            #: skip for caching
            logger.info(PROCESSING_MESSAGE_FOUND_IN_CACHE % entry.path)
            return

        try:
            doc = UDLGBuilder.build(stream)
            assert (
                doc.records[-1].record_type == enums.RecordTypeEnum.MessageEnd)
            logger.info(PROCESSING_MESSAGE_OK % entry.path)
            health[entry.path] = True
        except Exception as err:
            logger.info(PROCESSING_MESSAGE_FAIL % entry.path)
            health[entry.path] = False
コード例 #8
0
 def test_cc_dog_in_motion(self):
     instance = UDLGBuilder.build(self.cc_dog_in_motion)
     with allure.step('check .net binary data format header'):
         net = instance.data
         self.assertEqual(net.header.record_type,
                          enums.RecordTypeEnum.SerializedStreamHeader)
         self.assertEqual(net.header.root_id, 1)
         self.assertEqual(net.header.header_id, -1)
         self.assertEqual(net.header.major_version, 1)
         self.assertEqual(net.header.minor_version, 0)
     with allure.step('check records consistency'):
         self.assertEqual(instance.data.count, 7)
         self.assertIsInstance(instance.data.records[0].entry,
                               records.BinaryLibrary)
         self.assertIsInstance(instance.data.records[6].entry,
                               records.MessageEnd)
コード例 #9
0
ファイル: check.py プロジェクト: CIbeaST/udlg_advance_i18n
def process(source, opts):
    with closing(open(source, 'rb')) as udlg_file:
        return UDLGBuilder.build(stream=udlg_file)
コード例 #10
0
 def test_lucas(self):
     instance = UDLGBuilder.build(self.lucas)
     with allure.step('check records'):
         self.assertEqual(instance.data.count, 96)