Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the open function in parse_files should include encoding type #23

Closed
CoderHuo opened this issue May 11, 2018 · 2 comments
Closed

the open function in parse_files should include encoding type #23

CoderHuo opened this issue May 11, 2018 · 2 comments

Comments

@CoderHuo
Copy link
Contributor

CoderHuo commented May 11, 2018

eg:

def parse_files(filenames,encoding=None):
    """Parse given ASN.1 specification file(s) and return a dictionary of
    its/their contents.

    >>> foo = asn1tools.parse_files('foo.asn')

    """

    if isinstance(filenames, str):
        filenames = [filenames]

    string = ''

    for filename in filenames:
        with open(filename, 'r',encoding=encoding) as fin:
            string += fin.read()
            string += '\n'

    return parse_string(string)
@eerimoq
Copy link
Owner

eerimoq commented May 11, 2018

You should create a pull request, tested with both Python 2 and 3.

open() in Python 2 does not take the encoding argument. open() in the io-module takes the extra argument, but it reads unicode instead of str, which may be what we want, but in the cantools package I ended up opening the file differently in Python 2 and 3. See: https://github.com/eerimoq/cantools/blob/master/cantools/db/__init__.py#L65-L70

@CoderHuo
Copy link
Contributor Author

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants