Beispiel #1
0
 def test_ascii_bytes_success_py2k(self):
     vals = [
         (six.binary_type("The quick brown fox"), six.binary_type("The quick brown fox")),
         (six.text_type("The quick brown fox", "utf-8"), six.binary_type("The quick brown fox")),
         (six.text_type("The quick brown fox", "ascii"), six.binary_type("The quick brown fox")),
     ]
     for v, coerced in vals:
         self.assertEqual(coerced, helpers.ascii_bytes(v))
Beispiel #2
0
    def to_storage(self, subject):
        if subject is None:
            return None

        res = helpers.ascii_bytes(subject)
        res = res.replace('-', '').replace(':', '').lower()
        if not MacAddress.RE_MAC_ADDRESS.match(res):
            msg = "Not a valid MAC address: {0}".format(subject)
            raise TypeError(msg)
        return res
Beispiel #3
0
    def to_storage(self, subject):
        if subject is None:
            return None

        res = helpers.ascii_bytes(subject)
        res = res.lower()
        if not Fingerprint.RE_FINGERPRINT.match(res):
            msg = "Not a valid 128 or 160-bit hexidecimal fingerprint: {0}"
            msg = msg.format(subject)
            raise TypeError(msg)
        return res.replace(':', '')
Beispiel #4
0
    def to_storage(self, subject):
        if subject is None:
            return None

        if isinstance(subject, uuid.UUID):
            return subject.hex

        res = helpers.ascii_bytes(subject)
        res = res.replace('-', '').lower()
        if not UUID.RE_UUID.match(res):
            msg = "Not a valid UUID: {0}".format(subject)
            raise TypeError(msg)
        return res