Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
pickle._Unpickler Class Reference

List of all members.

Public Member Functions

def __init__
def load
def marker
def persistent_load
def load_proto
def load_persid
def load_binpersid
def load_none
def load_false
def load_true
def load_int
def load_binint
def load_binint1
def load_binint2
def load_long
def load_long1
def load_long4
def load_float
def load_binfloat
def load_string
def load_binstring
def load_binbytes
def load_unicode
def load_binunicode
def load_short_binstring
def load_short_binbytes
def load_tuple
def load_empty_tuple
def load_tuple1
def load_tuple2
def load_tuple3
def load_empty_list
def load_empty_dictionary
def load_list
def load_dict
def load_inst
def load_obj
def load_newobj
def load_global
def load_ext1
def load_ext2
def load_ext4
def get_extension
def find_class
def load_reduce
def load_pop
def load_pop_mark
def load_dup
def load_get
def load_binget
def load_long_binget
def load_put
def load_binput
def load_long_binput
def load_append
def load_appends
def load_setitem
def load_setitems
def load_build
def load_mark
def load_stop

Public Attributes

 readline
 read
 memo
 encoding
 errors
 proto
 fix_imports
 mark
 stack
 append

Static Public Attributes

dictionary dispatch = {}

Private Member Functions

def _instantiate

Detailed Description

Definition at line 777 of file pickle.py.


Constructor & Destructor Documentation

def pickle._Unpickler.__init__ (   self,
  file,
  fix_imports = True,
  encoding = "ASCII",
  errors = "strict" 
)
This takes a binary file for reading a pickle data stream.

The protocol version of the pickle is detected automatically, so no
proto argument is needed.

The file-like object must have two methods, a read() method
that takes an integer argument, and a readline() method that
requires no arguments.  Both methods should return bytes.
Thus file-like object can be a binary file object opened for
reading, a BytesIO object, or any other custom object that
meets this interface.

Optional keyword arguments are *fix_imports*, *encoding* and *errors*,
which are used to control compatiblity support for pickle stream
generated by Python 2.x.  If *fix_imports* is True, pickle will try to
map the old Python 2.x names to the new names used in Python 3.x.  The
*encoding* and *errors* tell pickle how to decode 8-bit string
instances pickled by Python 2.x; these default to 'ASCII' and
'strict', respectively.

Definition at line 780 of file pickle.py.

00780 
00781                  encoding="ASCII", errors="strict"):
00782         """This takes a binary file for reading a pickle data stream.
00783 
00784         The protocol version of the pickle is detected automatically, so no
00785         proto argument is needed.
00786 
00787         The file-like object must have two methods, a read() method
00788         that takes an integer argument, and a readline() method that
00789         requires no arguments.  Both methods should return bytes.
00790         Thus file-like object can be a binary file object opened for
00791         reading, a BytesIO object, or any other custom object that
00792         meets this interface.
00793 
00794         Optional keyword arguments are *fix_imports*, *encoding* and *errors*,
00795         which are used to control compatiblity support for pickle stream
00796         generated by Python 2.x.  If *fix_imports* is True, pickle will try to
00797         map the old Python 2.x names to the new names used in Python 3.x.  The
00798         *encoding* and *errors* tell pickle how to decode 8-bit string
00799         instances pickled by Python 2.x; these default to 'ASCII' and
00800         'strict', respectively.
00801         """
00802         self.readline = file.readline
00803         self.read = file.read
00804         self.memo = {}
00805         self.encoding = encoding
00806         self.errors = errors
00807         self.proto = 0
00808         self.fix_imports = fix_imports

Here is the caller graph for this function:


Member Function Documentation

def pickle._Unpickler._instantiate (   self,
  klass,
  k 
) [private]

Definition at line 1034 of file pickle.py.

