Dogeon Documentation. Release Lin Ju

Similar documents
json-rpc Documentation

LECTURE 20. Serialization and Data Persistence

python-rapidjson Documentation

JSONRPC Documentation

msgpack Documentation

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

pyprika Documentation

pybdg Documentation Release 1.0.dev2 Outernet Inc

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Babu Madhav Institute of Information Technology, UTU 2015

Kaiso Documentation. Release 0.1-dev. onefinestay

Python Essential Reference, Second Edition - Chapter 5: Control Flow Page 1 of 8

streamio Documentation

redis-lua Documentation

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

prompt Documentation Release Stefan Fischer

Serialization. Lab 1 JSON

Advanced Algorithms and Computational Models (module A)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Control Structures 1 / 17

Java Basic Datatypees

IHIH Documentation. Release Romain Dartigues

Java Bytecode (binary file)

DaMPL. Language Reference Manual. Henrique Grando

Princeton University. Computer Science 217: Introduction to Programming Systems. Data Types in C

sqlalchemy-redshift Documentation

Armide Documentation. Release Kyle Mayes

databuild Documentation

Language Reference Manual

OstrichLib Documentation

pylatexenc Documentation

Advanced Python. Executive Summary, Session 1

Syntax and Grammars 1 / 21

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

Lecture #13: More Sequences and Strings. Last modified: Tue Mar 18 16:17: CS61A: Lecture #13 1

tolerance Documentation

COMP6700/2140 Data and Types

6. Data Types and Dynamic Typing (Cont.)

Programming in Python 3

ML 4 A Lexer for OCaml s Type System

lina Documentation Release Author

Python in 10 (50) minutes

Files. Files need to be opened in Python before they can be read from or written into Files are opened in Python using the open() built-in function

SCHEME INTERPRETER GUIDE 4

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

3 The Building Blocks: Data Types, Literals, and Variables

configobj Documentation

Python Tutorial. Day 1

CS 115 Lecture 4. More Python; testing software. Neil Moore

This tutorial will help you understand JSON and its use within various programming languages such as PHP, PERL, Python, Ruby, Java, etc.

VLC : Language Reference Manual

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

Variables, Constants, and Data Types

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

freeze Documentation Release 0.7.0alpha Jean-Louis Fuchs

Tagalog Documentation

The Pyth Language. Administrivia

CSE : Python Programming

htmlmin Documentation

pyvcd Documentation Release Peter Grayson and Steven Sprouse

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Exercise: Using Numbers

Language Reference Manual

Basic data types. Building blocks of computation

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Json Parse Error - No Json Object Could Be Decoded Django Rest Framework

Full file at

Variables and Values

The type of all data used in a C (or C++) program must be specified

pymemcache Documentation

Python. Executive Summary

Question 1. tmp = Stack() # Transfer every item from stk onto tmp. while not stk.is_empty(): tmp.push(stk.pop())

Coral Programming Language Reference Manual

CSC148 Fall 2017 Ramp Up Session Reference

Key Differences Between Python and Java

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

Strings are actually 'objects' Strings

pygtrie Release Jul 03, 2017

PYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s

Part III Appendices 165


Basic types and definitions. Chapter 3 of Thompson

Lecture no

TH IRD EDITION. Python Cookbook. David Beazley and Brian K. Jones. O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo

CIS192 Python Programming

CS 541 Spring Programming Assignment 2 CSX Scanner

CIS192 Python Programming

FRAC: Language Reference Manual

Binary Encodings for JavaScript Object Notation: JSON-B, JSON-C, JSON-D

CIS192 Python Programming

Introduction to Bioinformatics

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

WordEmbeddingLoader Documentation

APT Session 2: Python

Lecture #12: Quick: Exceptions and SQL

New York University School of Continuing and Professional Studies Management and Information Technology. Advanced Python. Homework, Session 5

Lecture 21. Programming with Subclasses

Transcription:

Dogeon Documentation Release 1.0.0 Lin Ju June 07, 2014

Contents 1 Indices and tables 7 Python Module Index 9 i

ii

