Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Zend_Serializer_Adapter_PythonPickle Class Reference

Public Member Functions

 __construct ($opts=array())
 Constructor.
 
 setOption ($name, $value)
 Set an option.
 
 serialize ($value, array $opts=array())
 Serialize PHP to PythonPickle format.
 
 unserialize ($pickle, array $opts=array())
 Unserialize from Python Pickle format to PHP.
 
- Public Member Functions inherited from Zend_Serializer_Adapter_AdapterAbstract
 __construct ($opts=array())
 Constructor.
 
 setOptions ($opts)
 Set serializer options.
 
 setOption ($name, $value)
 Set a serializer option.
 
 getOptions ()
 Get serializer options.
 
 getOption ($name)
 Get a serializer option.
 

Public Attributes

const OP_MARK = '('
 
const OP_STOP = '.'
 
const OP_POP = '0'
 
const OP_POP_MARK = '1'
 
const OP_DUP = '2'
 
const OP_FLOAT = 'F'
 
const OP_INT = 'I'
 
const OP_BININT = 'J'
 
const OP_BININT1 = 'K'
 
const OP_LONG = 'L'
 
const OP_BININT2 = 'M'
 
const OP_NONE = 'N'
 
const OP_PERSID = 'P'
 
const OP_BINPERSID = 'Q'
 
const OP_REDUCE = 'R'
 
const OP_STRING = 'S'
 
const OP_BINSTRING = 'T'
 
const OP_SHORT_BINSTRING = 'U'
 
const OP_UNICODE = 'V'
 
const OP_BINUNICODE = 'X'
 
const OP_APPEND = 'a'
 
const OP_BUILD = 'b'
 
const OP_GLOBAL = 'c'
 
const OP_DICT = 'd'
 
const OP_EMPTY_DICT = '}'
 
const OP_APPENDS = 'e'
 
const OP_GET = 'g'
 
const OP_BINGET = 'h'
 
const OP_INST = 'i'
 
const OP_LONG_BINGET = 'j'
 
const OP_LIST = 'l'
 
const OP_EMPTY_LIST = ']'
 
const OP_OBJ = 'o'
 
const OP_PUT = 'p'
 
const OP_BINPUT = 'q'
 
const OP_LONG_BINPUT = 'r'
 
const OP_SETITEM = 's'
 
const OP_TUPLE = 't'
 
const OP_EMPTY_TUPLE = ')'
 
const OP_SETITEMS = 'u'
 
const OP_BINFLOAT = 'G'
 
const OP_PROTO = "\x80"
 
const OP_NEWOBJ = "\x81"
 
const OP_EXT1 = "\x82"
 
const OP_EXT2 = "\x83"
 
const OP_EXT4 = "\x84"
 
const OP_TUPLE1 = "\x85"
 
const OP_TUPLE2 = "\x86"
 
const OP_TUPLE3 = "\x87"
 
const OP_NEWTRUE = "\x88"
 
const OP_NEWFALSE = "\x89"
 
const OP_LONG1 = "\x8a"
 
const OP_LONG4 = "\x8b"
 
const OP_BINBYTES = 'B'
 
const OP_SHORT_BINBYTES = 'C'
 

