Example #1
0
    def from_yml_rep(cls, yml_rep):
        if isinstance(yml_rep, int):
            yml_rep = str(yml_rep)
        elif not isinstance(yml_rep, basestring):
            raise TableEntryInvalidYmlRepresentationError("Could not parse value[{}] of type[{}] as string".format(
                yml_rep, type(yml_rep).__name__))

        try:
            byte_rep = standard_text_to_byte_list(yml_rep, cls.size)
        except ValueError as e:
            raise TableEntryInvalidYmlRepresentationError(e.message)

        return yml_rep
Example #2
0
    def from_yml_rep(cls, yml_rep):
        if isinstance(yml_rep, int):
            yml_rep = str(yml_rep)
        elif not isinstance(yml_rep, str):
            raise TableEntryInvalidYmlRepresentationError("Could not parse value[{}] of type[{}] as string".format(
                yml_rep, type(yml_rep).__name__))

        try:
            byte_rep = standard_text_to_byte_list(yml_rep, cls.size)
        except ValueError as e:
            raise TableEntryInvalidYmlRepresentationError(str(e))

        return yml_rep
Example #3
0
def test_standard_text_to_byte_list_replacement():
    CharacterSubstitutions.character_substitutions = {'A': 'B'}
    assert_list_equal([114, 114, 115, 116, 114, 117, 118, 119, 114],
                      standard_text_to_byte_list("ABCDAEFGA", 9))
Example #4
0
def test_standard_text_to_byte_list_replacement_unicode():
    CharacterSubstitutions.character_substitutions = {'я': 'B'}
    assert_list_equal([114, 114, 115, 116, 114, 117, 118, 119, 114],
                      standard_text_to_byte_list("яBCDяEFGя", 9))
Example #5
0
 def to_block_size(cls, value):
     return len(standard_text_to_byte_list(value, cls.size, False))
Example #6
0
def test_standard_text_to_byte_list_replacement_unicode():
    CharacterSubstitutions.character_substitutions = {'я': 'B'}
    assert_list_equal([114, 114, 115, 116, 114, 117, 118, 119, 114],
                      standard_text_to_byte_list("яBCDяEFGя", 9))
Example #7
0
def test_standard_text_to_byte_list_replacement():
    CharacterSubstitutions.character_substitutions = {'A': 'B'}
    assert_list_equal([114, 114, 115, 116, 114, 117, 118, 119, 114],
                      standard_text_to_byte_list("ABCDAEFGA", 9))