transit-python 0.8.228-__py2.7.egg → 0.8.240__py2.7.egg

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.
EGG-INFO/PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.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
EGG-INFO/SOURCES.txt CHANGED
@@ -1,7 +1,10 @@
1
1
  setup.cfg
2
2
  setup.py
3
3
  scratch/__init__.py
4
+ scratch/bools.py
4
5
  scratch/cache-inconsistent.py
6
+ scratch/dt.py
7
+ scratch/emptyset.py
5
8
  scratch/frozendict.py
6
9
  scratch/int_issue.py
7
10
  scratch/issue.py
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/bools.pyc ADDED
Binary file
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/dt.pyc ADDED
Binary file
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/emptyset.pyc ADDED
Binary file
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
 
scratch/msgpack_issue.pyc CHANGED
Binary file
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/exemplars_test.pyc CHANGED
Binary file
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()
tests/regression.pyc CHANGED
Binary file
transit/class_hash.pyc CHANGED
Binary file
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/decoder.pyc CHANGED
Binary file
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/read_handlers.pyc CHANGED
Binary file
transit/reader.pyc CHANGED
Binary file
transit/rolling_cache.pyc CHANGED
Binary file
transit/sosjson.pyc CHANGED
Binary file
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/transit_types.pyc CHANGED
Binary file
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
Binary file
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))
transit/writer.pyc CHANGED
Binary file