Protected Member Functions

 _checkProtocolNumber ($number)
 Check and normalize pickle protocol number.
 
 _write ($value)
 Write a value.
 
 _writeProto ($protocol)
 Write pickle protocol.
 
 _writeGet ($id)
 Write a get.
 
 _writePut ($id)
 Write a put.
 
 _writeNull ()
 Write a null as None.
 
 _writeTrue ()
 Write a boolean true.
 
 _writeFalse ()
 Write a boolean false.
 
 _writeInt ($value)
 Write an integer value.
 
 _writeFloat ($value)
 Write a float value.
 
 _writeString ($value)
 Write a string value.
 
 _writeArrayDict (array $value)
 Write an associative array value as dictionary.
 
 _writeArrayList (array $value)
 Write a simple array value as list.
 
 _writeObject ($value)
 Write an object as an dictionary.
 
 _writeStop ()
 Write stop.
 
 _momorize ($value)
 Add a value to the memo and write the id.
 
 _searchMomo ($value)
 Search a value in the meno and return the id.
 
 _isArrayAssoc (array $value)
 Is an array associative?
 
 _quoteString ($str)
 Quote/Escape a string.
 
 _load ($op)
 Load a pickle opcode.
 
 _loadPut ()
 Load a PUT opcode.
 
 _loadBinPut ()
 Load a binary PUT.
 
 _loadLongBinPut ()
 Load a long binary PUT.
 
 _loadGet ()
 Load a GET operation.
 
 _loadBinGet ()
 Load a binary GET operation.
 
 _loadLongBinGet ()
 Load a long binary GET operation.
 
 _loadNone ()
 Load a NONE operator.
 
 _loadNewTrue ()
 Load a boolean TRUE operator.
 
 _loadNewFalse ()
 Load a boolean FALSE operator.
 
 _loadInt ()
 Load an integer operator.
 
 _loadBinInt ()
 Load a binary integer operator.
 
 _loadBinInt1 ()
 Load the first byte of a binary integer.
 
 _loadBinInt2 ()
 Load the second byte of a binary integer.
 
 _loadLong ()
 Load a long (float) operator.
 
 _loadLong1 ()
 Load a one byte long integer.
 
 _loadLong4 ()
 Load a 4 byte long integer.
 
 _loadFloat ()
 Load a float value.
 
 _loadBinFloat ()
 Load a binary float value.
 
 _loadString ()
 Load a string.
 
 _loadBinString ()
 Load a binary string.
 
 _loadShortBinString ()
 Load a short binary string.
 
 _loadBinBytes ()
 Load arbitrary binary bytes.
 
 _loadShortBinBytes ()
 Load a single binary byte.
 
 _loadUnicode ()
 Load a unicode string.
 
 _convertMatchingUnicodeSequence2Utf8 (array $match)
 Convert a unicode sequence to UTF-8.
 
 _hex2Utf8 ($hex)
 Convert a hex string to a UTF-8 string.
 
 _loadBinUnicode ()
 Load binary unicode sequence.
 
 _loadMark ()
 Load a marker sequence.
 
 _loadList ()
 Load an array (list)
 
 _loadAppend ()
 Load an append (to list) sequence.
 
 _loadEmptyList ()
 Load an empty list sequence.
 
 _loadAppends ()
 Load multiple append (to list) sequences at once.
 
 _loadDict ()
 Load an associative array (Python dictionary)
 
 _loadSetItem ()
 Load an item from a set.
 
 _loadEmptyDict ()
 Load an empty dictionary.
 
 _loadSetItems ()
 Load set items.
 
 _loadTuple ()
 Load a tuple.
 
 _loadTuple1 ()
 Load single item tuple.
 
 _loadTuple2 ()
 Load two item tuple.
 
 _loadTuple3 ()
 Load three item tuple.
 
 _loadProto ()
 Load a proto value.
 
 _read ($len)
 Read a segment of the pickle.
 
 _readline ()
 Read a line of the pickle at once.
 
 _unquoteString ($str)
 Unquote/Unescape a quoted string.
 
 _lastMarker ()
 Return last marker position in stack.
 
 _decodeBinLong ($data)
 Decode a binary long sequence.
 

Protected Attributes

 $_options
 
 $_protocol = 0
 
 $_binary = false
 
 $_memo = array()
 
 $_pickle = ''
 
 $_pickleLen = 0
 
 $_pos = 0
 
 $_stack = array()
 
 $_marker = null
 
- Protected Attributes inherited from Zend_Serializer_Adapter_AdapterAbstract
 $_options = array()
 

Static Protected Attributes

static $_isPhp6 = null
 
static $_isLittleEndian = null
 
static $_quoteString
 

Constructor & Destructor Documentation

__construct (   $opts = array())

Member Function Documentation

_checkProtocolNumber (   $number)
protected

Check and normalize pickle protocol number.

Parameters
int$number
Returns
int
Exceptions
Zend_Serializer_Exception
_convertMatchingUnicodeSequence2Utf8 ( array  $match)
protected

Convert a unicode sequence to UTF-8.

Parameters
array$match
Returns
string
_decodeBinLong (   $data)
protected

Decode a binary long sequence.

Parameters
string$data
Returns
int|float|string
_hex2Utf8 (   $hex)
protected

Convert a hex string to a UTF-8 string.

Parameters
string$sequence
Returns
string
Exceptions
Zend_Serializer_Exceptionon unmatched unicode sequence
_isArrayAssoc ( array  $value)
protected

Is an array associative?

Parameters
array$value
Returns
boolean
_lastMarker ( )
protected

Return last marker position in stack.

Returns
int
_load (   $op)
protected

Load a pickle opcode.

Parameters
string$op
Returns
void
Exceptions
Zend_Serializer_Exceptionon invalid opcode
_loadAppend ( )
protected

Load an append (to list) sequence.

Returns
void
_loadAppends ( )
protected

Load multiple append (to list) sequences at once.

Returns
void
_loadBinBytes ( )
protected

Load arbitrary binary bytes.

Returns
void
_loadBinFloat ( )
protected

Load a binary float value.

Returns
void
_loadBinGet ( )
protected

Load a binary GET operation.

Returns
void
Exceptions
Zend_Serializer_Exceptionon missing GET identifier
_loadBinInt ( )
protected

