Beispiel #1
0
    def get_control_characters(message, characters=None):
        u"""Read the UNA segment from the passed string.

        :param message: a valid EDI message string, or UNA segment string,
                        to extract the control characters from
        :param characters: the control characters to use, if none found in
                           the message
        :rtype: str or None
        :return: the control characters
        """

        if not characters:
            characters = Characters()

        # First, try to read the UNA segment ("Service String Advice",
        # conditional). This segment and the UNB segment (Interchange Header)
        # must always be written in ASCII, even if after the BGM the files
        # continues with cyrillic or UTF-16.

        # If it does not exist, return a default.
        if not message[:3] == u"UNA":
            return characters

        # Get the character definitions
        chars = message[3:9]
        characters.is_extracted_from_message = True

        characters.component_separator = chars[0]
        characters.data_separator = chars[1]
        characters.decimal_point = chars[2]
        characters.escape_character = chars[3]
        characters.reserved_character = chars[4]
        characters.segment_terminator = chars[5]

        return characters
Beispiel #2
0
def test_cc_assigning():
    one = Characters()
    one.component_separator = "x"
    assert one.component_separator == "x"
    assert one == "x+,? '"
Beispiel #3
0
 def test_cc_assigning(self):
     one = Characters()
     one.component_separator = 'x'
     self.assertEqual(one.component_separator, 'x')
     self.assertEqual(str(one), "x+,? '")