01034 
01035     def _instantiate(self, klass, k):
01036         args = tuple(self.stack[k+1:])
01037         del self.stack[k:]
01038         if (args or not isinstance(klass, type) or
01039             hasattr(klass, "__getinitargs__")):
01040             try:
01041                 value = klass(*args)
01042             except TypeError as err:
01043                 raise TypeError("in constructor for %s: %s" %
01044                                 (klass.__name__, str(err)), sys.exc_info()[2])
01045         else:
01046             value = klass.__new__(klass)
01047         self.append(value)

Here is the caller graph for this function:

def pickle._Unpickler.find_class (   self,
  module,
  name 
)

Definition at line 1104 of file pickle.py.

01104 
01105     def find_class(self, module, name):
01106         # Subclasses may override this.
01107         if self.proto < 3 and self.fix_imports:
01108             if (module, name) in _compat_pickle.NAME_MAPPING:
01109                 module, name = _compat_pickle.NAME_MAPPING[(module, name)]
01110             if module in _compat_pickle.IMPORT_MAPPING:
01111                 module = _compat_pickle.IMPORT_MAPPING[module]
01112         __import__(module, level=0)
01113         mod = sys.modules[module]
01114         klass = getattr(mod, name)
01115         return klass

Here is the call graph for this function:

Here is the caller graph for this function:

def pickle._Unpickler.get_extension (   self,
  code 
)

Definition at line 1091 of file pickle.py.

01091 
01092     def get_extension(self, code):
01093         nil = []
01094         obj = _extension_cache.get(code, nil)
01095         if obj is not nil:
01096             self.append(obj)
01097             return
01098         key = _inverted_registry.get(code)
01099         if not key:
01100             raise ValueError("unregistered extension code %d" % code)
01101         obj = self.find_class(*key)
01102         _extension_cache[code] = obj
01103         self.append(obj)

Here is the call graph for this function:

Here is the caller graph for this function:

def pickle._Unpickler.load (   self)
Read a pickled object representation from the open file.

Return the reconstituted object hierarchy specified in the file.

Definition at line 809 of file pickle.py.

00809 
00810     def load(self):
00811         """Read a pickled object representation from the open file.
00812 
00813         Return the reconstituted object hierarchy specified in the file.
00814         """
00815         # Check whether Unpickler was initialized correctly. This is
00816         # only needed to mimic the behavior of _pickle.Unpickler.dump().
00817         if not hasattr(self, "read"):
00818             raise UnpicklingError("Unpickler.__init__() was not called by "
00819                                   "%s.__init__()" % (self.__class__.__name__,))
00820         self.mark = object() # any new unique object
00821         self.stack = []
00822         self.append = self.stack.append
00823         read = self.read
00824         dispatch = self.dispatch
00825         try:
00826             while 1:
00827                 key = read(1)
00828                 if not key:
00829                     raise EOFError
00830                 assert isinstance(key, bytes_types)
00831                 dispatch[key[0]](self)
00832         except _Stop as stopinst:
00833             return stopinst.value

Definition at line 1172 of file pickle.py.

01172 
01173     def load_append(self):
01174         stack = self.stack
01175         value = stack.pop()
01176         list = stack[-1]
        list.append(value)

Definition at line 1179 of file pickle.py.

01179 
01180     def load_appends(self):
01181         stack = self.stack
01182         mark = self.marker()
01183         list = stack[mark - 1]
01184         list.extend(stack[mark + 1:])
        del stack[mark:]

Here is the call graph for this function:

Definition at line 958 of file pickle.py.

00958 
00959     def load_binbytes(self):
00960         len = mloads(b'i' + self.read(4))
        self.append(self.read(len))
def pickle._Unpickler.load_binfloat (   self,
  unpack = struct.unpack 
)

Definition at line 932 of file pickle.py.

00932 
00933     def load_binfloat(self, unpack=struct.unpack):
        self.append(unpack('>d', self.read(8))[0])

Here is the call graph for this function:

Definition at line 1147 of file pickle.py.

01147 
01148     def load_binget(self):
01149         i = self.read(1)[0]
        self.append(self.memo[i])

Definition at line 897 of file pickle.py.

00897 
00898     def load_binint(self):
        self.append(mloads(b'i' + self.read(4)))