Load a binary integer operator.

Returns
void
_loadBinInt1 ( )
protected

Load the first byte of a binary integer.

Returns
void
_loadBinInt2 ( )
protected

Load the second byte of a binary integer.

Returns
void
_loadBinPut ( )
protected

Load a binary PUT.

Returns
void
Exceptions
Zend_Serializer_Exceptionon missing stack
_loadBinString ( )
protected

Load a binary string.

Returns
void
_loadBinUnicode ( )
protected

Load binary unicode sequence.

Returns
void
_loadDict ( )
protected

Load an associative array (Python dictionary)

Returns
void
_loadEmptyDict ( )
protected

Load an empty dictionary.

Returns
void
_loadEmptyList ( )
protected

Load an empty list sequence.

Returns
void
_loadFloat ( )
protected

Load a float value.

Returns
void
_loadGet ( )
protected

Load a GET operation.

Returns
void
Exceptions
Zend_Serializer_Exceptionon missing GET identifier
_loadInt ( )
protected

Load an integer operator.

Returns
void
_loadList ( )
protected

Load an array (list)

Returns
void
_loadLong ( )
protected

Load a long (float) operator.

Returns
void
_loadLong1 ( )
protected

Load a one byte long integer.

Returns
void
_loadLong4 ( )
protected

Load a 4 byte long integer.

Returns
void
_loadLongBinGet ( )
protected

Load a long binary GET operation.

Returns
void
Exceptions
Zend_Serializer_Exceptionon missing GET identifier
_loadLongBinPut ( )
protected

Load a long binary PUT.

Returns
void
Exceptions
Zend_Serializer_Exceptionon missing stack
_loadMark ( )
protected

Load a marker sequence.

Returns
void
_loadNewFalse ( )
protected

Load a boolean FALSE operator.

Returns
void
_loadNewTrue ( )
protected

Load a boolean TRUE operator.

Returns
void
_loadNone ( )
protected

Load a NONE operator.

Returns
void
_loadProto ( )
protected

Load a proto value.

Returns
void
Exceptions
Zend_Serializer_Exceptionif Pickle version does not support this feature
_loadPut ( )
protected

Load a PUT opcode.

Returns
void
Exceptions
Zend_Serializer_Exceptionon missing stack
_loadSetItem ( )
protected

Load an item from a set.

Returns
void
_loadSetItems ( )
protected

Load set items.

Returns
void
_loadShortBinBytes ( )
protected

Load a single binary byte.

Returns
void
_loadShortBinString ( )
protected

Load a short binary string.

Returns
void
_loadString ( )
protected

Load a string.

Returns
void
_loadTuple ( )
protected

Load a tuple.

Returns
void
_loadTuple1 ( )
protected

Load single item tuple.

Returns
void
_loadTuple2 ( )
protected

Load two item tuple.

Returns
void
_loadTuple3 ( )
protected

Load three item tuple.

Returns
void
_loadUnicode ( )
protected

Load a unicode string.

Returns
void
_momorize (   $value)
protected

Add a value to the memo and write the id.

Parameters
mixed$value
Returns
void
_quoteString (   $str)
protected

Quote/Escape a string.

Parameters
string$str
Returns
string quoted string
_read (   $len)
protected

Read a segment of the pickle.

Parameters
mixed$len
Returns
string
Exceptions
Zend_Serializer_Exceptionif position matches end of data
_readline ( )
protected

Read a line of the pickle at once.

Returns
string
Exceptions
Zend_Serializer_Exceptionif no EOL character found
_searchMomo (   $value)
protected

Search a value in the meno and return the id.

Parameters
mixed$value
Returns
int|false The id or false
_unquoteString (   $str)
protected

Unquote/Unescape a quoted string.

Parameters
string$strquoted string
Returns
string unquoted string
_write (   $value)
protected

Write a value.

Parameters
mixed$value
Returns
void
Exceptions
Zend_Serializer_Exceptionon invalid or unrecognized value type
_writeArrayDict ( array  $value)
protected

Write an associative array value as dictionary.

Parameters
array$value
Returns
void
_writeArrayList ( array  $value)
protected

Write a simple array value as list.

Parameters
array$value
Returns
void
_writeFalse ( )
protected

Write a boolean false.

Returns
void
_writeFloat (   $value)
protected

Write a float value.

Parameters
float$value
Returns
void
_writeGet (   $id)
protected

Write a get.

Parameters
int$idId of memo
Returns
void
_writeInt (   $value)
protected

Write an integer value.

Parameters
int$value
Returns
void
_writeNull ( )
protected

Write a null as None.

Returns
void
_writeObject (   $value)
protected

Write an object as an dictionary.

