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

Fix child.text==None #37

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion easywebdav/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.4"
18 changes: 13 additions & 5 deletions easywebdav/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import requests
from requests.adapters import HTTPAdapter
import platform
from numbers import Number
import xml.etree.cElementTree as xml
Expand Down Expand Up @@ -31,7 +32,11 @@ def codestr(code):

def prop(elem, name, default=None):
child = elem.find('.//{DAV:}' + name)
return default if child is None else child.text
if child is None:
return default
if child.text is None:
return default
return child.text


def elem2file(elem):
Expand All @@ -54,11 +59,12 @@ class OperationFailed(WebdavException):
PROPFIND = "list directory",
)

def __init__(self, method, path, expected_code, actual_code):
def __init__(self, method, path, expected_code, actual_code, history):
self.method = method
self.path = path
self.expected_code = expected_code
self.actual_code = actual_code
self.history = "->".join([str((r.status_code, r.url)) for r in history])
operation_name = self._OPERATIONS[method]
self.reason = 'Failed to {operation_name} "{path}"'.format(**locals())
expected_codes = (expected_code,) if isinstance(expected_code, Number) else expected_code
Expand All @@ -68,7 +74,8 @@ def __init__(self, method, path, expected_code, actual_code):
{self.reason}.
Operation : {method} {path}
Expected code : {expected_codes_str}
Actual code : {actual_code} {actual_code_str}'''.format(**locals())
Actual code : {actual_code} {actual_code_str}
History : {history}'''.format(**locals())
super(OperationFailed, self).__init__(msg)

class Client(object):
Expand All @@ -83,6 +90,7 @@ def __init__(self, host, port=0, auth=None, username=None, password=None,
self.session = requests.session()
self.session.verify = verify_ssl
self.session.stream = True
self.session.mount(host, HTTPAdapter(max_retries=5))

if cert:
self.session.cert = cert
Expand All @@ -94,10 +102,10 @@ def __init__(self, host, port=0, auth=None, username=None, password=None,

def _send(self, method, path, expected_code, **kwargs):
url = self._get_url(path)
response = self.session.request(method, url, allow_redirects=False, **kwargs)
response = self.session.request(method, url, allow_redirects=True, **kwargs)
if isinstance(expected_code, Number) and response.status_code != expected_code \
or not isinstance(expected_code, Number) and response.status_code not in expected_code:
raise OperationFailed(method, path, expected_code, response.status_code)
raise OperationFailed(method, path, expected_code, response.status_code, response.history)
return response

def _get_url(self, path):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
exec(version_file.read())

properties = dict(
name="easywebdav",
name="easywebdav-dcache",
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand Down Expand Up @@ -38,4 +38,4 @@
"PyWebDAV",
))

setup(**properties)
setup(**properties)