@@ -60,8 +60,7 @@ def b_ord(character):
6060 """
6161 return ord (character )
6262
63- __all__ = ['UNDEFINED' ,
64- 'OtpErlangAtom' ,
63+ __all__ = ['OtpErlangAtom' ,
6564 'OtpErlangBinary' ,
6665 'OtpErlangFunction' ,
6766 'OtpErlangList' ,
@@ -70,11 +69,12 @@ def b_ord(character):
7069 'OtpErlangReference' ,
7170 'binary_to_term' ,
7271 'term_to_binary' ,
72+ 'set_undefined' ,
7373 'InputException' ,
7474 'OutputException' ,
7575 'ParseException' ]
7676
77- UNDEFINED = b'undefined' # Elixir use can set to b'nil'
77+ _UNDEFINED = b'undefined' # Change with set_undefined
7878
7979# tag values here http://www.erlang.org/doc/apps/erts/erl_ext_dist.html
8080_TAG_VERSION = 131
@@ -633,7 +633,7 @@ def _binary_to_term(i, data):
633633 return (i , True )
634634 if atom_name == b'false' :
635635 return (i , False )
636- if atom_name == UNDEFINED :
636+ if atom_name == _UNDEFINED :
637637 return (i , None )
638638 if tag == _TAG_ATOM_UTF8_EXT :
639639 atom_name = TypeUnicode (
@@ -649,7 +649,7 @@ def _binary_to_term(i, data):
649649 return (i , True )
650650 if atom_name == b'false' :
651651 return (i , False )
652- if atom_name == UNDEFINED :
652+ if atom_name == _UNDEFINED :
653653 return (i , None )
654654 if tag == _TAG_SMALL_ATOM_UTF8_EXT :
655655 atom_name = TypeUnicode (
@@ -770,7 +770,7 @@ def _term_to_binary(term):
770770 if isinstance (term , dict ):
771771 return _dict_to_binary (term )
772772 if term is None :
773- return OtpErlangAtom (TypeUnicode (UNDEFINED , encoding = 'utf-8' )).binary ()
773+ return OtpErlangAtom (TypeUnicode (_UNDEFINED , encoding = 'utf-8' )).binary ()
774774 if isinstance (term , OtpErlangAtom ):
775775 return term .binary ()
776776 if isinstance (term , OtpErlangList ):
@@ -866,6 +866,12 @@ def _bignum_to_binary(term):
866866def _float_to_binary (term ):
867867 return b_chr (_TAG_NEW_FLOAT_EXT ) + struct .pack (b'>d' , term )
868868
869+ # Elixir use can set to b'nil'
870+ def set_undefined (value ):
871+ assert isinstance (value , bytes )
872+ global _UNDEFINED
873+ _UNDEFINED = value
874+
869875# Exception classes listed alphabetically
870876
871877class InputException (ValueError ):
0 commit comments