1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 The low level BER based encoding used by spoon to serialize objects.
25
26 Users of the spoon library will probably not need to use this package
27 at all.
28 """
29
30 from cStringIO import StringIO
31
32 from common import UNIVERSAL, APPLICATION, CONTEXT, PRIVATE
33 from common import BERException
34
35 from tag import Tag
36 from stream import BERStream, encoder, zencoder, decoder, encode_container, decode_container
37 from stream import EOF_TYPE, NULL_TYPE, INT_TYPE, BYTES_TYPE, UTF8_TYPE, LIST_TYPE
38
39
41 """
42 Encode one or more python objects into a ber stream, written to the
43 given file object.
44 """
45 b = BERStream(fd)
46 for x in items:
47 b.add(x)
48
49
51 """
52 Decode a ber-encoded python object from a file object and return it.
53 """
54 return BERStream(fd).next()
55
56
58 """
59 Encode one or more python objects into a ber stream, and return the
60 encoded string.
61 """
62 s = StringIO()
63 encode_stream(s, *items)
64 return s.getvalue()
65
66
68 """
69 Decode a python object from a ber-encoded string and return it.
70 """
71 return decode_stream(StringIO(s))
72
73 for x in [decode, encode, decode_stream, encode_stream, BERException, Tag,
74 BERStream, encoder, zencoder,
75 decoder, encode_container, decode_container,
76 EOF_TYPE, NULL_TYPE, INT_TYPE, BYTES_TYPE, UTF8_TYPE, LIST_TYPE]:
77 x.__module__ = "spoon.ber"
78
79 __all__ = ["decode",
80 "encode",
81 "decode_stream",
82 "encode_stream",
83 "UNIVERSAL",
84 "APPLICATION",
85 "CONTEXT",
86 "PRIVATE",
87 "BERException",
88 "Tag",
89 "BERStream",
90 "encoder",
91 "zencoder",
92 "decoder",
93 "encode_container",
94 "decode_container",
95 "EOF_TYPE",
96 "NULL_TYPE",
97 "INT_TYPE",
98 "BYTES_TYPE",
99 "UTF8_TYPE",
100 "LIST_TYPE"]
101