Git Product home page Git Product logo

Comments (2)

hdima avatar hdima commented on August 21, 2024

Unfortunately there's no reliable way to distinguish a list from a "string" in Erlang. So Erlang lists mapped to List class in ErlPort which is a subclass of list but also can be converted to Unicode string with to_string() method.

I think there are at least two ways to pass str to Python 3 (both of them require some Python code unfortunately):

  • A wrapper for a function can be created in Python which always convert string arguments to str. Something like the following code (not tested):

    def get_bucket(connection, bucket_name):
        return connection.get_bucket(bucket_name.to_string())
  • Custom data type decoder can be used to for example convert {string, String} Erlang tuple to str in Python. The code can look like this (not tested):

    def str_decoder(value):
        if isinstance(value, tuple) and len(value) == 2 and value[0] == "string":
            value = value[1].to_string()
        return value

from erlport.

jdoig avatar jdoig commented on August 21, 2024

I've managed to fix this for my uses (that is fire and forget calls from Elixir to Python) with the following:
in: decode

    elif tag == 109:
        # BINARY_EXT ... In Elixir this is a BitString
        ln = len(string)
        if ln < 5:
            raise IncompleteData(string)
        length = int4_unpack(string[1:5])[0] + 5
        if ln < length:
            raise IncompleteData(string)
        stringy = string[5:length]
        return stringy.decode(), string[length:]

and in OpaqueObject:

    @classmethod
    def decode(cls, data, language):
        if isinstance(data, str):
            data = data.encode()
        if language == b"python":
            return loads(data)
        return cls(data, language)

here: https://github.com/jdoig/erlport

My requirements are very simple so I've no idea the overall impact of doing this or how this would work with erlang. Just leaving this here in case any one arrives via a search.

from erlport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.