iota/codecs.py
def encode(self, input, errors='strict'):
        """
        Encodes a byte string into trytes.
        """
        if isinstance(input, memoryview):
            input = input.tobytes()

        if not isinstance(input, (binary_type, bytearray)):
            raise with_context(
                exc=TypeError(
                    "Can't encode {type}; byte string expected.".format(
                        type=type(input).__name__,
                    )),

                context={
                    'input': input,
                },
            )

        # :bc: In Python 2, iterating over a byte string yields
        # characters instead of integers.
        if not isinstance(input, bytearray):
            input = bytearray(input)

        trytes = bytearray()

        for c in input:
            second, first = divmod(c, len(self.alphabet))

            trytes.append(self.alphabet[first])
            trytes.append(self.alphabet[second])

        return binary_type(trytes), len(input)
def encode(self, input, errors='strict'):
        """
        Encodes a byte string into trytes.
        """
        if isinstance(input, memoryview):
            input = input.tobytes()

        if not isinstance(input, (binary_type, bytearray)):
            raise with_context(
                exc=TypeError(
                    "Can't encode {type}; byte string expected.".format(
                        type=type(input).__name__,
                    )),

                context={
                    'input': input,
                },
            )

        # :bc: In Python 2, iterating over a byte string yields
        # characters instead of integers.
        if not isinstance(input, bytearray):
            input = bytearray(input)

        trytes = bytearray()

        for c in input:
            second, first = divmod(c, len(self.alphabet))

            trytes.append(self.alphabet[first])
            trytes.append(self.alphabet[second])

        return binary_type(trytes), len(input)
def encode ( self , input , errors = 'strict' ) : if isinstance ( input , memoryview ) : input = input . tobytes ( ) if not isinstance ( input , ( binary_type , bytearray ) ) : raise with_context ( exc = TypeError ( "Can't encode {type}; byte string expected." . format ( type = type ( input ) . __name__ , ) ) , context = { 'input' : input , } , ) # :bc: In Python 2, iterating over a byte string yields # characters instead of integers. if not isinstance ( input , bytearray ) : input = bytearray ( input ) trytes = bytearray ( ) for c in input : second , first = divmod ( c , len ( self . alphabet ) ) trytes . append ( self . alphabet [ first ] ) trytes . append ( self . alphabet [ second ] ) return binary_type ( trytes ) , len ( input )
Encodes a byte string into trytes.
Encodes a byte string into trytes .