Esempio n. 1
0
 def test_bytes(self):
     """
     When called with an instance of L{bytes}, L{bytes_to_str}
     decodes its input using I{ascii} and returns the resulting str
     string as an instance of L{str}.
     """
     self.assertRaises(
         UnicodeDecodeError,
         lambda: bytes_to_str("\N{SNOWMAN}".encode("utf-8")),
     )
     decoded = bytes_to_str(b"hello world")
     self.assertIsInstance(decoded, str)
     self.assertEqual(decoded, "hello world")
Esempio n. 2
0
 def basic_from_element(cls, e):
     pieces = []
     value = bytes_to_str(e.find("Value").text)
     while value:
         piece, value = _split_quoted(value)
         pieces.append(piece)
     return cls(pieces)
Esempio n. 3
0
 def test_str(self):
     """
     When called with an instance of L{str},
     L{bytes_to_str} returns its input unmodified.
     """
     self.assertEqual(
         "\N{SNOWMAN}",
         bytes_to_str("\N{SNOWMAN}"),
     )
Esempio n. 4
0
 def basic_from_element(cls, e):
     text = bytes_to_str(e.find("Value").text)
     parts = dict(zip(_SOA_FIELDS, text.split()))
     return cls(
         Name(parts["mname"]),
         Name(parts["rname"]),
         int(parts["serial"]),
         int(parts["refresh"]),
         int(parts["retry"]),
         int(parts["expire"]),
         int(parts["minimum"]),
     )
Esempio n. 5
0
 def basic_from_element(cls, e):
     value = bytes_to_str(e.find("Value").text)
     order, preference, rest = value.split(None, 2)
     flag, rest = _split_quoted(rest)
     service, rest = _split_quoted(rest)
     regexp, replacement = _split_quoted(rest)
     return cls(
         int(order),
         int(preference),
         flag,
         service,
         regexp,
         Name(replacement),
     )
Esempio n. 6
0
 def basic_from_element(cls, e):
     return cls(bytes_to_str(e.find("Value").text))
Esempio n. 7
0
 def basic_from_element(cls, e):
     priority, weight, port, name = bytes_to_str(
         e.find("Value").text).split()
     return cls(int(priority), int(weight), int(port), Name(name))
Esempio n. 8
0
 def basic_from_element(cls, e):
     return cls(_split_quoted(bytes_to_str(e.find("Value").text))[0])
Esempio n. 9
0
 def basic_from_element(cls, e):
     parts = bytes_to_str(e.find("Value").text).split()
     preference = int(parts[0])
     name = parts[1]
     return cls(Name(name), preference)