File: __init__.py

package info (click to toggle)
duo-unix 1.11.3-1.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,892 kB
  • sloc: sh: 12,108; ansic: 9,223; python: 1,639; makefile: 156
file content (41 lines) | stat: -rw-r--r-- 1,182 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/python -OOOO
# vim: set fileencoding=utf8 shiftwidth=4 tabstop=4 textwidth=80 foldmethod=marker :
# Copyright (c) 2010, Kou Man Tong. All rights reserved.
# For licensing, see LICENSE file included in the package.
"""
BSON serialization and deserialization logic.
Specifications taken from: http://bsonspec.org/#/specification
The following types are unsupported, because for data exchange purposes, they're
over-engineered:
	0x06 (Undefined)
	0x07 (ObjectId)
	0x09 (UTC datetime - Sorry, but Python's datetime module sucks.
		datetime.now() has no timezone? Seriously?! Simple timestamps will save
		you a lot of trouble)
	0x0b (Regex - Exactly which flavor do you want? Better let higher level
		programmers make that decision.)
	0x0c (DBPointer)
	0x0d (JavaScript code)
	0x0e (Symbol)
	0x0f (JS w/ scope)
	0x11 (MongoDB-specific timestamp)

For binaries, only the default 0x0 type is supported.
"""

from codec import *
__all__ = ["loads", "dumps"]

# {{{ Public API
def dumps(obj):
	"""
	Given a dict, outputs a BSON string.
	"""
	return encode_document(obj)

def loads(data):
	"""
	Given a BSON string, outputs a dict.
	"""
	return decode_document(data, 0)[1]
# }}}