Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Serialization
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Python=== The core general serialization mechanism is the <code>pickle</code> [[Python (programming language)#Libraries|standard library]] module, alluding to the database systems term ''pickling''<ref>{{cite journal|last1=Herlihy|first1=Maurice|last2=Liskov|first2=Barbara|author-link1=Maurice Herlihy|author-link2=Barbara Liskov|title=A Value Transmission Method for Abstract Data Types|journal=[[ACM Transactions on Programming Languages and Systems]]|date=October 1982|volume=4|issue=4|pages=527β551|doi=10.1145/69622.357182|url=http://cs.brown.edu/~mph/HerlihyL82/p527-herlihy.pdf|issn=0164-0925|oclc=67989840|citeseerx=10.1.1.87.5301|s2cid=8126961}}</ref><ref>{{cite book|last1=Birrell|first1=Andrew|last2=Jones|first2=Mike|last3=Wobber|first3=Ted|title=Proceedings of the eleventh ACM Symposium on Operating systems principles - SOSP '87 |chapter=A simple and efficient implementation of a small database |date=November 1987|volume=11|issue=5|pages=149β154|doi=10.1145/41457.37517|isbn=089791242X |issn=0163-5980|oclc=476062921|quote=Our implementation makes use of a mechanism called βpicklesβ, which will convert between any strongly typed data structure and a representation of that structure suitable for storing in permanent disk files. The operation Pickle.Write takes a pointer to a strongly typed data structure and delivers buffers of bits for writing to the disk. Conversely Pickle.Read reads buffers of bits from the disk and delivers a copy of the original data structure.(*) This conversion involves identifying the occurrences of addresses in the structure, and arranging that when the structure is read back from disk the addresses are replaced with addresses valid in the current execution environment. The pickle mechanism is entirely automatic: it is driven by the run-time typing structures that are present for our garbage collection mechanism. ... (*) Pickling is quite similar to the concept of marshalling in remote procedure calls. But in fact our pickling implementation works only by interpreting at run-time the structure of [[dynamically typed]] values, while our RPC implementation works only by generating code for the marshalling of statically typed values. Each facility would benefit from adding the mechanisms of the other, but that has not yet been done.|citeseerx=10.1.1.100.1457|s2cid=12908261}}</ref><ref>{{cite web|last1=van Rossum|first1=Guido|author-link1=Guido van Rossum|title=Flattening Python Objects|url=http://legacy.python.org/workshops/1994-11/FlattenPython.html|website=Python Programming Language β Legacy Website|publisher=[[Python Software Foundation]]|access-date=6 April 2017|location=[[Delaware]], United States|date=1 December 1994|quote=Origin of the name 'flattening': Because I want to leave the original 'marshal' module alone, and Jim complained that 'serialization' also means something totally different that's actually relevant in the context of [[Concurrent computing|concurrent]] access to persistent objects, I'll use the term 'flattening' from now on. ... (The Modula-3 system uses the term 'pickled' data for this concept. They have probably solved all problems already, and in a type-safe manner :-)}}</ref> to describe data serialization (''unpickling'' for ''deserializing''). Pickle uses a simple [[Stack (abstract data type)|stack]]-based [[virtual machine]] that records the instructions used to reconstruct the object. It is a cross-version [https://docs.python.org/library/pickle.html#pickle-protocol customisable] but unsafe (not secure against erroneous or malicious data) serialization format. Malformed or maliciously constructed data, may cause the deserializer to import arbitrary modules and instantiate any object.<ref name=autogenerated1>{{cite web|url=https://docs.python.org/2/library/pickle.html|title=11.1. pickle β Python object serialization β Python 2.7.14rc1 documentation|website=docs.python.org}}</ref><ref>{{cite web|url=https://docs.python.org/release/3.0.1/library/pickle.html#pickle-restrict|title=pickle β Python object serialization β Python v3.0.1 documentation|website=docs.python.org}}</ref> The standard library also includes modules serializing to standard data formats: <code>[https://docs.python.org/library/json.html json]</code> (with built-in support for basic scalar and collection types and able to support arbitrary types via [https://docs.python.org/library/json.html#encoders-and-decoders encoding and decoding hooks]). <code>[https://docs.python.org/library/plistlib.html plistlib]</code> (with support for both binary and XML [[property list]] formats). <code>[https://docs.python.org/library/xdrlib.html xdrlib]</code> (with support for the External Data Representation (XDR) standard as described in RFC 1014). Finally, it is recommended that an object's <code>[https://docs.python.org/reference/datamodel.html#object.__repr__ __repr__]</code> be evaluable in the right environment, making it a rough match for Common Lisp's <code>[http://www.lispworks.com/documentation/HyperSpec/Body/f_pr_obj.htm print-object]</code>. Not all object types can be pickled automatically, especially ones that hold [[operating system]] resources like [[file handle]]s, but users can register custom "reduction" and construction functions to support the pickling and unpickling of arbitrary types. Pickle was originally implemented as the pure Python <code>pickle</code> module, but, in versions of Python prior to 3.0, the <code>cPickle</code> module (also a built-in) offers improved performance (up to 1000 times faster<ref name=autogenerated1 />). The <code>cPickle</code> was adapted from the [[Unladen Swallow]] project. In Python 3, users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version.<ref>{{cite web|url=https://docs.python.org/release/3.1.5/whatsnew/3.0.html|title=What's New In Python 3.0 β Python v3.1.5 documentation|website=docs.python.org}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)