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

Python 3 support #54

Merged
merged 8 commits into from Apr 2, 2013

Conversation

Projects
None yet
1 participant
@JonnyJD
Owner

JonnyJD commented Mar 30, 2013

This would especially be great because we don't have to care about python vs python2 anymore. On distributions where python = Python 3 we would use that and on other systems we just use Python 2.

First problem encountered:

This Disc ID is ambiguous:
Traceback (most recent call last):
  File "./isrcsubmit.py", line 805, in <module>
    release_id = disc.release["id"]         # implicitly fetches release
  File "./isrcsubmit.py", line 433, in release
    self._release = self.getRelease(self._verified)
  File "./isrcsubmit.py", line 459, in getRelease
    release["title"]))
  File "./isrcsubmit.py", line 304, in print_encoded
    if isinstance(arg, unicode):
NameError: global name 'unicode' is not defined
@JonnyJD

This comment has been minimized.

Owner

JonnyJD commented Mar 29, 2013

Just renaming the types is not enough. There is this problem afterwards:

  File "./isrcsubmit.py", line 318, in print_encoded
    msg = " ".join(stringArgs)
TypeError: sequence item 0: expected str instance, bytes found

Basically because " " is a unicode string in Python 3, but we want it to be a byte string.
A typical Python2/3 problem.

@JonnyJD

This comment has been minimized.

Owner

JonnyJD commented Mar 29, 2013

The next problem (after fixing all string/byte literals) is then:

  File "./isrcsubmit.py", line 324, in print_encoded
    sys.stdout.write(msg)
TypeError: must be str, not bytes

Which can be fixed (in Python 3) with sys.stdout.buffer.write(msg).

It is possibly the best option to make 2 implementations for print_encoded.

The same problem with string literals also occurs directly in the backend code with

  File "./isrcsubmit.py", line 567, in gather_isrcs
    if line.startswith("Track") and len(line) > 12:
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

So we probably also need a function that can convert to bytes (without printing).

@JonnyJD

This comment has been minimized.

Owner

JonnyJD commented Mar 30, 2013

Starting with Python 2.6 byte literals like b"blub" work already. So we can use that directly. Python-discid has a requirement of Python >= 2.6 anyways.

@ghost ghost assigned JonnyJD Mar 30, 2013

@JonnyJD

This comment has been minimized.

Owner

JonnyJD commented Mar 30, 2013

We also have to decode everything we get from the backends (and possibly command line).
Otherwise we get this as output:

using b'cd-info 0.90'
...
found new ISRC for track 1: b'GBBBN7902002'

From musicbrainzngs we already get unicode strings.

JonnyJD added some commits Mar 30, 2013

JonnyJD added a commit that referenced this pull request Apr 2, 2013

Merge branch 'py3'
See pull request #54

@JonnyJD JonnyJD merged commit 8afa77c into master Apr 2, 2013

@JonnyJD JonnyJD deleted the py3 branch Apr 2, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment