nti.externalization.oids: Stable object identifiers
Functions for finding and parsing OIDs.
- class ParsedOID(oid, db_name, intid)
Bases:
tupleThe fields of a parsed OID:
oid,db_nameandintid- db_name
Alias for field number 1
- intid
Alias for field number 2
- oid
Alias for field number 0
- from_external_oid(ext_oid)[source]
Given a byte string, as produced by
to_external_oid(), parses it into its component parts.- Parameters:
ext_oid (bytes) – As produced by
to_external_oid(). (Text/unicode is also accepted.)- Returns:
A three-tuple,
ParsedOID. Only the OID is guaranteed to be present; the other fields may be empty (db_name) orNone(intid).
- to_external_oid(self, default=None, add_to_connection=False, add_to_intids=False) bytes[source]
For a
persistent object, returns itspersistent OIDin a parseable external format (seefrom_external_oid()). This format includes the database name (so it works in a ZODB multi-database) and the integer ID from the closestzope.intid.interfaces.IIntIdsutility.If the object implements a method
toExternalOID(), that method will be called and its result (or the default) will be returned. This should generally be considered legacy behaviour.If the object has not been saved, and add_to_connection is
False(the default) returns the default.- Parameters:
add_to_connection (bool) – If the object is persistent but not yet added to a connection, setting this to true will attempt to add it to the nearest connection in its containment tree, thus letting it have an OID.
add_to_intids (bool) – If we can obtain an OID for this object, but it does not have an intid, and an intid utility is available, then if this is
True(not the default) we will register it with the utility.
- Returns:
A
bytesstring.