nti.externalization.oids: Stable object identifiers

Functions for finding and parsing OIDs.

to_external_oid(self, default=None, add_to_connection=False, add_to_intids=False) → bytes[source]

For a persistent object, returns its persistent OID in a parseable external format (see from_external_oid()). This format includes the database name (so it works in a ZODB multi-database) and the integer ID from the closest zope.intid.interfaces.IIntIds utility.

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 bytes string.

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) or None (intid).
class ParsedOID(oid, db_name, intid)

Bases: tuple

The fields of a parsed OID: oid, db_name and intid

db_name

Alias for field number 1

intid

Alias for field number 2

oid

Alias for field number 0