amnong / easywebdav

A WebDAV Client in Python
http://pypi.python.org/pypi/easywebdav/
ISC License
207 stars 113 forks source link

Running upload() on python 3 fails #53

Open andybelov opened 7 years ago

andybelov commented 7 years ago

Running upload() on python 3 leads to the error because basestring is no longer available in Python 3.

Stack trace:

def upload(self, local_path_or_fileobj, remote_path):
--> 153         if isinstance(local_path_or_fileobj, basestring):
    154             with open(local_path_or_fileobj, 'rb') as f:
    155                 self._upload(f, remote_path)

NameError: name 'basestring' is not defined
afsneto commented 6 years ago

Just insert at the beginning of the code (after import statements):

try:
    unicode = unicode
except NameError:
    # 'unicode' is undefined, must be Python 3
    str = str
    unicode = str
    bytes = bytes
    basestring = (str,bytes)
else:
    # 'unicode' exists, must be Python 2
    str = str
    unicode = unicode
    bytes = str
    basestring = basestring
Duaard commented 6 years ago

Inserting the code snippet after import statements did not work for me, as it only changes the basestring value for the class it is being imported to, where it should be changed inside the easywebdav.py

As a work around I just cloned easywebdav.py and inserted the code snippet after the checking of py_majversion.

Duaard commented 6 years ago

My bad, I misunderstood the instruction. It was supposed to be inserted after the import statements IN THE ORIGINAL SCRIPT :smiley: