Class: Python::Pickle::Protocol1 Private

Inherits:
Protocol0 show all
Defined in:
lib/python/pickle/protocol1.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Implements reading and writing of Python Pickle protocol 1.

Direct Known Subclasses

Protocol2

Constant Summary collapse

EMPTY_TUPLE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The EMPTY_TUPLE opcode.

41
BINFLOAT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The BINFLOAT opcode.

71
BININT1 =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The BININT1 opcode.

75
BINSTRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The BINSTRING opcode.

84
SHORT_BINSTRING =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The SHORT_BINSTRING opcode.

85
BINUNICODE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The BINUNICODE opcode.

88
EMPTY_LIST =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The EMPTY_LIST opcode.

93
APPENDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The APPENDS opcode.

101
BINGET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The BINGET opcode.

104
LONG_BINGET =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The LONG_BINGET opcode.

106
BINPUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The BINPUT opcode.

113
SETITEMS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The SETITEMS opcode.

117
EMPTY_DICT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The EMPTY_DICT opcode.

125

Constants inherited from Protocol0

Python::Pickle::Protocol0::APPEND, Python::Pickle::Protocol0::BINPERSID, Python::Pickle::Protocol0::BUILD, Python::Pickle::Protocol0::DICT, Python::Pickle::Protocol0::DUP, Python::Pickle::Protocol0::FLOAT, Python::Pickle::Protocol0::GET, Python::Pickle::Protocol0::GLOBAL, Python::Pickle::Protocol0::INST, Python::Pickle::Protocol0::INT, Python::Pickle::Protocol0::LIST, Python::Pickle::Protocol0::LONG, Python::Pickle::Protocol0::MARK, Python::Pickle::Protocol0::NONE, Python::Pickle::Protocol0::OBJ, Python::Pickle::Protocol0::PERSID, Python::Pickle::Protocol0::POP, Python::Pickle::Protocol0::POP_MARK, Python::Pickle::Protocol0::PUT, Python::Pickle::Protocol0::REDUCE, Python::Pickle::Protocol0::SETITEM, Python::Pickle::Protocol0::STOP, Python::Pickle::Protocol0::STRING, Python::Pickle::Protocol0::TUPLE, Python::Pickle::Protocol0::UNICODE

Instance Attribute Summary

Attributes inherited from Protocol

#io

Instance Method Summary collapse

Methods inherited from Protocol0

#read_escaped_char, #read_float, #read_float_instruction, #read_get_instruction, #read_global_instruction, #read_hex_escaped_char, #read_inst_instruction, #read_int, #read_int_instruction, #read_long, #read_long_instruction, #read_nl_string, #read_persid_instruction, #read_put_instruction, #read_string, #read_string_instruction, #read_unicode_escaped_char, #read_unicode_escaped_char16, #read_unicode_escaped_char32, #read_unicode_instruction, #read_unicode_string

Methods inherited from Protocol

#initialize, #read

Constructor Details

This class inherits a constructor from Python::Pickle::Protocol

Instance Method Details

#read_binfloat_instructionInstructions::BinFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a BINFLOAT instruction.

Returns:

Since:

  • 0.2.0



223
224
225
# File 'lib/python/pickle/protocol1.rb', line 223

def read_binfloat_instruction
  Instructions::BinFloat.new(read_float64_be)
end

#read_binget_instructionInstructions::BinGet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a BINGET instruction.

Returns:

Since:

  • 0.2.0



287
288
289
# File 'lib/python/pickle/protocol1.rb', line 287

def read_binget_instruction
  Instructions::BinGet.new(read_uint8)
end

#read_binint1_instructionInstructions::BinInt1

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a BININT1 instruction.

Returns:

Since:

  • 0.2.0



234
235
236
# File 'lib/python/pickle/protocol1.rb', line 234

def read_binint1_instruction
  Instructions::BinInt1.new(read_uint8)
end

#read_binput_instructionInstructions::BinPut

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a BINPUT instruction.

Returns:

Since:

  • 0.2.0



309
310
311
# File 'lib/python/pickle/protocol1.rb', line 309

def read_binput_instruction
  Instructions::BinPut.new(read_uint8)
end

#read_binstring_instructionInstructions::BinString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a BINSTRING instruction.

Returns:

Since:

  • 0.2.0