DSON (Doge Serialized Object Notation) <http://dogeon.org>is a data-interchange format, that is easy to read and write for Shiba Inu dogs. It is easy for machines to parse and generate. It is designed to be as similiar as possible to the DogeScript Programming Language. DSON is a text format that is not language independent but uses conventions that are familiar to a wide variety of japanese dog breeds. These properties make DSON an ideal data-interchange language for everything that involves Shiba Inu intercommunication. dson exposes an API familiar to users of the standard library marshal and pickle modules. It is the externally maintained version of the dson library contained in Python 2.6, but maintains compatibility with Python 2.4 and Python 2.5 and (currently) has significant performance advantages, even without using the optional C extension for speedups. Encoding basic Python object hierarchies: >>> import dson >>> dson.dumps([ foo, { bar : ( baz, None, 1.0, 2)}]) so "foo" and such "bar" is so "baz" and empty and 1.0 and 2 many wow many >>> print dson.dumps("\"foo\bar") "\"foo\bar" >>> print dson.dumps(u \u1234 ) "\u1234" >>> print dson.dumps( \\ ) "\\" >>> print dson.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=true) such "a" is 0, "b" is 0, "c" is 0 wow >>> from StringIO import StringIO >>> io = StringIO() >>> dson.dump([ streaming API ], io) >>> io.getvalue() so "streaming API" many Compact encoding: >>> import dson >>> dson.dumps([1,2,3,{ 4 : 5, 6 : 7}], sort_keys=true) so 1 and 2 and 3 and such "4" is 5,"6" is 7 wow many Pretty printing: >>> import dson >>> print dson.dumps({ 4 : 5, 6 : 7}, sort_keys=true, indent=4) such "4" is 5, "6" is 7 wow Decoding DSON: >>> import dson >>> obj = [u foo, {u bar : [u baz, None, 1.0, 2]}] >>> dson.loads( so "foo" and such "bar" is so "baz" and empty and 1.0 and 2 many wow many ) == obj True >>> dson.loads( "\\"foo\\bar" ) == u "foo\x08ar True >>> from StringIO import StringIO >>> io = StringIO( so "streaming API" many ) >>> dson.load(io)[0] == streaming API True Specializing DSON object decoding: Contents 1

>>> import dson >>> def as_complex(dct):... if complex in dct:... return complex(dct[ real ], dct[ imag ])... return dct... >>> dson.loads( such " complex " is yes, "real" is 1, "imag" is 2 wow,... object_hook=as_complex) (1+2j) >>> from decimal import Decimal >>> dson.loads( 1.1, parse_float=decimal) == Decimal( 1.1 ) True Specializing DSON object encoding: >>> import dson >>> def encode_complex(obj):... if isinstance(obj, complex):... return [obj.real, obj.imag]... raise TypeError(repr(o) + " is not DSON serializable")... >>> dson.dumps(2 + 1j, default=encode_complex) so 2.0 and 1.0 many >>> dson.dsonencoder(default=encode_complex).encode(2 + 1j) so 2.0 and 1.0 many >>>.join(dson.dsonencoder(default=encode_complex).iterencode(2 + 1j)) so 2.0 and 1.0 many todo Using dson.tool from the shell to validate and pretty-print: $ echo such "dson" is "obj" wow python -m dson.tool { "dson": "obj" } $ echo such 1.2 is 3.4 wow python -m dson.tool Expecting property name enclosed in double quotes: line 1 column 3 (char 2) dson.dump(obj, fp, skipkeys=false, ensure_ascii=true, check_circular=true, allow_nan=true, cls=none, indent=none, separators=none, encoding= utf-8, default=none, sort_keys=false, **kw) Serialize obj as a DSON formatted stream to fp (a.write()-supporting file-like object). If skipkeys is true then dict keys that are not basic types (str, unicode, int, long, float, bool, None) will be skipped instead of raising a TypeError. If ensure_ascii is true (the default), all non-ascii characters in the output are escaped with \uxxxx sequences, and the result is a str instance consisting of ASCII characters only. If ensure_ascii is False, some chunks written to fp may be unicode instances. This usually happens because the input contains unicode strings or the encoding parameter is used. Unless fp.write() explicitly understands unicode (as in codecs.getwriter) this is likely to cause an error. If check_circular is false, then the circular reference check for container types will be skipped and a circular reference will result in an OverflowError (or worse). If allow_nan is false, then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the DSON specification, instead of using the JavaScript equivalents (NaN, Infinity, -Infinity). If indent is a non-negative integer, then DSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. Since 2 Contents