Parameters
object$value
Returns
void
_writeProto (   $protocol)
protected

Write pickle protocol.

Parameters
int$protocol
Returns
void
_writePut (   $id)
protected

Write a put.

Parameters
int$idId of memo
Returns
void
_writeStop ( )
protected

Write stop.

Returns
void
_writeString (   $value)
protected

Write a string value.

Parameters
string$value
Returns
void
_writeTrue ( )
protected

Write a boolean true.

Returns
void
serialize (   $value,
array  $opts = array() 
)

Serialize PHP to PythonPickle format.

Parameters
mixed$value
array$opts
Returns
string

Implements Zend_Serializer_Adapter_AdapterInterface.

setOption (   $name,
  $value 
)
unserialize (   $pickle,
array  $opts = array() 
)

Unserialize from Python Pickle format to PHP.

Parameters
string$pickle
array$opts
Returns
mixed
Exceptions
Zend_Serializer_Exceptionon invalid Pickle string

Implements Zend_Serializer_Adapter_AdapterInterface.

Member Data Documentation

$_binary = false
protected
$_isLittleEndian = null
staticprotected
$_isPhp6 = null
staticprotected
$_marker = null
protected
$_memo = array()
protected
$_options
protected
Initial value:
= array(
'protocol' => 0,
)
$_pickle = ''
protected
$_pickleLen = 0
protected
$_pos = 0
protected
$_protocol = 0
protected
$_quoteString
staticprotected
Initial value:
= array(
'\\' => '\\\\',
"\x00" => '\\x00', "\x01" => '\\x01', "\x02" => '\\x02', "\x03" => '\\x03',
"\x04" => '\\x04', "\x05" => '\\x05', "\x06" => '\\x06', "\x07" => '\\x07',
"\x08" => '\\x08', "\x09" => '\\t', "\x0a" => '\\n', "\x0b" => '\\x0b',
"\x0c" => '\\x0c', "\x0d" => '\\r', "\x0e" => '\\x0e', "\x0f" => '\\x0f',
"\x10" => '\\x10', "\x11" => '\\x11', "\x12" => '\\x12', "\x13" => '\\x13',
"\x14" => '\\x14', "\x15" => '\\x15', "\x16" => '\\x16', "\x17" => '\\x17',
"\x18" => '\\x18', "\x19" => '\\x19', "\x1a" => '\\x1a', "\x1b" => '\\x1b',
"\x1c" => '\\x1c', "\x1d" => '\\x1d', "\x1e" => '\\x1e', "\x1f" => '\\x1f',
"\xff" => '\\xff'
)
$_stack = array()
protected
const OP_APPEND = 'a'
const OP_APPENDS = 'e'
const OP_BINBYTES = 'B'
const OP_BINFLOAT = 'G'
const OP_BINGET = 'h'
const OP_BININT = 'J'
const OP_BININT1 = 'K'
const OP_BININT2 = 'M'
const OP_BINPERSID = 'Q'
const OP_BINPUT = 'q'
const OP_BINSTRING = 'T'
const OP_BINUNICODE = 'X'
const OP_BUILD = 'b'
const OP_DICT = 'd'
const OP_DUP = '2'
const OP_EMPTY_DICT = '}'
const OP_EMPTY_LIST = ']'
const OP_EMPTY_TUPLE = ')'
const OP_EXT1 = "\x82"
const OP_EXT2 = "\x83"
const OP_EXT4 = "\x84"
const OP_FLOAT = 'F'
const OP_GET = 'g'
const OP_GLOBAL = 'c'
const OP_INST = 'i'
const OP_INT = 'I'
const OP_LIST = 'l'
const OP_LONG = 'L'
const OP_LONG1 = "\x8a"
const OP_LONG4 = "\x8b"
const OP_LONG_BINGET = 'j'
const OP_LONG_BINPUT = 'r'
const OP_MARK = '('
const OP_NEWFALSE = "\x89"
const OP_NEWOBJ = "\x81"
const OP_NEWTRUE = "\x88"
const OP_NONE = 'N'
const OP_OBJ = 'o'
const OP_PERSID = 'P'
const OP_POP = '0'
const OP_POP_MARK = '1'
const OP_PROTO = "\x80"
const OP_PUT = 'p'
const OP_REDUCE = 'R'
const OP_SETITEM = 's'
const OP_SETITEMS = 'u'
const OP_SHORT_BINBYTES = 'C'
const OP_SHORT_BINSTRING = 'U'
const OP_STOP = '.'
const OP_STRING = 'S'
const OP_TUPLE = 't'
const OP_TUPLE1 = "\x85"
const OP_TUPLE2 = "\x86"
const OP_TUPLE3 = "\x87"
const OP_UNICODE = 'V'