Skip to content

Commit

Permalink
Encode None as atom none
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Vasiliev committed Feb 24, 2010
1 parent ff84be2 commit 53b46bf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Version 0.5 (XXXX-XX-XX)

- None ecnoded as atom none (Dmitry Vasiliev)

- Encode dict as a proplist (ordered by Python sort order, may be used as
orddict if keys are all the same type) (Bob Ippolito)

Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
- Add new datatypes (None, references?)
- Add new datatypes (references?)

- Add version keyword to encode() function
4 changes: 4 additions & 0 deletions src/erlport/erlterms.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def decode_term(string):
return True, tail
elif name == "false":
return False, tail
elif name == "none":
return None, tail
return Atom(name), tail
elif tag == 104 or tag == 105:
# SMALL_TUPLE_EXT, LARGE_TUPLE_EXT
Expand Down Expand Up @@ -336,5 +338,7 @@ def encode_term(term,
# encode dict as proplist, but will be orddict compatible if keys
# are all of the same type.
return encode_term(sorted(term.iteritems()))
elif term is None:
return pack(">BH", 100, 4) + "none"

raise ValueError("unsupported data type: %s" % type(term))
10 changes: 10 additions & 0 deletions src/erlport/tests/erlterms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ dict encoded as (Python) ordered proplists:
>>> encode(dict(a=1,b=2,c=3)) == encode([('a', 1), ('b', 2), ('c', 3)])
True

None encoded as atom none:

>>> encode(None) == encode(Atom('none'))
True


Decoding
--------
Expand Down Expand Up @@ -254,3 +259,8 @@ Atoms true and false decoded as True and False:
(True, '')
>>> decode('\x83d\x00\x05false')
(False, '')

Atom none decoded as None:

>>> decode('\x83d\x00\x04none')
(None, '')

0 comments on commit 53b46bf

Please sign in to comment.