Definition at line 901 of file pickle.py.

00901 
00902     def load_binint1(self):
        self.append(ord(self.read(1)))

Here is the call graph for this function:

Definition at line 905 of file pickle.py.

00905 
00906     def load_binint2(self):
        self.append(mloads(b'i' + self.read(2) + b'\000\000'))

Definition at line 866 of file pickle.py.

00866 
00867     def load_binpersid(self):
00868         pid = self.stack.pop()
        self.append(self.persistent_load(pid))

Here is the call graph for this function:

Definition at line 1162 of file pickle.py.

01162 
01163     def load_binput(self):
01164         i = self.read(1)[0]
        self.memo[i] = self.stack[-1]

Definition at line 951 of file pickle.py.

00951 
00952     def load_binstring(self):
00953         len = mloads(b'i' + self.read(4))
00954         data = self.read(len)
00955         value = str(data, self.encoding, self.errors)
        self.append(value)

Definition at line 967 of file pickle.py.

00967 
00968     def load_binunicode(self):
00969         len = mloads(b'i' + self.read(4))
        self.append(str(self.read(len), 'utf-8', 'surrogatepass'))

Definition at line 1205 of file pickle.py.

01205 
01206     def load_build(self):
01207         stack = self.stack
01208         state = stack.pop()
01209         inst = stack[-1]
01210         setstate = getattr(inst, "__setstate__", None)
01211         if setstate:
01212             setstate(state)
01213             return
01214         slotstate = None
01215         if isinstance(state, tuple) and len(state) == 2:
01216             state, slotstate = state
01217         if state:
01218             inst_dict = inst.__dict__
01219             intern = sys.intern
01220             for k, v in state.items():
01221                 if type(k) is str:
01222                     inst_dict[intern(k)] = v
01223                 else:
01224                     inst_dict[k] = v
01225         if slotstate:
01226             for k, v in slotstate.items():
                setattr(inst, k, v)

Here is the call graph for this function:

Definition at line 1018 of file pickle.py.

01018 
01019     def load_dict(self):
01020         k = self.marker()
01021         d = {}
01022         items = self.stack[k+1:]
01023         for i in range(0, len(items), 2):
01024             key = items[i]
01025             value = items[i+1]
01026             d[key] = value
        self.stack[k:] = [d]

Here is the call graph for this function:

Definition at line 1138 of file pickle.py.

01138 
01139     def load_dup(self):
        self.append(self.stack[-1])

Definition at line 1009 of file pickle.py.

01009 
01010     def load_empty_dictionary(self):
        self.append({})

Definition at line 1005 of file pickle.py.

01005 
01006     def load_empty_list(self):
        self.append([])

Definition at line 989 of file pickle.py.

00989 
00990     def load_empty_tuple(self):
        self.append(())

Definition at line 1076 of file pickle.py.

01076 
01077     def load_ext1(self):
01078         code = ord(self.read(1))
        self.get_extension(code)

Here is the call graph for this function:

Definition at line 1081 of file pickle.py.

01081 
01082     def load_ext2(self):
01083         code = mloads(b'i' + self.read(2) + b'\000\000')
        self.get_extension(code)

Here is the call graph for this function:

Definition at line 1086 of file pickle.py.

01086 
01087     def load_ext4(self):
01088         code = mloads(b'i' + self.read(4))
        self.get_extension(code)

Here is the call graph for this function:

Definition at line 875 of file pickle.py.

00875 
00876     def load_false(self):
        self.append(False)

Definition at line 928 of file pickle.py.

00928 
00929     def load_float(self):
        self.append(float(self.readline()[:-1]))

Definition at line 1142 of file pickle.py.

01142 
01143     def load_get(self):
01144         i = int(self.readline()[:-1])
        self.append(self.memo[i])

Definition at line 1069 of file pickle.py.

01069 
01070     def load_global(self):
01071         module = self.readline()[:-1].decode("utf-8")
01072         name = self.readline()[:-1].decode("utf-8")
01073         klass = self.find_class(module, name)
        self.append(klass)

Here is the call graph for this function:

Definition at line 1048 of file pickle.py.

01048 
01049     def load_inst(self):
01050         module = self.readline()[:-1].decode("ascii")
01051         name = self.readline()[:-1].decode("ascii")
01052         klass = self.find_class(module, name)
        self._instantiate(klass, self.marker())

Here is the call graph for this function:

Definition at line 883 of file pickle.py.

00883 
00884     def load_int(self):
00885         data = self.readline()
00886         if data == FALSE[1:]:
00887             val = False
00888         elif data == TRUE[1:]:
00889             val = True
00890         else:
00891             try:
00892                 val = int(data, 0)
00893             except ValueError:
00894                 val = int(data, 0)
        self.append(val)

Definition at line 1013 of file pickle.py.

01013 
01014     def load_list(self):
01015         k = self.marker()
        self.stack[k:] = [self.stack[k+1:]]

Here is the call graph for this function:

Definition at line 909 of file pickle.py.

00909 
00910     def load_long(self):
00911         val = self.readline()[:-1].decode("ascii")
00912         if val and val[-1] == 'L':
00913             val = val[:-1]
        self.append(int(val, 0))

Here is the call graph for this function:

Definition at line 916 of file pickle.py.

00916 
00917     def load_long1(self):
00918         n = ord(self.read(1))
00919         data = self.read(n)
        self.append(decode_long(data))

Here is the call graph for this function:

Definition at line 922 of file pickle.py.

00922 
00923     def load_long4(self):
00924         n = mloads(b'i' + self.read(4))
00925         data = self.read(n)
        self.append(decode_long(data))

Here is the call graph for this function:

Definition at line 1152 of file pickle.py.

01152 
01153     def load_long_binget(self):
01154         i = mloads(b'i' + self.read(4))
        self.append(self.memo[i])

Definition at line 1167 of file pickle.py.

01167 
01168     def load_long_binput(self):
01169         i = mloads(b'i' + self.read(4))
        self.memo[i] = self.stack[-1]

Definition at line 1229 of file pickle.py.

01229 
01230     def load_mark(self):
        self.append(self.mark)

Definition at line 1062 of file pickle.py.

01062 
01063     def load_newobj(self):
01064         args = self.stack.pop()
01065         cls = self.stack[-1]
01066         obj = cls.__new__(cls, *args)
        self.stack[-1] = obj

Definition at line 871 of file pickle.py.

00871 
00872     def load_none(self):
        self.append(None)

Definition at line 1055 of file pickle.py.

01055 
01056     def load_obj(self):
01057         # Stack is ... markobject classobject arg1 arg2 ...
01058         k = self.marker()
01059         klass = self.stack.pop(k+1)
        self._instantiate(klass, k)

Here is the call graph for this function:

Definition at line 861 of file pickle.py.

00861 
00862     def load_persid(self):
00863         pid = self.readline()[:-1].decode("ascii")
        self.append(self.persistent_load(pid))

Here is the call graph for this function:

Definition at line 1129 of file pickle.py.

01129 
01130     def load_pop(self):
        del self.stack[-1]

Definition at line 1133 of file pickle.py.

01133 
01134     def load_pop_mark(self):
01135         k = self.marker()
        del self.stack[k:]

Here is the call graph for this function:

Definition at line 854 of file pickle.py.

00854 
00855     def load_proto(self):
00856         proto = ord(self.read(1))
00857         if not 0 <= proto <= HIGHEST_PROTOCOL:
00858             raise ValueError("unsupported pickle protocol: %d" % proto)
        self.proto = proto

Here is the call graph for this function:

Definition at line 1157 of file pickle.py.

01157 
01158     def load_put(self):
01159         i = int(self.readline()[:-1])
        self.memo[i] = self.stack[-1]

Definition at line 1116 of file pickle.py.

01116 
01117     def load_reduce(self):
01118         stack = self.stack
01119         args = stack.pop()
01120         func = stack[-1]
01121         try:
01122             value = func(*args)
01123         except:
01124             print(sys.exc_info())
01125             print(func, args)
01126             raise
        stack[-1] = value

