本文整理汇总了Python中twext.web2.dav.util.davXMLFromStream函数的典型用法代码示例。如果您正苦于以下问题:Python davXMLFromStream函数的具体用法?Python davXMLFromStream怎么用?Python davXMLFromStream使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了davXMLFromStream函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: calendar_query
def calendar_query(self, calendar_uri, query, got_xml, data, no_init):
if not no_init:
response = yield self.send(SimpleStoreRequest(self, "MKCALENDAR", calendar_uri, authid="wsanchez"))
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
if data:
for filename, icaldata in data.iteritems():
request = SimpleStoreRequest(self, "PUT", joinURL(calendar_uri, filename + ".ics"), authid="wsanchez")
request.stream = MemoryStream(icaldata)
yield self.send(request)
else:
# Add holiday events to calendar
for child in FilePath(self.holidays_dir).children():
if os.path.splitext(child.basename())[1] != ".ics":
continue
request = SimpleStoreRequest(self, "PUT", joinURL(calendar_uri, child.basename()), authid="wsanchez")
request.stream = MemoryStream(child.getContent())
yield self.send(request)
request = SimpleStoreRequest(self, "REPORT", calendar_uri, authid="wsanchez")
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
开发者ID:anemitz,项目名称:calendarserver,代码行数:34,代码来源:test_multiget.py
示例2: http_ACL
def http_ACL(self, request):
"""
Respond to a ACL request. (RFC 3744, section 8.1)
"""
if not self.fp.exists():
log.err("File not found: %s" % (self.fp.path,))
yield responsecode.NOT_FOUND
return
#
# Check authentication and access controls
#
x = waitForDeferred(self.authorize(request, (davxml.WriteACL(),)))
yield x
x.getResult()
#
# Read request body
#
doc = waitForDeferred(davXMLFromStream(request.stream))
yield doc
try:
doc = doc.getResult()
except ValueError, e:
log.err("Error while handling ACL body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:26,代码来源:acl.py
示例3: propfind_cb
def propfind_cb(response):
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("Incorrect response to PROPFIND: %s" % (response.code,))
def got_xml(doc):
if not isinstance(doc.root_element, davxml.MultiStatus):
self.fail("PROPFIND response XML root element is not multistatus: %r" % (doc.root_element,))
response = doc.root_element.childOfType(davxml.Response)
href = response.childOfType(davxml.HRef)
self.failUnless(str(href) == inbox_uri)
for propstat in response.childrenOfType(davxml.PropertyStatus):
status = propstat.childOfType(davxml.Status)
if status.code != responsecode.OK:
self.fail("Unable to read requested properties (%s): %r"
% (status, propstat.childOfType(davxml.PropertyContainer).toxml()))
container = propstat.childOfType(davxml.PropertyContainer)
#
# Check CalDAV:calendar-free-busy-set
#
free_busy_set = container.childOfType(caldavxml.CalendarFreeBusySet)
if not free_busy_set:
self.fail("Expected CalDAV:calendar-free-busy-set element; but got none.")
if not free_busy_set.children:
self.fail("Expected non-empty CalDAV:calendar-free-busy-set element.")
return davXMLFromStream(response.stream).addCallback(got_xml)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:34,代码来源:test_resource.py
示例4: http_PROPFIND
def http_PROPFIND(self, request):
"""
Respond to a PROPFIND request. (RFC 2518, section 8.1)
"""
if not self.exists():
log.err("File not found: %s" % (self,))
raise HTTPError(responsecode.NOT_FOUND)
#
# Check authentication and access controls
#
x = waitForDeferred(self.authorize(request, (davxml.Read(),)))
yield x
x.getResult()
#
# Read request body
#
try:
doc = waitForDeferred(davXMLFromStream(request.stream))
yield doc
doc = doc.getResult()
except ValueError, e:
log.err("Error while handling PROPFIND body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:25,代码来源:propfind.py
示例5: http_PROPFIND
def http_PROPFIND(self, request):
"""
Respond to a PROPFIND request. (RFC 2518, section 8.1)
"""
if not self.exists():
# Return 403 if parent does not allow Bind
parentURL = parentForURL(request.uri)
parent = (yield request.locateResource(parentURL))
yield parent.authorize(request, (davxml.Bind(),))
log.error("Resource not found: %s" % (self,))
raise HTTPError(responsecode.NOT_FOUND)
#
# Check authentication and access controls
#
yield self.authorize(request, (davxml.Read(),))
#
# Read request body
#
try:
doc = (yield davXMLFromStream(request.stream))
except ValueError, e:
log.error("Error while handling PROPFIND body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:26,代码来源:propfind.py
示例6: do_test
def do_test(response):
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
return davXMLFromStream(response.stream).addCallback(got_xml)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:7,代码来源:test_addressbookmultiget.py
示例7: check_result
def check_result(response):
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("Incorrect response code for PROPPATCH (%s != %s)"
% (response.code, responsecode.MULTI_STATUS))
return davXMLFromStream(response.stream).addCallback(check_xml)
开发者ID:jrossi,项目名称:twext,代码行数:8,代码来源:test_prop.py
示例8: calendar_query
def calendar_query(self, query, got_xml):
request = SimpleStoreRequest(self, "REPORT", "/calendars/users/wsanchez/calendar/", authid="wsanchez")
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:14,代码来源:test_calendarquery.py
示例9: http_REPORT
def http_REPORT(self, request):
"""
Respond to a REPORT request. (RFC 3253, section 3.6)
"""
if not self.exists():
log.err("Resource not found: %s" % (self,))
raise HTTPError(responsecode.NOT_FOUND)
#
# Read request body
#
try:
doc = (yield davXMLFromStream(request.stream))
except ValueError, e:
log.err("Error while handling REPORT body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:16,代码来源:report.py
示例10: addressbook_query
def addressbook_query(self, addressbook_uri, query, got_xml, data, no_init):
if not no_init:
''' FIXME: clear address book, possibly by removing
mkcol = """<?xml version="1.0" encoding="utf-8" ?>
<D:mkcol xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:carddav">
<D:set>
<D:prop>
<D:resourcetype><D:collection/><C:addressbook/></D:resourcetype>
</D:prop>
</D:set>
</D:mkcol>
"""
response = yield self.send(SimpleStoreRequest(self, "MKCOL", addressbook_uri, content=mkcol, authid="wsanchez"))
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCOL failed: %s" % (response.code,))
'''
if data:
for filename, icaldata in data.iteritems():
request = SimpleStoreRequest(self, "PUT", joinURL(addressbook_uri, filename + ".vcf"), authid="wsanchez")
request.stream = MemoryStream(icaldata)
yield self.send(request)
else:
# Add vcards to addressbook
for child in FilePath(self.vcards_dir).children():
if os.path.splitext(child.basename())[1] != ".vcf":
continue
request = SimpleStoreRequest(self, "PUT", joinURL(addressbook_uri, child.basename()), authid="wsanchez")
request.stream = MemoryStream(child.getContent())
yield self.send(request)
request = SimpleStoreRequest(self, "REPORT", addressbook_uri, authid="wsanchez")
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
开发者ID:anemitz,项目名称:calendarserver,代码行数:46,代码来源:test_addressbookmultiget.py
示例11: propfind_cb
def propfind_cb(response):
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("Incorrect response to PROPFIND: %s" % (response.code,))
def got_xml(doc):
if not isinstance(doc.root_element, davxml.MultiStatus):
self.fail("PROPFIND response XML root element is not multistatus: %r" % (doc.root_element,))
response = doc.root_element.childOfType(davxml.Response)
href = response.childOfType(davxml.HRef)
self.failUnless(str(href) == calendar_uri)
container = response.childOfType(davxml.PropertyStatus).childOfType(davxml.PropertyContainer)
#
# Check CalDAV:supported-calendar-component-set
#
supported_components = container.childOfType(caldavxml.SupportedCalendarComponentSet)
if supported_components:
self.fail("CalDAV:supported-calendar-component-set element was returned; but should be hidden.")
#
# Check CalDAV:supported-calendar-data
#
supported_calendar = container.childOfType(caldavxml.SupportedCalendarData)
if supported_calendar:
self.fail("CalDAV:supported-calendar-data elementwas returned; but should be hidden.")
#
# Check DAV:supported-report-set
#
supported_reports = container.childOfType(davxml.SupportedReportSet)
if supported_reports:
self.fail("DAV:supported-report-set element was returned; but should be hidden..")
return davXMLFromStream(response.stream).addCallback(got_xml)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:41,代码来源:test_props.py
示例12: http_PROPPATCH
def http_PROPPATCH(self, request):
"""
Respond to a PROPPATCH request. (RFC 2518, section 8.2)
"""
if not self.exists():
log.error("File not found: %s" % (self,))
raise HTTPError(responsecode.NOT_FOUND)
x = waitForDeferred(self.authorize(request, (davxml.WriteProperties(),)))
yield x
x.getResult()
#
# Read request body
#
try:
doc = waitForDeferred(davXMLFromStream(request.stream))
yield doc
doc = doc.getResult()
except ValueError, e:
log.error("Error while handling PROPPATCH body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:22,代码来源:proppatch.py
示例13: http_MKCALENDAR
def http_MKCALENDAR(self, request):
"""
Respond to a MKCALENDAR request.
(CalDAV-access-09, section 5.3.1)
"""
#
# Check authentication and access controls
#
parent = (yield request.locateResource(parentForURL(request.uri)))
yield parent.authorize(request, (davxml.Bind(),))
if self.exists():
log.error("Attempt to create collection where resource exists: %s" % (self,))
raise HTTPError(ErrorResponse(
responsecode.FORBIDDEN,
(davxml.dav_namespace, "resource-must-be-null"),
"Resource already exists",
))
if not parent.isCollection():
log.error("Attempt to create collection with non-collection parent: %s"
% (self,))
raise HTTPError(ErrorResponse(
responsecode.CONFLICT,
(caldavxml.caldav_namespace, "calendar-collection-location-ok"),
"Cannot create calendar inside another calendar",
))
#
# Read request body
#
try:
doc = (yield davXMLFromStream(request.stream))
yield self.createCalendar(request)
except ValueError, e:
log.error("Error while handling MKCALENDAR: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:38,代码来源:mkcalendar.py
示例14: calendar_query
def calendar_query(self, calendar_uri, query, got_xml):
response = yield self.send(SimpleRequest(self.site, "MKCALENDAR", calendar_uri))
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
# Add holiday events to calendar
yield addEventsDir(self, FilePath(self.holidays_dir), calendar_uri)
request = SimpleRequest(self.site, "REPORT", calendar_uri)
request.stream = MemoryStream(query.toxml())
response = yield self.send(request)
response = IResponse(response)
if response.code != responsecode.MULTI_STATUS:
self.fail("REPORT failed: %s" % (response.code,))
returnValue(
(yield davXMLFromStream(response.stream).addCallback(got_xml))
)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:23,代码来源:test_calendarquery.py
示例15: oops
def oops(self, request, response, code, method, name):
def gotResponseData(doc):
if doc is None:
doc_xml = None
else:
doc_xml = doc.toxml()
def fail(acl):
self.fail("Incorrect status code %s (!= %s) for %s of resource %s with %s ACL: %s\nACL: %s"
% (response.code, code, method, request.uri, name, doc_xml, acl.toxml()))
def getACL(resource):
return resource.accessControlList(request)
d = request.locateResource(request.uri)
d.addCallback(getACL)
d.addCallback(fail)
return d
d = davXMLFromStream(response.stream)
d.addCallback(gotResponseData)
return d
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:23,代码来源:test_acl.py
示例16: http_MKCOL
def http_MKCOL(self, request):
#
# Check authentication and access controls
#
parent = (yield request.locateResource(parentForURL(request.uri)))
yield parent.authorize(request, (davxml.Bind(),))
if self.exists():
log.err("Attempt to create collection where resource exists: %s"
% (self,))
raise HTTPError(ErrorResponse(
responsecode.FORBIDDEN,
(davxml.dav_namespace, "resource-must-be-null"))
)
if not parent.isCollection():
log.err("Attempt to create collection with non-collection parent: %s"
% (self,))
raise HTTPError(ErrorResponse(
responsecode.CONFLICT,
(davxml.dav_namespace, "collection-location-ok"))
)
#
# Don't allow DAV collections in a calendar or address book collection
#
if config.EnableCalDAV:
parent = (yield self._checkParents(request, isPseudoCalendarCollectionResource))
if parent is not None:
raise HTTPError(StatusResponse(
responsecode.FORBIDDEN,
"Cannot create collection within calendar collection %s" % (parent,)
))
if config.EnableCardDAV:
parent = (yield self._checkParents(request, isAddressBookCollectionResource))
if parent is not None:
raise HTTPError(StatusResponse(
responsecode.FORBIDDEN,
"Cannot create collection within address book collection %s" % (parent,)
))
#
# Read request body
#
try:
doc = (yield davXMLFromStream(request.stream))
except ValueError, e:
log.err("Error while handling MKCOL: %s" % (e,))
# TODO: twext.web2.dav 'MKCOL' tests demand this particular response
# code, but should we really be looking at the XML content or the
# content-type header? It seems to me like this ought to be considered
# a BAD_REQUEST if it claims to be XML but isn't, but an
# UNSUPPORTED_MEDIA_TYPE if it claims to be something else. -glyph
raise HTTPError(
StatusResponse(responsecode.UNSUPPORTED_MEDIA_TYPE, str(e))
)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:62,代码来源:mkcol.py
注:本文中的twext.web2.dav.util.davXMLFromStream函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论