def __init__(self, content, delimiter=","): precondition.AssertType(content, text) precondition.AssertType(delimiter, text) self._content = content self._delimiter = delimiter
def ParseFromDatastore(self, value): """See base class.""" precondition.AssertType(value, int) self._value = abs(compatibility.builtins.int(value))
def ParseFromHumanReadable(self, string): precondition.AssertType(string, Text) self._value = string.encode("utf-8")
def Format(self, fmt): """Return the value as a string formatted as per strftime semantics.""" precondition.AssertType(fmt, Text) stime = time.gmtime(self._value / self.converter) return compatibility.FormatTime(fmt, stime)
def Floor(self, interval): precondition.AssertType(interval, Duration) seconds = self.AsSecondsSinceEpoch() // interval.ToInt( SECONDS) * interval.ToInt(SECONDS) return self.FromSecondsSinceEpoch(seconds)
def ParseFromBytes(self, string): precondition.AssertType(string, bytes) self.ParseFromHumanReadable(string.decode("utf-8"))
def ParseFromDatastore(self, value): precondition.AssertType(value, int) self._value = compatibility.builtins.int(value)
def testIntCorrect(self): del self # Unused. precondition.AssertType(108, int) precondition.AssertType(0xABC, int) precondition.AssertType(2**1024, int)
def testIntIncorrect(self): with self.assertRaises(TypeError): precondition.AssertType(1.23, int) with self.assertRaises(TypeError): precondition.AssertType("123", int)
def ParseFromHumanReadable(self, string): precondition.AssertType(string, Text) self._value = binascii.unhexlify(string.encode("ascii"))
def FromHex(cls, hex_string): precondition.AssertType(hex_string, Text) return cls(binascii.unhexlify(hex_string))
def ParseFromHumanReadable(self, string): precondition.AssertType(string, Text) self.ParseFromBytes(string.encode("ascii"))
def FromYaml(source, default_router_cls): precondition.AssertType(source, Text) acl_list = APIAuthorization.ParseYAMLAuthorizationsList(source) return APIAuthorizationManager(acl_list, default_router_cls)
def write(self, text: Text): # pylint: disable=invalid-name precondition.AssertType(text, Text) self.buf.write(text)
def ReadFileBytesAsUnicode(file_obj): data = file_obj.read() precondition.AssertType(data, bytes) return data.decode("utf-8")
def testStringCorrect(self): precondition.AssertType("foo", str) precondition.AssertType("gżegżółka", str)
def Xor(bytestr, key): """Returns a `bytes` object where each byte has been xored with key.""" precondition.AssertType(bytestr, bytes) return bytes([byte ^ key for byte in bytestr])
def testStringIncorrect(self): with self.assertRaises(TypeError): precondition.AssertType(b"foo", str)
def ParseFromBytes(self, string): precondition.AssertType(string, bytes) self._value = string
def WriteBlobWithUnknownHash(self, blob_data: bytes) -> rdf_objects.BlobID: precondition.AssertType(blob_data, bytes) return self.delegate.WriteBlobWithUnknownHash(blob_data)
def ParseFromHumanReadable(self, string): precondition.AssertType(string, Text) self._value = compatibility.builtins.int(string)
def ReadBlob(self, blob_id: rdf_objects.BlobID) -> Optional[bytes]: precondition.AssertType(blob_id, rdf_objects.BlobID) return self.delegate.ReadBlob(blob_id)
def FromMicrosecondsSinceEpoch(cls, value): precondition.AssertType(value, int) return cls(value)
def CheckBlobExists(self, blob_id: rdf_objects.BlobID) -> bool: precondition.AssertType(blob_id, rdf_objects.BlobID) return self.delegate.CheckBlobExists(blob_id)
def __init__(self, cls): precondition.AssertType(cls, type) super(HashUnsupportedError, self).__init__("Hashing {} is unsupported!".format( compatibility.GetName(cls)))
def FromWireFormat(cls, value): precondition.AssertType(value, bytes) return cls(value)
def ParseFromDatastore(self, value): precondition.AssertType(value, bytes) self._value = value
def FromSerializedBytes(cls, value: bytes): precondition.AssertType(value, bytes) return cls(value)
def ParseFromString(self, string): precondition.AssertType(string, bytes) self._value = string.decode("utf-8")
def __init__(self, columns, delimiter=","): precondition.AssertIterableType(columns, text) precondition.AssertType(delimiter, text) self._writer = Writer(delimiter=delimiter) self._columns = columns