Definition at line 1187 of file pickle.py.

01187 
01188     def load_setitem(self):
01189         stack = self.stack
01190         value = stack.pop()
01191         key = stack.pop()
01192         dict = stack[-1]
        dict[key] = value

Definition at line 1195 of file pickle.py.

01195 
01196     def load_setitems(self):
01197         stack = self.stack
01198         mark = self.marker()
01199         dict = stack[mark - 1]
01200         for i in range(mark + 1, len(stack), 2):
01201             dict[stack[i]] = stack[i + 1]
01202 
        del stack[mark:]

Here is the call graph for this function:

Definition at line 979 of file pickle.py.

00979 
00980     def load_short_binbytes(self):
00981         len = ord(self.read(1))
        self.append(bytes(self.read(len)))

Here is the call graph for this function:

Definition at line 972 of file pickle.py.

00972 
00973     def load_short_binstring(self):
00974         len = ord(self.read(1))
00975         data = bytes(self.read(len))
00976         value = str(data, self.encoding, self.errors)
        self.append(value)

Here is the call graph for this function:

Definition at line 1233 of file pickle.py.

01233 
01234     def load_stop(self):
01235         value = self.stack.pop()
        raise _Stop(value)

Definition at line 936 of file pickle.py.

00936 
00937     def load_string(self):
00938         orig = self.readline()
00939         rep = orig[:-1]
00940         for q in (b'"', b"'"): # double or single quote
00941             if rep.startswith(q):
00942                 if not rep.endswith(q):
00943                     raise ValueError("insecure string pickle")
00944                 rep = rep[len(q):-len(q)]
00945                 break
00946         else:
00947             raise ValueError("insecure string pickle: %r" % orig)
00948         self.append(codecs.escape_decode(rep)[0]
                    .decode(self.encoding, self.errors))

Here is the call graph for this function:

Definition at line 879 of file pickle.py.

00879 
00880     def load_true(self):
        self.append(True)

Definition at line 984 of file pickle.py.

00984 
00985     def load_tuple(self):
00986         k = self.marker()
        self.stack[k:] = [tuple(self.stack[k+1:])]

Here is the call graph for this function:

Definition at line 993 of file pickle.py.

00993 
00994     def load_tuple1(self):
        self.stack[-1] = (self.stack[-1],)

Definition at line 997 of file pickle.py.

00997 
00998     def load_tuple2(self):
        self.stack[-2:] = [(self.stack[-2], self.stack[-1])]

Definition at line 1001 of file pickle.py.

01001 
01002     def load_tuple3(self):
        self.stack[-3:] = [(self.stack[-3], self.stack[-2], self.stack[-1])]

Definition at line 963 of file pickle.py.

00963 
00964     def load_unicode(self):
        self.append(str(self.readline()[:-1], 'raw-unicode-escape'))
def pickle._Unpickler.marker (   self)

Definition at line 842 of file pickle.py.

00842 
00843     def marker(self):
00844         stack = self.stack
00845         mark = self.mark
00846         k = len(stack)-1
00847         while stack[k] is not mark: k = k-1
00848         return k

Here is the caller graph for this function:

def pickle._Unpickler.persistent_load (   self,
  pid 
)

Definition at line 849 of file pickle.py.

00849 
00850     def persistent_load(self, pid):
00851         raise UnpicklingError("unsupported persistent id encountered")

Here is the caller graph for this function:


Member Data Documentation

Definition at line 821 of file pickle.py.

Definition at line 852 of file pickle.py.

Definition at line 804 of file pickle.py.

Definition at line 805 of file pickle.py.

Definition at line 807 of file pickle.py.

Definition at line 819 of file pickle.py.

Definition at line 803 of file pickle.py.

Definition at line 806 of file pickle.py.

Definition at line 802 of file pickle.py.

Definition at line 801 of file pickle.py.

Definition at line 820 of file pickle.py.


The documentation for this class was generated from the following file: