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

diff_match_patch.py references old urllib.parse, breaking in ST3 build 3126 #241

Open
armahillo opened this issue Jun 10, 2017 · 3 comments

Comments

@armahillo
Copy link

Spent the last hour poking around about this. I saw a few issues in this repo discussed by @wbond and some others, and while it appears that this was working with ST3 build 3120, the current stable build (3126) is not working again, and I cannot install Floobits either via package installer or manually via git.

It seems that the issue is the splitting of the urllib module, discussed on this SO post: https://stackoverflow.com/a/29358613

urllib was split into urllib.parse, urllib.request, and urllib.error in Python 3.

(Relevant PY3 docs: https://docs.python.org/3.3/library/urllib.parse.html#module-urllib.parse )

My instance of ST3 is indeed using PY3 v3.3.6

>>> import sys
>>> print(sys.version)
3.3.6 (default, Sep 22 2016, 23:41:32)

and urllib is sourcing from there as well:

>>> urllib.__file__
'/opt/sublime_text/python3.3.zip/urllib/__init__.pyo'
>>> urllib.__loader__
<zipimporter object "/opt/sublime_text/python3.3.zip">

In file .../Floobits/floo/common/lib/diff_match_patch.py, line 32, it has this:

try:
    from urllib import parse
    assert parse

    def unquote_py3(x):
        return parse.unquote(x)
    unquote = unquote_py3
    str_instances = str
    unichr = chr
except ImportError:
    import urllib as parse

The from urllib import parse seems to be the offending line; and it looks like the script is trying to gracefully accommodate that in the exception block import urllib as parse.

Attempting these in the ST3 terminal, I get:

>>> from urllib import parse
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name parse
>>> import urllib as parse
>>> parse.unquote
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: 'module' object has no attribute 'unquote'

However, in 3.3, these methods are found in the urllib.parse module, and I was able to get a confirmation of loading for parse.unquote by doing this:

>>> from urllib.parse import quote
>>> quote
<function quote at 0x7f1a41b82290>
>>> from urllib.parse import unquote
>>> unquote
<function unquote at 0x7f1a41b82050>

So it appears that these methods are available, but the existing code in that file (.../diff_match_patch.py) is not importing them correctly.

Just on a lark, I tried changing that opening block to:

try:
#    from urllib import parse    # omitted this
#    assert parse                     # omitted this
    from urllib.parse import quote   # added this
    from urllib.parse import unquote  # added this

#    def unquote_py3(x):  # omitted this
#        return parse.unquote(x) # omitted this
#    unquote = unquote_py3 # omitted this
    str_instances = str
    unichr = chr
except ImportError:
    import urllib as parse

    def unquote_py2(x):
        return parse.unquote(x.encode('utf-8')).decode('utf-8')
    unquote = unquote_py2
    import __builtin__
    str_instances = (str, __builtin__.basestring)

And then did a find/replace (s/parse.quote/quote/).

When I closed and reopened ST3, the errors about urllib.parse were no longer showing, however I did see a couple other errors related to urllib, including:

HTTPError = urllib.error.HTTPError
AttributeError: 'module' object has no attribute 'error'

and

Traceback (most recent call last):
  File "/home/aaron/.config/sublime-text-3/Packages/Floobits/floo/common/reactor.py", line 11, in <module>
    from . import api, msg
  File "/home/aaron/.config/sublime-text-3/Packages/Floobits/floo/common/api.py", line 28, in <module>
    import urllib2
ImportError: No module named 'urllib2'

So I suspect that the module refactoring they did in this version has had some effects in other places as well.

I'm super rusty in python (and am looking through this repo for the first time ever tonight) and while I'd be happy to submit a PR for these superficial changes, someone more experienced should really audit this as well.

Happy to answer any followup questions about this issue or provide additional information, if that's needed. (I'm on Ubuntu 17.04)

@ggreer
Copy link
Member

ggreer commented Jun 15, 2017

I'm very confused by this. I'm using the same platform (Ubuntu 17.04) & build of Sublime (3126) and I can collaborate just fine.

Maybe another plugin is monkey patching urllib?

@CromFr
Copy link

CromFr commented Oct 17, 2017

Same issue for me (ArchLinux, sublime 3143)
Full error log: errors.txt

@Naurand
Copy link

Naurand commented Oct 18, 2017

Same probleme here, (Ubuntu 14.04.5 LTS)
(sublime 3126)
Exact same error log.
Edit: Ok just worked with new version 3143

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

4 participants