transit-python 0.8.228-__py2-none-any.whl → 0.8.240__py2-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
scratch/bools.py ADDED
@@ -0,0 +1,15 @@
1
+ from transit.transit_types import true, false
2
+
3
+
4
+ if true:
5
+ print("ok")
6
+ if not true:
7
+ print("not ok")
8
+ if false:
9
+ print("not ok")
10
+ if not false:
11
+ print("ok")
12
+ if true and false:
13
+ print("not ok")
14
+ if true or false:
15
+ print("ok")
scratch/dt.py ADDED
@@ -0,0 +1,7 @@
1
+ from transit.writer import Writer
2
+ from StringIO import StringIO
3
+ import datetime as dt
4
+
5
+ io = StringIO()
6
+ writer = Writer(io, "json")
7
+ writer.write({"date": dt.datetime.utcnow()})
scratch/emptyset.py ADDED
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+ from transit.writer import Writer
3
+ from transit.reader import Reader
4
+ from transit.transit_types import URI
5
+ from StringIO import StringIO
6
+ import sys
7
+
8
+ io = StringIO()
9
+
10
+ x = set()
11
+ print(x)
12
+
13
+ writer = Writer(io, protocol="json")
14
+ writer.write(x)
15
+ reader = Reader(protocol="json")
16
+ print io.getvalue()
17
+ io.seek(0)
18
+ outcome = reader.read(io)
19
+ print(outcome)
scratch/msgpack_issue.py CHANGED
@@ -2,11 +2,18 @@ from transit.reader import Reader
2
2
  from transit.writer import Writer
3
3
  from StringIO import StringIO
4
4
 
5
- mpcode = "94a37e6360a37e637ea37e635ea37e6323".decode("hex")
5
+ #json = "{\"~#set\":[{\"~#set\":[1,3,2]},{\"~#set\":[null,0,2.0,\"~~eight\",1,true,\"five\",false,\"~$seven\",\"~:six\"]}]}\n"
6
+ #mpcode = "94a37e6360a37e637ea37e635ea37e6323".decode("hex")
6
7
 
8
+ json = "{\"~#set\":[1,true]}"
7
9
  io = StringIO()
8
- io.write(mpcode)
10
+ io.write(json)
9
11
  io.seek(0)
10
- r = Reader(protocol="msgpack")
11
- print(r.read(io))
12
+ r = Reader(protocol="json")
13
+ correct = r.read(io)
14
+ out = StringIO()
15
+ w = Writer(out, protocol="json")
16
+ w.write(correct)
17
+ print(json)
18
+ print(out.getvalue())
12
19
 
tests/exemplars_test.py CHANGED
@@ -17,7 +17,7 @@ import unittest
17
17
  # then import transit stuff
18
18
  from transit.reader import Reader, JsonUnmarshaler, MsgPackUnmarshaler
19
19
  from transit.writer import Writer
20
- from transit.transit_types import Keyword, Symbol, URI, frozendict, TaggedValue, Link
20
+ from transit.transit_types import Keyword, Symbol, URI, frozendict, TaggedValue, Link, true, false
21
21
  from StringIO import StringIO
22
22
  from transit.helpers import mapcat
23
23
  from helpers import ints_centered_on, hash_of_size, array_of_symbools
@@ -96,7 +96,7 @@ def exemplar(name, val):
96
96
  globals()["test_" + name + "_json"] = ExemplarTest
97
97
 
98
98
  ARRAY_SIMPLE = (1, 2, 3)
99
- ARRAY_MIXED = (0, 1, 2.0, True, False, 'five', Keyword("six"), Symbol("seven"), '~eight', None)
99
+ ARRAY_MIXED = (0, 1, 2.0, true, false, 'five', Keyword("six"), Symbol("seven"), '~eight', None)
100
100
  ARRAY_NESTED = (ARRAY_SIMPLE, ARRAY_MIXED)
101
101
  SMALL_STRINGS = ("", "a", "ab", "abc", "abcd", "abcde", "abcdef")
102
102
  POWERS_OF_TWO = tuple(map(lambda x: pow(2, x), range(66)))
@@ -131,14 +131,14 @@ MAP_SIMPLE = frozendict({Keyword("a"): 1,
131
131
 
132
132
  MAP_MIXED = frozendict({Keyword("a"): 1,
133
133
  Keyword("b"): u"a string",
134
- Keyword("c"): True})
134
+ Keyword("c"): true})
135
135
 
