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

A few improvements when integrating with DavMail #105

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions pycarddav/carddav.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PyCardDAV(object):
"""

def __init__(self, resource, debug='', user='', passwd='',
verify=True, write_support=False, auth='basic'):
verify=True, write_support=False, auth='basic', proxies=None):
#shutup urllib3
urllog = logging.getLogger('requests.packages.urllib3.connectionpool')
urllog.setLevel(logging.CRITICAL)
Expand All @@ -91,6 +91,8 @@ def __init__(self, resource, debug='', user='', passwd='',
if auth == 'digest':
from requests.auth import HTTPDigestAuth
self._settings['auth'] = HTTPDigestAuth(user, passwd)
if proxies:
self._settings['proxies'] = proxies
self._default_headers = {"User-Agent": "pyCardDAV"}

headers = self.headers
Expand Down Expand Up @@ -128,7 +130,7 @@ def get_abook(self):

:rtype: list of hrefs to vcards
"""
xml = self._get_xml_props()
xml = self._get_xml_props(['getcontenttype', 'getetag', 'resourcetype'])
abook = self._process_xml_props(xml)
return abook

Expand Down Expand Up @@ -215,7 +217,7 @@ def upload_new_card(self, card):
return (parsed_url.path, etag)
response.raise_for_status()

def _get_xml_props(self):
def _get_xml_props(self, props=[]):
"""PROPFIND method

gets the xml file with all vcard hrefs
Expand All @@ -224,9 +226,19 @@ def _get_xml_props(self):
"""
headers = self.headers
headers['Depth'] = '1'

root = ET.Element('{DAV:}propfind')
proplist = ET.SubElement(root, 'prop')

for prop in props:
ET.SubElement(proplist, prop)

data = ET.tostring(root, encoding="utf-8", xml_declaration=True, pretty_print=True)

response = self.session.request('PROPFIND',
self.url.resource,
headers=headers,
data=data,
**self._settings)
response.raise_for_status()

Expand Down