Imgur / imgurpython

Official Imgur python client library (deprecated)
MIT License
546 stars 116 forks source link

add python2 support #5

Closed chid closed 10 years ago

jacobgreenleaf commented 10 years ago

I am merging the album command. Thanks for splitting into atomic commits.

On Python 2.x support, do you think it would be better to refactor the places where it uses urlencode and HTTPError and so on to use generic functions, and polymorphically bind those to python 2.x bindings in python 2.x, and so on?

chid commented 10 years ago

Sorry I'm not sure I understand, could you please provide a code sample?

How about like,

try:
    from urllib.request import urlopen, build_opener, Request
    from urllib.parse import urlparse, urlencode
    from urllib.error import HTTPError
except ImportError:
    from urlparse import urlparse
    from urllib import urlopen, urlencode
    from urllib2 import HTTPError, build_opener, Request

which is what I used in https://github.com/chid/push.co/blob/master/push.py

jacobgreenleaf commented 10 years ago

Edit: I misread your code, looks good, will merge.

chid commented 10 years ago

I must say, I found that function name UrlLibOpen odd to read