def decode(data): value = data.get(attribute) if value is None: return False if isinstance(value, six.text_type): if encoding == utils.ENCODING: return False value = utils.safe_binary(value) data[attribute] = convert_with_fallbacks(value, attribute, encoding, encoding_fallbacks) return True
def __persistent_load(self, reference): """Load a persistent reference. The reference might changed according a renaming rules. We give back a special object to represent that reference, and not the real object designated by the reference. """ # This takes care of returning the OID as bytes in order to convert # a database to Python 3. if isinstance(reference, tuple): oid, cls_info = reference if isinstance(cls_info, tuple): cls_info = self.__update_symb(cls_info) return ZODBReference((utils.safe_binary(oid), cls_info)) if isinstance(reference, list): if len(reference) == 1: oid, = reference return ZODBReference(['w', (utils.safe_binary(oid))]) mode, information = reference if mode == 'm': database_name, oid, cls_info = information if isinstance(cls_info, tuple): cls_info = self.__update_symb(cls_info) return ZODBReference( ['m', (database_name, utils.safe_binary(oid), cls_info)]) if mode == 'n': database_name, oid = information return ZODBReference( ['m', (database_name, utils.safe_binary(oid))]) if mode == 'w': if len(information) == 1: oid, = information return ZODBReference(['w', (utils.safe_binary(oid))]) oid, database_name = information return ZODBReference( ['w', (utils.safe_binary(oid), database_name)]) if isinstance(reference, (str, zodbpickle.binary)): oid = reference return ZODBReference(utils.safe_binary(oid)) raise AssertionError('Unknown reference format.')
def __reduce_ex__(self, protocol): type_info, args = super(Time, self).__reduce_ex__(protocol) assert len(args) > 0 return (datetime.time, (utils.safe_binary(args[0]), ) + args[1:])
def __reduce__(self): type_info, args = super(Date, self).__reduce__() assert len(args) > 0 return (datetime.date, (utils.safe_binary(args[0]), ) + args[1:])
def encode(data): value = data.get(attribute) if value is not None and not isinstance(value, zodbpickle.binary): data[attribute] = utils.safe_binary(value) return True return False