~ubuntu-branches/ubuntu/karmic/python3.0/karmic

« back to all changes in this revision

Viewing changes to Lib/pickletools.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-16 17:18:23 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090216171823-1d5cm5qnnjvmnzzm
Tags: 3.0.1-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
527
527
    """
528
528
 
529
529
    s = read_stringnl(f, decode=False, stripquotes=False)
 
530
    if s[-1:] == b'L':
 
531
        s = s[:-1]
530
532
    return int(s)
531
533
 
532
534
 
2052
2054
    1: l        LIST       (MARK at 0)
2053
2055
    2: p    PUT        0
2054
2056
    5: L    LONG       1
2055
 
    8: a    APPEND
2056
 
    9: L    LONG       2
2057
 
   12: a    APPEND
2058
 
   13: (    MARK
2059
 
   14: L        LONG       3
2060
 
   17: L        LONG       4
2061
 
   20: t        TUPLE      (MARK at 13)
2062
 
   21: p    PUT        1
2063
 
   24: a    APPEND
2064
 
   25: (    MARK
2065
 
   26: d        DICT       (MARK at 25)
2066
 
   27: p    PUT        2
2067
 
   30: c    GLOBAL     'builtins bytes'
2068
 
   46: p    PUT        3
2069
 
   49: (    MARK
2070
 
   50: (        MARK
2071
 
   51: l            LIST       (MARK at 50)
2072
 
   52: p        PUT        4
2073
 
   55: L        LONG       97
2074
 
   59: a        APPEND
2075
 
   60: L        LONG       98
 
2057
    9: a    APPEND
 
2058
   10: L    LONG       2
 
2059
   14: a    APPEND
 
2060
   15: (    MARK
 
2061
   16: L        LONG       3
 
2062
   20: L        LONG       4
 
2063
   24: t        TUPLE      (MARK at 15)
 
2064
   25: p    PUT        1
 
2065
   28: a    APPEND
 
2066
   29: (    MARK
 
2067
   30: d        DICT       (MARK at 29)
 
2068
   31: p    PUT        2
 
2069
   34: c    GLOBAL     'builtins bytes'
 
2070
   50: p    PUT        3
 
2071
   53: (    MARK
 
2072
   54: (        MARK
 
2073
   55: l            LIST       (MARK at 54)
 
2074
   56: p        PUT        4
 
2075
   59: L        LONG       97
2076
2076
   64: a        APPEND
2077
 
   65: L        LONG       99
2078
 
   69: a        APPEND
2079
 
   70: t        TUPLE      (MARK at 49)
2080
 
   71: p    PUT        5
2081
 
   74: R    REDUCE
2082
 
   75: p    PUT        6
2083
 
   78: V    UNICODE    'def'
2084
 
   83: p    PUT        7
2085
 
   86: s    SETITEM
2086
 
   87: a    APPEND
2087
 
   88: .    STOP
 
2077
   65: L        LONG       98
 
2078
   70: a        APPEND
 
2079
   71: L        LONG       99
 
2080
   76: a        APPEND
 
2081
   77: t        TUPLE      (MARK at 53)
 
2082
   78: p    PUT        5
 
2083
   81: R    REDUCE
 
2084
   82: p    PUT        6
 
2085
   85: V    UNICODE    'def'
 
2086
   90: p    PUT        7
 
2087
   93: s    SETITEM
 
2088
   94: a    APPEND
 
2089
   95: .    STOP
2088
2090
highest protocol among opcodes = 0
2089
2091
 
2090
2092
Try again with a "binary" pickle.
2126
2128
 
2127
2129
Exercise the INST/OBJ/BUILD family.
2128
2130
 
2129
 
>>> import random
2130
 
>>> dis(pickle.dumps(random.getrandbits, 0))
2131
 
    0: c    GLOBAL     'random getrandbits'
2132
 
   20: p    PUT        0
2133
 
   23: .    STOP
 
2131
>>> import pickletools
 
2132
>>> dis(pickle.dumps(pickletools.dis, 0))
 
2133
    0: c    GLOBAL     'pickletools dis'
 
2134
   17: p    PUT        0
 
2135
   20: .    STOP
2134
2136
highest protocol among opcodes = 0
2135
2137
 
2136
2138
>>> from pickletools import _Example
2157
2159
   92: V    UNICODE    'value'
2158
2160
   99: p    PUT        7
2159
2161
  102: L    LONG       42
2160
 
  106: s    SETITEM
2161
 
  107: b    BUILD
2162
 
  108: a    APPEND
2163
 
  109: g    GET        5
2164
 
  112: a    APPEND
2165
 
  113: .    STOP
 
2162
  107: s    SETITEM
 
2163
  108: b    BUILD
 
2164
  109: a    APPEND
 
2165
  110: g    GET        5
 
2166
  113: a    APPEND
 
2167
  114: .    STOP
2166
2168
highest protocol among opcodes = 0
2167
2169
 
2168
2170
>>> dis(pickle.dumps(x, 1))