iota.py icon indicating copy to clipboard operation
iota.py copied to clipboard

`TypeError` when calling codecs.open with `trytes_ascii` codec

Open todofixthis opened this issue 7 years ago • 1 comments

Calling codecs.open with the trytes_ascii codec yields a TypeError:

In [1]: import iota
In [2]: import codecs

In [3]: with codecs.open('hello.txt', 'r', 'trytes_ascii') as r:
   ...:    print(r.read())

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-aed860f82ea7> in <module>()
----> 1 with codecs.open('setup.cfg', 'r', 'trytes_ascii') as r:
      2     print(r.read())
      3

~/.virtualenvwrapper/pyota-py3/bin/../lib/python3.6/codecs.py in open(filename, mode, encoding, errors, buffering)
    897         return file
    898     info = lookup(encoding)
--> 899     srw = StreamReaderWriter(file, info.streamreader, info.streamwriter, errors)
    900     # Add attributes to simplify introspection
    901     srw.encoding = encoding

~/.virtualenvwrapper/pyota-py3/bin/../lib/python3.6/codecs.py in __init__(self, stream, Reader, Writer, errors)
    690         """
    691         self.stream = stream
--> 692         self.reader = Reader(stream, errors)
    693         self.writer = Writer(stream, errors)
    694         self.errors = errors

TypeError: 'NoneType' object is not callable

todofixthis avatar Nov 02 '17 04:11 todofixthis

Looks like AsciiTrytesCodec.get_codec_info is missing some items in its return value:

https://docs.python.org/3/library/codecs.html#codecs.CodecInfo

incrementalencoder
incrementaldecoder

Incremental encoder and decoder classes or factory functions. These have to provide the interface defined by the base classes IncrementalEncoder and IncrementalDecoder, respectively. Incremental codecs can maintain state.

streamwriter
streamreader

Stream writer and reader classes or factory functions. These have to provide the interface defined by the base classes StreamWriter and StreamReader, respectively. Stream codecs can maintain state.

todofixthis avatar Nov 02 '17 04:11 todofixthis