the default item separator is,, the output might include trailing whitespace when indent is specified. You can use separators=(,, : ) to avoid this. If separators is an (item_separator, dict_separator) tuple then it will be used instead of the default ( and, is ) separators. ( and, is ) is the most compact DSON representation. encoding is the character encoding for str instances, default is UTF-8. default(obj) is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError. If sort_keys is True (default: False), then the output of dictionaries will be sorted by key. To use a custom DSONEncoder subclass (e.g. one that overrides the.default() method to serialize additional types), specify it with the cls kwarg; otherwise DSONEncoder is used. dson.dumps(obj, skipkeys=false, ensure_ascii=true, check_circular=true, allow_nan=true, cls=none, indent=none, separators=none, encoding= utf-8, default=none, sort_keys=false, **kw) Serialize obj to a DSON formatted str. If skipkeys is false then dict keys that are not basic types (str, unicode, int, long, float, bool, None) will be skipped instead of raising a TypeError. If ensure_ascii is false, all non-ascii characters are not escaped, and the return value may be a unicode instance. See dump for details. If check_circular is false, then the circular reference check for container types will be skipped and a circular reference will result in an OverflowError (or worse). If allow_nan is false, then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the DSON specification, instead of using the JavaScript equivalents (NaN, Infinity, -Infinity). If indent is a non-negative integer, then DSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. Since the default item separator is,, the output might include trailing whitespace when indent is specified. You can use separators=( and, is ) to avoid this. If separators is an (item_separator, dict_separator) tuple then it will be used instead of the default ( and, is ) separators. ( and, is ) is the most compact DSON representation. encoding is the character encoding for str instances, default is UTF-8. default(obj) is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError. If sort_keys is True (default: False), then the output of dictionaries will be sorted by key. To use a custom DSONEncoder subclass (e.g. one that overrides the.default() method to serialize additional types), specify it with the cls kwarg; otherwise DSONEncoder is used. dson.load(fp, encoding=none, cls=none, object_hook=none, parse_float=none, parse_int=none, parse_constant=none, object_pairs_hook=none, **kw) Deserialize fp (a.read()-supporting file-like object containing a DSON document) to a Python object. If the contents of fp is encoded with an ASCII based encoding other than utf-8 (e.g. latin-1), then an appropriate encoding name must be specified. Encodings that are not ASCII based (such as UCS-2) are not allowed, and should be wrapped with codecs.getreader(fp)(encoding), or simply decoded to a unicode object and passed to loads() object_hook is an optional function that will be called with the result of any object literal decode (a dict). The return value of object_hook will be used instead of the dict. This feature can be used to implement custom decoders (e.g. DSON-RPC class hinting). Contents 3

object_pairs_hook is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.ordereddict will remember the order of insertion). If object_hook is also defined, the object_pairs_hook takes priority. To use a custom DSONDecoder subclass, specify it with the cls kwarg; otherwise DSONDecoder is used. dson.loads(s, encoding=none, cls=none, object_hook=none, parse_float=none, parse_int=none, parse_constant=none, object_pairs_hook=none, **kw) Deserialize s (a str or unicode instance containing a DSON document) to a Python object. If s is a str instance and is encoded with an ASCII based encoding other than utf-8 (e.g. latin-1) then an appropriate encoding name must be specified. Encodings that are not ASCII based (such as UCS-2) are not allowed and should be decoded to unicode first. object_hook is an optional function that will be called with the result of any object literal decode (a dict). The return value of object_hook will be used instead of the dict. This feature can be used to implement custom decoders (e.g. DSON-RPC class hinting). object_pairs_hook is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.ordereddict will remember the order of insertion). If object_hook is also defined, the object_pairs_hook takes priority. parse_float, if specified, will be called with the string of every DSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for DSON floats (e.g. decimal.decimal). parse_int, if specified, will be called with the string of every DSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for DSON integers (e.g. float). parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN, null, true, false. This can be used to raise an exception if invalid DSON numbers are encountered. To use a custom DSONDecoder subclass, specify it with the cls kwarg; otherwise DSONDecoder is used. Implementation of DSONDecoder class dson.decoder.dsondecoder(encoding=none, object_hook=none, parse_float=none, parse_int=none, parse_constant=none, strict=true, object_pairs_hook=none) Simple DSON decoder Performs the following translations in decoding by default: DSON object array string number (int) number (real) yes no empty Python dict list unicode int, long float True False None It also understands NaN, Infinity, and -Infinity as their corresponding float values, which is outside the DSON spec. encoding determines the encoding used to interpret any str objects decoded by this instance (utf-8 by default). It has no effect when decoding unicode objects. 4 Contents