245
246
247
248
249
250
# File 'lib/python/pickle/protocol1.rb', line 245

def read_binstring_instruction
  length = read_uint32_le
  string = @io.read(length)

  Instructions::BinString.new(length,string)
end

#read_binunicode_instructionInstructions::BinUnicode

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a BINUNICODE instruction.

Returns:

Since:

  • 0.2.0



273
274
275
276
277
278
# File 'lib/python/pickle/protocol1.rb', line 273

def read_binunicode_instruction
  length = read_uint32_le
  string = @io.read(length).force_encoding(Encoding::UTF_8)

  Instructions::BinUnicode.new(length,string)
end

#read_float64_beFloat

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a double precision (64bit) floating point number, in network byte-order (big-endian).

Returns:

  • (Float)

    The decoded float.



194
195
196
# File 'lib/python/pickle/protocol1.rb', line 194

def read_float64_be
  @io.read(8).unpack1('G')
end

#read_instructionInstruction

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads an instruction from the pickle stream.

Returns:

Raises:



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/python/pickle/protocol1.rb', line 136

def read_instruction
  case (opcode = @io.getbyte)
  #
  # Protocol 0 instructions
  #
  when MARK      then Instructions::MARK
  when STOP      then Instructions::STOP
  when POP       then Instructions::POP
  when POP_MARK  then Instructions::POP_MARK
  when DUP       then Instructions::DUP
  when FLOAT     then read_float_instruction
  when INT       then read_int_instruction
  when LONG      then read_long_instruction
  when NONE      then Instructions::NONE
  when REDUCE    then Instructions::REDUCE
  when STRING    then read_string_instruction
  when UNICODE   then read_unicode_instruction
  when APPEND    then Instructions::APPEND
  when BUILD     then Instructions::BUILD
  when GLOBAL    then read_global_instruction
  when DICT      then Instructions::DICT
  when GET       then read_get_instruction
  when LIST      then Instructions::LIST
  when PUT       then read_put_instruction
  when SETITEM   then Instructions::SETITEM
  when TUPLE     then Instructions::TUPLE
  when INST      then read_inst_instruction
  when OBJ       then Instructions::OBJ
  when PERSID    then read_persid_instruction
  when BINPERSID then Instructions::BINPERSID
  #
  # Protocol 1 instructions
  #
  when EMPTY_TUPLE     then Instructions::EMPTY_TUPLE
  when BINFLOAT        then read_binfloat_instruction
  when BININT1         then read_binint1_instruction
  when BINSTRING       then read_binstring_instruction
  when SHORT_BINSTRING then read_short_binstring_instruction
  when BINUNICODE      then read_binunicode_instruction
  when EMPTY_LIST      then Instructions::EMPTY_LIST
  when APPENDS         then Instructions::APPENDS
  when BINGET          then read_binget_instruction
  when LONG_BINGET     then read_long_binget_instruction
  when BINPUT          then read_binput_instruction
  when SETITEMS        then Instructions::SETITEMS
  when EMPTY_DICT      then Instructions::EMPTY_DICT
  else
    raise(InvalidFormat,"invalid opcode (#{opcode.inspect}) for protocol 1")
  end
end

#read_long_binget_instructionInstructions::LongBinGet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a LONG_BINGET instruction.

Returns:

Since:

  • 0.2.0



298
299
300
# File 'lib/python/pickle/protocol1.rb', line 298

def read_long_binget_instruction
  Instructions::LongBinGet.new(read_uint32_le)
end

#read_short_binstring_instructionInstructions::ShortBinString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a SHORT_BINSTRING instruction.

Returns:

Since:

  • 0.2.0



259
260
261
262
263
264
# File 'lib/python/pickle/protocol1.rb', line 259

def read_short_binstring_instruction
  length = read_uint8
  string = @io.read(length)

  Instructions::ShortBinString.new(length,string)
end

#read_uint32_leInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads an unsigned 32bit integer, in little-endian byte-order.

Returns:

  • (Integer)


212
213
214
# File 'lib/python/pickle/protocol1.rb', line 212

def read_uint32_le
  @io.read(4).unpack1('L<')
end

#read_uint8Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reads a single 8bit unsigned integer (byte).

Returns:

  • (Integer)


203
204
205
# File 'lib/python/pickle/protocol1.rb', line 203

def read_uint8
  @io.getbyte
end