本文整理汇总了Python中txweb2.http_headers.MimeType类的典型用法代码示例。如果您正苦于以下问题:Python MimeType类的具体用法?Python MimeType怎么用?Python MimeType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MimeType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_update_attachment
def test_update_attachment(self):
"""
Test that action=update-attachment works.
"""
yield self.createShare("user01", "puser01")
calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
yield calendar1.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
yield self.commitTransaction(0)
object1 = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home="user01", calendar_name="calendar", name="1.ics")
resourceID = object1.id()
attachment, _ignore_location = yield object1.addAttachment(None, MimeType.fromString("text/plain"), "test.txt", MemoryStream("Here is some text."))
managedID = attachment.managedID()
yield self.commitTransaction(0)
shared_object = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", calendar_name="shared-calendar", name="1.ics")
data = "Here is some more text."
attachment, location = yield shared_object.updateAttachment(managedID, MimeType.fromString("text/plain"), "test.txt", MemoryStream(data))
managedID = attachment.managedID()
from txdav.caldav.datastore.sql_external import ManagedAttachmentExternal
self.assertTrue(isinstance(attachment, ManagedAttachmentExternal))
self.assertEqual(attachment.size(), len(data))
self.assertTrue("user01/dropbox/" in location)
yield self.commitTransaction(1)
cobjs = yield ManagedAttachment.referencesTo(self.theTransactionUnderTest(0), managedID)
self.assertEqual(cobjs, set((resourceID,)))
attachment = yield ManagedAttachment.load(self.transactionUnderTest(), resourceID, managedID)
self.assertEqual(attachment.name(), "test.txt")
data = yield self.attachmentToString(attachment)
self.assertEqual(data, "Here is some more text.")
yield self.commitTransaction(0)
开发者ID:eventable,项目名称:CalendarServer,代码行数:34,代码来源:test_conduit.py
示例2: test_MissingContentType
def test_MissingContentType(self):
test_files = (
("plain.txt", MimeType.fromString("text/plain"),),
("word.doc", MimeType.fromString("application/msword"),),
("markup.html", MimeType.fromString("text/html"),),
("octet", MimeType.fromString("application/octet-stream"),),
("bogus.bog", MimeType.fromString("application/octet-stream"),),
)
class FakeAttachment(object):
def __init__(self, name):
self._name = name
def name(self):
return self._name
for filename, result in test_files:
item = StorageTransportBase(FakeAttachment(filename), None, None)
self.assertEquals(item._contentType, result)
self.assertEquals(item._dispositionName, None)
item = StorageTransportBase(FakeAttachment(filename), result, filename)
self.assertEquals(item._contentType, result)
self.assertEquals(item._dispositionName, filename)
开发者ID:nunb,项目名称:calendarserver,代码行数:25,代码来源:test_util.py
示例3: 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, authPrincipal=self.authPrincipal))
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"),
headers=Headers({"content-type": MimeType.fromString("text/vcard")}),
authPrincipal=self.authPrincipal
)
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()),
headers=Headers({"content-type": MimeType.fromString("text/vcard")}),
authPrincipal=self.authPrincipal
)
request.stream = MemoryStream(child.getContent())
yield self.send(request)
request = SimpleStoreRequest(self, "REPORT", addressbook_uri, authPrincipal=self.authPrincipal)
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:nunb,项目名称:calendarserver,代码行数:58,代码来源:test_addressbookmultiget.py
示例4: initFromStore
def initFromStore(self):
"""
Execute necessary SQL queries to retrieve attributes.
@return: C{True} if this attachment exists, C{False} otherwise.
"""
att = self._attachmentSchema
if self._dropboxID and self._dropboxID != ".":
where = (att.DROPBOX_ID == self._dropboxID).And(
att.PATH == self._name)
else:
where = (att.ATTACHMENT_ID == self._attachmentID)
rows = (yield Select(
self._allColumns(),
From=att,
Where=where
).on(self._txn))
if not rows:
returnValue(None)
for attr, value in zip(self._rowAttributes(), rows[0]):
setattr(self, attr, value)
self._created = parseSQLTimestamp(self._created)
self._modified = parseSQLTimestamp(self._modified)
self._contentType = MimeType.fromString(self._contentType)
returnValue(self)
开发者ID:red-hood,项目名称:calendarserver,代码行数:28,代码来源:sql_attachment.py
示例5: test_timeoutOnPUT
def test_timeoutOnPUT(self):
"""
PUT gets a 503 on a lock timeout.
"""
# Create a fake lock
txn = self.transactionUnderTest()
yield NamedLock.acquire(txn, "ImplicitUIDLock:%s" % (hashlib.md5("uid1").hexdigest(),))
# PUT fails
principal = yield self.actualRoot.findPrincipalForAuthID("wsanchez")
request = SimpleStoreRequest(
self,
"PUT",
"/calendars/users/wsanchez/calendar/1.ics",
headers=Headers({"content-type": MimeType.fromString("text/calendar")}),
authPrincipal=principal
)
request.stream = MemoryStream("""BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Apple Computer\, Inc//iCal 2.0//EN
VERSION:2.0
BEGIN:VEVENT
UID:uid1
DTSTART;VALUE=DATE:20020101
DTEND;VALUE=DATE:20020102
DTSTAMP:20020101T121212Z
SUMMARY:New Year's Day
END:VEVENT
END:VCALENDAR
""".replace("\n", "\r\n"))
response = yield self.send(request)
self.assertEqual(response.code, responsecode.SERVICE_UNAVAILABLE)
开发者ID:eventable,项目名称:CalendarServer,代码行数:33,代码来源:test_wrapping.py
示例6: test_get_attachment_links
def test_get_attachment_links(self):
"""
Test that action=get-attachment-links works.
"""
yield self.createShare("user01", "puser01")
calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
cobj1 = yield calendar1.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
calobjID = cobj1.id()
yield self.commitTransaction(0)
object1 = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home="user01", calendar_name="calendar", name="1.ics")
attachment, _ignore_location = yield object1.addAttachment(None, MimeType.fromString("text/plain"), "test.txt", MemoryStream("Here is some text."))
attID = attachment.id()
managedID = attachment.managedID()
yield self.commitTransaction(0)
shared_object = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", calendar_name="shared-calendar", name="1.ics")
links = yield shared_object.ownerHome().getAttachmentLinks()
self.assertEqual(len(links), 1)
self.assertTrue(isinstance(links[0], AttachmentLink))
self.assertEqual(links[0]._attachmentID, attID)
self.assertEqual(links[0]._managedID, managedID)
self.assertEqual(links[0]._calendarObjectID, calobjID)
yield self.commitTransaction(1)
开发者ID:eventable,项目名称:CalendarServer,代码行数:26,代码来源:test_conduit.py
示例7: test_remove_attachment
def test_remove_attachment(self):
"""
Test that action=remove-attachment works.
"""
yield self.createShare("user01", "puser01")
calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
yield calendar1.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
yield self.commitTransaction(0)
object1 = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home="user01", calendar_name="calendar", name="1.ics")
resourceID = object1.id()
attachment, _ignore_location = yield object1.addAttachment(None, MimeType.fromString("text/plain"), "test.txt", MemoryStream("Here is some text."))
managedID = attachment.managedID()
yield self.commitTransaction(0)
shared_object = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", calendar_name="shared-calendar", name="1.ics")
yield shared_object.removeAttachment(None, managedID)
yield self.commitTransaction(1)
cobjs = yield ManagedAttachment.referencesTo(self.theTransactionUnderTest(0), managedID)
self.assertEqual(cobjs, set())
attachment = yield ManagedAttachment.load(self.theTransactionUnderTest(0), resourceID, managedID)
self.assertTrue(attachment is None)
yield self.commitTransaction(0)
开发者ID:eventable,项目名称:CalendarServer,代码行数:26,代码来源:test_conduit.py
示例8: doPOSTGet
def doPOSTGet(self, request):
"""
Return the specified timezone data.
"""
tzid = request.args.get("tzid", ())
if len(tzid) != 1:
raise HTTPError(ErrorResponse(
responsecode.BAD_REQUEST,
(calendarserver_namespace, "valid-timezone"),
"Invalid tzid query parameter",
))
tzid = tzid[0]
try:
tzdata = readTZ(tzid)
except TimezoneException:
raise HTTPError(ErrorResponse(
responsecode.NOT_FOUND,
(calendarserver_namespace, "timezone-available"),
"Timezone not found",
))
response = Response()
response.stream = MemoryStream(tzdata)
response.headers.setHeader("content-type", MimeType.fromString("text/calendar; charset=utf-8"))
return response
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:27,代码来源:timezoneservice.py
示例9: makeClass
def makeClass(cls, txn, attachmentData):
"""
Given the various database rows, build the actual class.
@param attachmentData: the standard set of attachment columns
@type attachmentData: C{list}
@return: the constructed child class
@rtype: L{Attachment}
"""
att = cls._attachmentSchema
dropbox_id = attachmentData[cls._allColumns().index(att.DROPBOX_ID)]
c = ManagedAttachment if dropbox_id == "." else DropBoxAttachment
child = c(
txn,
attachmentData[cls._allColumns().index(att.ATTACHMENT_ID)],
attachmentData[cls._allColumns().index(att.DROPBOX_ID)],
attachmentData[cls._allColumns().index(att.PATH)],
)
for attr, value in zip(child._rowAttributes(), attachmentData):
setattr(child, attr, value)
child._created = parseSQLTimestamp(child._created)
child._modified = parseSQLTimestamp(child._modified)
child._contentType = MimeType.fromString(child._contentType)
return child
开发者ID:red-hood,项目名称:calendarserver,代码行数:28,代码来源:sql_attachment.py
示例10: 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"),
headers=Headers({"content-type": MimeType.fromString("text/calendar")}),
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()),
headers=Headers({"content-type": MimeType.fromString("text/calendar")}),
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:svn2github,项目名称:calendarserver-raw,代码行数:46,代码来源:test_multiget.py
示例11: _processRequest
def _processRequest(self):
"""
Process the request by sending it to the relevant server.
@return: the HTTP response.
@rtype: L{Response}
"""
store = self.storeMap[self.server.details()]
j = json.loads(self.data)
if self.stream is not None:
j["stream"] = self.stream
j["streamType"] = self.streamType
try:
if store.conduit.isStreamAction(j):
stream = ProducerStream()
class StreamProtocol(Protocol):
def connectionMade(self):
stream.registerProducer(self.transport, False)
def dataReceived(self, data):
stream.write(data)
def connectionLost(self, reason):
stream.finish()
result = yield store.conduit.processRequestStream(
j, StreamProtocol()
)
try:
ct, name = result
except ValueError:
code = responsecode.BAD_REQUEST
else:
headers = {"content-type": MimeType.fromString(ct)}
headers["content-disposition"] = MimeDisposition(
"attachment", params={"filename": name}
)
returnValue(Response(responsecode.OK, headers, stream))
else:
result = yield store.conduit.processRequest(j)
code = responsecode.OK
except Exception as e:
# Send the exception over to the other side
result = {
"result": "exception",
"class": ".".join((
e.__class__.__module__,
e.__class__.__name__,
)),
"details": str(e),
}
code = responsecode.BAD_REQUEST
response = JSONResponse(code, result)
returnValue(response)
开发者ID:red-hood,项目名称:calendarserver,代码行数:58,代码来源:util.py
示例12: render
def render(self, request):
response = Response()
response.stream = MemoryStream((yield self.iCalendarZipArchiveData()))
# FIXME: Use content-encoding instead?
response.headers.setHeader(
b"content-type",
MimeType.fromString(b"application/zip")
)
returnValue(response)
开发者ID:nunb,项目名称:calendarserver,代码行数:11,代码来源:principals.py
示例13: render
def render(self, request):
# yield self.handleQueryArguments(request)
htmlContent = yield flattenString(request, self.elementClass())
response = Response()
response.stream = MemoryStream(htmlContent)
response.headers.setHeader(
b"content-type", MimeType.fromString(b"text/html; charset=utf-8")
)
returnValue(response)
开发者ID:eventable,项目名称:CalendarServer,代码行数:12,代码来源:resource.py
示例14: test_get_all_attachments
def test_get_all_attachments(self):
"""
Test that action=get-all-attachments works.
"""
yield self.createShare("user01", "puser01")
calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
yield calendar1.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
yield self.commitTransaction(0)
object1 = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home="user01", calendar_name="calendar", name="1.ics")
yield object1.addAttachment(None, MimeType.fromString("text/plain"), "test.txt", MemoryStream("Here is some text."))
yield self.commitTransaction(0)
shared_object = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", calendar_name="shared-calendar", name="1.ics")
attachments = yield shared_object.ownerHome().getAllAttachments()
self.assertEqual(len(attachments), 1)
self.assertTrue(isinstance(attachments[0], ManagedAttachment))
self.assertEqual(attachments[0].contentType(), MimeType.fromString("text/plain"))
self.assertEqual(attachments[0].name(), "test.txt")
yield self.commitTransaction(1)
开发者ID:eventable,项目名称:CalendarServer,代码行数:22,代码来源:test_conduit.py
示例15: finalState
def finalState(self):
"""
Setup the server with data changes appearing before the final sync
"""
txn = self.theTransactionUnderTest(1)
obj = yield self.calendarObjectUnderTest(txn, name="p02_2.ics", calendar_name="calendar", home="puser02")
attachment, _ignore_location = yield obj.addAttachment(None, MimeType.fromString("text/plain"), "test_p02.txt", MemoryStream("Here is some text #p02."))
self.stash["puser02_attachment_id"] = attachment.id()
self.stash["puser02_attachment_mid"] = attachment.managedID()
self.stash["puser02_attachment_md5"] = attachment.md5()
yield self.commitTransaction(1)
yield self.waitAllEmpty()
开发者ID:eventable,项目名称:CalendarServer,代码行数:14,代码来源:test_migration.py
示例16: test_get_attachment_data
def test_get_attachment_data(self):
"""
Test that action=get-all-attachments works.
"""
yield self.createShare("user01", "puser01")
calendar1 = yield self.calendarUnderTest(txn=self.theTransactionUnderTest(0), home="user01", name="calendar")
yield calendar1.createCalendarObjectWithName("1.ics", Component.fromString(self.caldata1))
yield self.commitTransaction(0)
object1 = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(0), home="user01", calendar_name="calendar", name="1.ics")
attachment, _ignore_location = yield object1.addAttachment(None, MimeType.fromString("text/plain"), "test.txt", MemoryStream("Here is some text."))
remote_id = attachment.id()
yield self.commitTransaction(0)
home1 = yield self.homeUnderTest(txn=self.theTransactionUnderTest(1), name="puser01")
shared_object = yield self.calendarObjectUnderTest(txn=self.theTransactionUnderTest(1), home="puser01", calendar_name="shared-calendar", name="1.ics")
attachment = yield ManagedAttachment._create(self.theTransactionUnderTest(1), None, home1.id())
attachment._contentType = MimeType.fromString("text/plain")
attachment._name = "test.txt"
yield shared_object.ownerHome().readAttachmentData(remote_id, attachment)
yield self.commitTransaction(1)
开发者ID:eventable,项目名称:CalendarServer,代码行数:23,代码来源:test_conduit.py
示例17: render
def render(self, request):
lastID = request.headers.getRawHeaders(u"last-event-id")
response = Response()
response.stream = EventStream(self._eventDecoder, self._events, lastID)
response.headers.setHeader(b"content-type", MimeType.fromString(b"text/event-stream"))
# Keep track of the event streams
def cleanupFilter(_request, _response):
self._streams.remove(response.stream)
return _response
request.addResponseFilter(cleanupFilter)
self._streams.add(response.stream)
return response
开发者ID:redtailtech,项目名称:calendarserver,代码行数:16,代码来源:eventsource.py
示例18: secondState
def secondState(self):
"""
Setup the server with data changes appearing after the first sync
"""
txn = self.theTransactionUnderTest(0)
obj = yield self.calendarObjectUnderTest(txn, name="01_1.ics", calendar_name="calendar", home="user01")
yield obj.setComponent(self.data01_1_changed)
obj = yield self.calendarObjectUnderTest(txn, name="02_2.ics", calendar_name="calendar", home="user02")
attachment, _ignore_location = yield obj.addAttachment(None, MimeType.fromString("text/plain"), "test_02.txt", MemoryStream("Here is some text #02."))
self.stash["user02_attachment_id"] = attachment.id()
self.stash["user02_attachment_md5"] = attachment.md5()
self.stash["user02_attachment_mid"] = attachment.managedID()
yield self.commitTransaction(0)
yield self.waitAllEmpty()
开发者ID:eventable,项目名称:CalendarServer,代码行数:17,代码来源:test_migration.py
示例19: doGet
def doGet(self, request):
"""
Return the specified timezone data.
"""
tzids = request.args.get("tzid", ())
if len(tzids) != 1:
raise HTTPError(JSONResponse(
responsecode.BAD_REQUEST,
{
"error": "invalid-tzid",
"description": "Invalid tzid query parameter",
},
))
format = request.args.get("format", ("text/calendar",))
if len(format) != 1 or format[0] not in self.formats:
raise HTTPError(JSONResponse(
responsecode.BAD_REQUEST,
{
"error": "invalid-format",
"description": "Invalid format query parameter",
},
))
format = format[0]
calendar = self.timezones.getTimezone(tzids[0])
if calendar is None:
raise HTTPError(JSONResponse(
responsecode.NOT_FOUND,
{
"error": "missing-tzid",
"description": "Tzid could not be found",
}
))
tzdata = calendar.getText(format=format if format != "text/plain" else None)
response = Response()
response.stream = MemoryStream(tzdata)
response.headers.setHeader("content-type", MimeType.fromString("%s; charset=utf-8" % (format,)))
return response
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:42,代码来源:timezonestdservice.py
示例20: actionGet
def actionGet(self, request, tzid):
"""
Return the specified timezone data.
"""
if set(request.args.keys()) - set(("start", "end",)):
self.problemReport("invalid-action", "Invalid request-URI query parameters", responsecode.BAD_REQUEST)
accepted_type = bestAcceptType(request.headers.getHeader("accept"), self.formats)
if accepted_type is None:
self.problemReport("invalid-format", "Accept header does not match available media types", responsecode.NOT_ACCEPTABLE)
calendar = self.timezones.getTimezone(tzid)
if calendar is None:
self.problemReport("tzid-not-found", "Time zone identifier not found", responsecode.NOT_FOUND)
tzdata = calendar.getText(format=accepted_type if accepted_type != "text/plain" else None)
response = Response()
response.stream = MemoryStream(tzdata)
response.headers.setHeader("content-type", MimeType.fromString("%s; charset=utf-8" % (accepted_type,)))
return response
开发者ID:eventable,项目名称:CalendarServer,代码行数:22,代码来源:timezonestdservice.py
注:本文中的txweb2.http_headers.MimeType类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论