136
136
  MAP_NESTED = frozendict({Keyword("simple"): MAP_SIMPLE,
137
137
  Keyword("mixed"): MAP_MIXED})
138
138
 
139
139
  exemplar("nil", None)
140
- exemplar("true", True)
141
- exemplar("false", False)
140
+ exemplar("true", true)
141
+ exemplar("false", false)
142
142
  exemplar("zero", 0)
143
143
  exemplar("one", 1)
144
144
  exemplar("one_string", "hello")
tests/regression.py CHANGED
@@ -17,7 +17,7 @@ import unittest
17
17
 
18
18
  from transit.reader import Reader
19
19
  from transit.writer import Writer
20
- from transit.transit_types import Symbol, frozendict
20
+ from transit.transit_types import Symbol, frozendict, true, false
21
21
  from StringIO import StringIO
22
22
 
23
23
  class RegressionBaseTest(unittest.TestCase):
@@ -37,12 +37,44 @@ def regression(name, value):
37
37
 
38
38
  globals()["test_" + name + "_json"] = RegressionTest
39
39
 
40
- regression("cache_consistency", ({"Problem?":True},
40
+ regression("cache_consistency", ({"Problem?":true},
41
41
  Symbol("Here"),
42
42
  Symbol("Here")))
43
43
  regression("one_pair_frozendict", frozendict({"a":1}))
44
44
  regression("json_int_max", (2**53+100, 2**63+100))
45
45
  regression("newline_in_string", "a\nb")
46
46
 
47
+ class BooleanTest(unittest.TestCase):
48
+ """Even though we're roundtripping transit_types.true and
49
+ transit_types.false now, make sure we can still write Python bools.
50
+
51
+ Additionally, make sure we can still do basic logical evaluation on transit
52
+ Boolean values.
53
+ """
54
+ def test_write_bool(self):
55
+ for protocol in ("json", "json-verbose", "msgpack"):
56
+ io = StringIO()
57
+ w = Writer(io, protocol)
58
+ w.write((True, False))
59
+ r = Reader(protocol)
60
+ io.seek(0)
61
+ out_data = r.read(io)
62
+ assert out_data[0] == true
63
+ assert out_data[1] == false
64
+
65
+ def test_basic_eval(self):
66
+ assert true
67
+ assert not false
68
+
69
+ def test_or(self):
70
+ assert true or false
71
+ assert not (false or false)
72
+ assert true or true
73
+
74
+ def test_and(self):
75
+ assert not (true and false)
76
+ assert true and true
77
+ assert not (false and false)
78
+
47
79
  if __name__ == '__main__':
48
80
  unittest.main()
transit/decoder.py CHANGED
@@ -18,6 +18,7 @@ from collections import OrderedDict
18
18
  from helpers import pairs
19
19
  import read_handlers as rh
20
20
  from rolling_cache import RollingCache, is_cacheable, is_cache_key
21
+ from transit_types import true, false
21
22
 
22
23
  class Tag(object):
23
24
  def __init__(self, tag):
@@ -88,8 +89,9 @@ class Decoder(object):
88
89
  return self.decode_list(node, cache, as_map_key)
89
90
  elif tp is str:
90
91
  return self.decode_string(unicode(node, "utf-8"), cache, as_map_key)
91
- else:
92
- return node
92
+ elif tp is bool:
93
+ return true if node else false
94
+ return node
93
95
 
94
96
  def decode_list(self, node, cache, as_map_key):
95
97
  """Special case decodes map-as-array.
transit/read_handlers.py CHANGED
@@ -47,7 +47,7 @@ class SymbolHandler(object):
47
47
  class BooleanHandler(object):
48
48
  @staticmethod
49
49
  def from_rep(x):
50
- return x == "t"
50
+ return transit_types.true if x == "t" else transit_types.false
51
51
 
52
52
  class IntHandler(object):
53
53
  @staticmethod
transit/transit_types.py CHANGED
@@ -188,3 +188,29 @@ class Link(object):
188
188
  @property
189
189
  def as_array(self):
190
190
  return [self.href, self.rel, self.name, self.render, self.prompt]
191
+
192
+ class Boolean(object):
193
+ """To allow a separate t/f that won't hash as 1/0. Don't call directly,
194
+ instead use true and false as singleton objects. Can use with type check.
195
+
196
+ Note that the Booleans are for preserving hash/set bools that duplicate 1/0
197
+ and not designed for use in Python outside of logical evaluation (don't treat
198
+ as an int, they're not). You can get a Python bool using bool(x)
199
+ where x is a true or false Boolean.
200
+ """
201
+ def __init__(self, name):
202
+ self.v = True if name == "true" else False
203
+ self.name = name
204
+
205
+ def __nonzero__(self):
206
+ return self.v
207
+
208
+ def __repr__(self):
209
+ return self.name
210
+
211
+ def __str__(self):
212
+ return self.name
213
+
214
+ # lowercase rep matches java/clojure
215
+ false = Boolean("false")
216
+ true = Boolean("true")
transit/write_handlers.py CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  from constants import *
16
16
  from class_hash import ClassDict
17
- from transit_types import Keyword, Symbol, URI, frozendict, TaggedValue, Link
17
+ from transit_types import Keyword, Symbol, URI, frozendict, TaggedValue, Link, Boolean
18
18
  import uuid
19
19
  import datetime, time
20
20
  from dateutil import tz
@@ -103,7 +103,7 @@ class BooleanHandler(object):
103
103
  return '?'
104
104
  @staticmethod
105
105
  def rep(b):
106
- return b
106
+ return bool(b)
107
107
  @staticmethod
108
108
  def string_rep(b):
109
109
  return 't' if b else 'f'
@@ -258,6 +258,7 @@ class WriteHandler(ClassDict):
258
258
  super(WriteHandler, self).__init__()
259
259
  self[type(None)] = NoneHandler
260
260
  self[bool] = BooleanHandler
261
+ self[Boolean] = BooleanHandler
261
262
  self[str] = StringHandler
262
263
  self[unicode] = StringHandler
263
264
  self[list] = ArrayHandler
transit/writer.py CHANGED
@@ -101,7 +101,7 @@ class Marshaler(object):
101
101
  return self.emit_string(ESC, "_", None, True, cache) if as_map_key else self.emit_object(None)
102
102
 
103
103
  def emit_string(self, prefix, tag, string, as_map_key, cache):
104
- encoded = cache.encode(str(prefix)+tag+escape(string), as_map_key)
104
+ encoded = cache.encode(str(prefix)+tag+string, as_map_key)
105
105
  # TODO: Remove this optimization for the time being - it breaks the cache
106
106
  #if "cache_enabled" in self.opts and is_cacheable(encoded, as_map_key):
107
107
  # return self.emit_object(cache.value_to_key[encoded], as_map_key)
@@ -222,7 +222,7 @@ class Marshaler(object):
222
222
 
223
223
  marshal_dispatch = {"_": Marshaler.emit_nil,
224
224
  "?": Marshaler.emit_boolean,
225
- "s": lambda self, rep, as_map_key, cache: Marshaler.emit_string(self, "", "", rep, as_map_key, cache),
225
+ "s": lambda self, rep, as_map_key, cache: Marshaler.emit_string(self, "", "", escape(rep), as_map_key, cache),
226
226
  "i": lambda self, rep, as_map_key, cache: Marshaler.emit_int(self, "i", rep, as_map_key, cache),
227
227
  "n": lambda self, rep, as_map_key, cache: Marshaler.emit_int(self, "n", rep, as_map_key, cache),
228
228
  "d": Marshaler.emit_double,
@@ -383,7 +383,7 @@ class VerboseSettings(object):
383
383
  self.handlers = self._verbose_handlers(WriteHandler())
384
384
 
385
385
  def emit_string(self, prefix, tag, string, as_map_key, cache):
386
- return self.emit_object(unicode(prefix) + tag + escape(string), as_map_key)
386
+ return self.emit_object(unicode(prefix) + tag + string, as_map_key)
387
387
 
388
388
  def emit_map(self, m, _, cache):
389
389
  self.emit_map_start(len(m))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.0
2
2
  Name: transit-python
3
- Version: 0.8.228-
3
+ Version: 0.8.240-
4
4
  Summary: Transit marshalling for Python
5
5
  Home-page: https://github.com/cognitect/transit-python
6
6
  Author: Cognitect
@@ -1,34 +1,37 @@
1
1
  scratch/__init__.py,sha256=9_8wL9Scv8_Cs8HJyJHGvx1vwXErsuvlsAqNZLcJQR0,8
2
+ scratch/bools.py,sha256=kQqhGbxJCHha20nsrlqiApniIPEbP3kyQWzyzwJ4SLw,275
2
3
  scratch/cache-inconsistent.py,sha256=nEjlqWeI6c7qQF6NFTHH-0C4-4vXBWXadY8WLONVAYE,315
4
+ scratch/dt.py,sha256=egSEA-BgibuKvnUvM7MwCj7GD3Mny6ubbUusdA3ptHE,176
5
+ scratch/emptyset.py,sha256=g_A9qLLGYXBeufsSj0v7PsA7sS0KmP_lcICrV6furPo,367
3
6
  scratch/frozendict.py,sha256=uk9Jo3vIWnZidG_DfXheB1lSsDFTiLwDD7prQc4HvAc,282
4
7
  scratch/int_issue.py,sha256=B14VHNXbNZ5Jf9kdbXUUePQRLea5qiKlRPn5CIuJ0TY,174
5
8
  scratch/issue.py,sha256=gGC6SVp05uP6rWVPyc6UqbWI-t4cLfVoUU7k4YxyMdQ,984
6
9
  scratch/mp_test.py,sha256=RWB0hlyDcpGU5tdjA0EITYswdxY9w66h9qoBMzU4f2w,585
7
- scratch/msgpack_issue.py,sha256=xKd9eQcWCT5aYqaauE8Y1tz0LwwafOfLDzfLGOllxMk,254
10
+ scratch/msgpack_issue.py,sha256=z7OrqXZRb2xgpE9_OboTqx0oh_ohIYuM_B6JDoIcOD8,511
8
11
  scratch/newline.py,sha256=FtdK3IWjnlC034FflqSVY6JCY5Z_TS400zh8p_ikoKo,266
9
12
  scratch/streamit.py,sha256=rC8y3zt81aVuScV8a1e4nKEpX9kGGX6QEjvqQ5LiPy0,1531
10
13
  scratch/testmprt.py,sha256=xjTG1qvyzv2nQNF0zn-XzIvwOsr0wjCwM_LyRgGj6EE,299
11
14
  scratch/unicodeme.py,sha256=krZmAiiEjLuftIL-JPf0nUL6h0Xw1u9ofBpjWWaSOhw,413
12
15
  tests/__init__.py,sha256=y9R3nXPFDAi05mokKlugHqaUNAE0lx9-I4k1SDI87U4,609
13
- tests/exemplars_test.py,sha256=sy5LzbDlPjVBruTW4UVBq8JuueIRRGqPBiVygqTEJ3c,9725
16
+ tests/exemplars_test.py,sha256=AD8pL4Zw84pNj28o-AIStVRz-1Z5-FetKqWgYKq01YU,9738
14
17
  tests/helpers.py,sha256=9BuwIEAf31xAAk_OmL6w9B8wFmNle8RmkZB9Epmetws,1079
15
- tests/regression.py,sha256=Wq2in9PY2uICjymwFSmC55kAW3e0i4rD85vBix8N9lE,1671
18
+ tests/regression.py,sha256=fCDwirB79_E25q6G7bjyzgHmyr1fDmLCgktNrgBoJLM,2648
16
19
  tests/seattle_benchmark.py,sha256=PxWmRRjGFd0bVLdC42x6Rqc-G3KvBgK6RLBImWcmOiI,1573
17
20
  transit/__init__.py,sha256=y9R3nXPFDAi05mokKlugHqaUNAE0lx9-I4k1SDI87U4,609
18
21
  transit/class_hash.py,sha256=Ah-NK2m4B8ybczCbmeia_J22hEU7EyvFuIRdIV16b4U,1542
19
22
  transit/constants.py,sha256=ePRHd1AAkar1RpEWW1cVRZhjhc168tksSo8n7KEbHig,802
20
- transit/decoder.py,sha256=BI7g0E66jiOgzBy479LL1eC3pO36TLECJ4I9R-VJTWw,7547
23
+ transit/decoder.py,sha256=KXI3Lv0EV38_nnw1Wyynn3NdQ_lQPvDIV5-5ViIywPo,7635
21
24
  transit/helpers.py,sha256=O4xJKHixO3SHm7JsyeN8rKkUKn60qdCvWS7DtGrAqAo,893
22
- transit/read_handlers.py,sha256=oSoQR7BX6S9WWBRevOjlK6yQGGFMmBm5aEwY0ce0bj0,3432
25
+ transit/read_handlers.py,sha256=-HbZzU1ToIKbqOFbyXUd_8J0W7oSA7odPbrMv_CtheA,3479
23
26
  transit/reader.py,sha256=FVwldxgHfiQpdJ4k2bOZI5NMukzT4A0LUFfHTsDNkMM,3150
24
27
  transit/rolling_cache.py,sha256=_Ea4fAVtWJzY0Vbmd17nGYvAnvmoo7img6DdSRZLlFg,2967
25
28
  transit/sosjson.py,sha256=OcMwIckMFpIFThc6YsTKwSoNsLdFXupC7oul9h6H2kg,2407
26
- transit/transit_types.py,sha256=_MxonyebyZT-6c2KgG5_TWvOWCyxWpTYFeJSjJzEp8k,5131
27
- transit/write_handlers.py,sha256=B32DIYf2B2imE-eXYG_YN2wqqz6Dn_UQ6txmdFbSS1c,6627
28
- transit/writer.py,sha256=5syISzlcG5NahSH3dtzs-NkAsuYcJJ1E7KhUD09b9J4,14840
29
- transit_python-0.8.228_.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10
30
- transit_python-0.8.228_.dist-info/METADATA,sha256=sfkOBkvbYSa9HF5JmtpRmKV7XMJHaUDnQNnGvqhVcOA,303
31
- transit_python-0.8.228_.dist-info/metadata.json,sha256=wW8OvVQuYlcBXX72Gi7NTFFdJ-bzZSB7TZ4O5H8zwT8,461
32
- transit_python-0.8.228_.dist-info/RECORD,,
33
- transit_python-0.8.228_.dist-info/top_level.txt,sha256=MPPjLxlgwZmph_D-Ql5euqlFA-UzT5Ea0h1sQkt56d0,22
34
- transit_python-0.8.228_.dist-info/WHEEL,sha256=54bVun1KfEBTJ68SHUmbxNPj80VxlQ0sHi4gZdGZXEY,92
29
+ transit/transit_types.py,sha256=yb2pfI2L9SipINIzz35IdLXuUSFTwa1j3xdGD5To_b8,5930
30
+ transit/write_handlers.py,sha256=49x1jS2r27-Z3gG7xvdr8gpXjyhlbX7jIEx538KmJAo,6681
31
+ transit/writer.py,sha256=hN81k2iW8S6Jl4fIOI3ABbnbf1n_OjINR4Fccc0yQ7c,14832
32
+ transit_python-0.8.240_.dist-info/DESCRIPTION.rst,sha256=OCTuuN6LcWulhHS3d5rfjdsQtW22n7HENFRh6jC6ego,10
33
+ transit_python-0.8.240_.dist-info/METADATA,sha256=rrJJSZnuLSV6LM988SnSHx1nnbCZsA5Z6FSYruthJOY,303
34
+ transit_python-0.8.240_.dist-info/metadata.json,sha256=4J5Nfr9vu4_lhcK1jDUkABiPvljg9qmHhVycEXDMgJI,461
35
+ transit_python-0.8.240_.dist-info/RECORD,,
36
+ transit_python-0.8.240_.dist-info/top_level.txt,sha256=MPPjLxlgwZmph_D-Ql5euqlFA-UzT5Ea0h1sQkt56d0,22
37
+ transit_python-0.8.240_.dist-info/WHEEL,sha256=54bVun1KfEBTJ68SHUmbxNPj80VxlQ0sHi4gZdGZXEY,92
@@ -1 +1 @@
1
- {"name": "transit-python", "metadata_version": "2.0", "generator": "bdist_wheel (0.24.0)", "summary": "Transit marshalling for Python", "run_requires": [{"requires": ["python-dateutil", "msgpack-python"]}], "version": "0.8.228-", "extensions": {"python.details": {"project_urls": {"Home": "https://github.com/cognitect/transit-python"}, "document_names": {"description": "DESCRIPTION.rst"}, "contacts": [{"role": "author", "name": "Cognitect"}]}}, "extras": []}
1
+ {"name": "transit-python", "metadata_version": "2.0", "generator": "bdist_wheel (0.24.0)", "summary": "Transit marshalling for Python", "run_requires": [{"requires": ["python-dateutil", "msgpack-python"]}], "version": "0.8.240-", "extensions": {"python.details": {"project_urls": {"Home": "https://github.com/cognitect/transit-python"}, "document_names": {"description": "DESCRIPTION.rst"}, "contacts": [{"role": "author", "name": "Cognitect"}]}}, "extras": []}