Note that currently only encodings that are a superset of ASCII work, strings of other encodings should be passed in as unicode. object_hook, if specified, will be called with the result of every DSON object decoded and its return value will be used in place of the given dict. This can be used to provide custom deserializations (e.g. to support DSON-RPC class hinting). object_pairs_hook, if specified will be called with the result of every DSON object decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, collections.ordereddict will remember the order of insertion). If object_hook is also defined, the object_pairs_hook takes priority. parse_float, if specified, will be called with the string of every DSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for DSON floats (e.g. decimal.decimal). parse_int, if specified, will be called with the string of every DSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for DSON integers (e.g. float). parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN. This can be used to raise an exception if invalid DSON numbers are encountered. If strict is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including \t (tab), \n, \r and \0. decode(s, _w=<built-in method match of _sre.sre_pattern object at 0x7ffc6b8285d0>) Return the Python representation of s (a str or unicode instance containing a DSON document) raw_decode(s, idx=0) Decode a DSON document from s (a str or unicode beginning with a DSON document) and return a 2-tuple of the Python representation and the index in s where the document ended. This can be used to decode a DSON document from a string that may have extraneous data at the end. Implementation of DSONEncoder class dson.encoder.dsonencoder(skipkeys=false, ensure_ascii=true, check_circular=true, allow_nan=true, sort_keys=false, indent=none, separators=none, encoding= utf-8, default=none) Extensible DSON encoder for Python data structures. Supports the following objects and types by default: Python dict list, tuple str, unicode int, long, float True False None DSON object array string number yes no empty To extend this to recognize other objects, subclass and implement a.default() method with another method that returns a serializable object for o if possible, otherwise it should call the superclass implementation (to raise TypeError). Constructor for DSONEncoder, with sensible defaults. If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, long, float or None. If skipkeys is True, such items are simply skipped. Contents 5

If ensure_ascii is true (the default), all non-ascii characters in the output are escaped with uxxxx sequences, and the results are str instances consisting of ASCII characters only. If ensure_ascii is False, a result may be a unicode instance. This usually happens if the input contains unicode strings or the encoding parameter is used. If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place. If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not DSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats. If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that DSON serializations can be compared on a day-to-day basis. If indent is a non-negative integer, then DSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation. Since the default item separator is and, the output might include trailing whitespace when indent is specified. You can use separators=( and, is ) to avoid this. If specified, separators should be a (item_separator, key_separator) tuple. The default is ( and, is ). To get the most compact DSON representation you should specify ( and, is ) to eliminate whitespace. If specified, default is a function that gets called for objects that can t otherwise be serialized. It should return a DSON encodable version of the object or raise a TypeError. If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to DSON-encoding. The default is UTF-8. default(o) Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError). For example, to support arbitrary iterators, you could implement default like this: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return DSONEncoder.default(self, o) encode(o) Return a DSON string representation of a Python data structure. >>> DSONEncoder().encode({"foo": ["bar", "baz"]}) such "foo" is so "bar" and "baz" many wow iterencode(o, _one_shot=false) Encode the given object and yield each string representation as available. For example: for chunk in DSONEncoder().iterencode(bigobject): mysocket.write(chunk) 6 Contents

CHAPTER 1 Indices and tables genindex modindex search 7

8 Chapter 1. Indices and tables

Python Module Index d dson, 7 dson.decoder, 4 dson.encoder, 5 9