本文整理汇总了Python中twext.python.filepath.CachingFilePath.remove方法的典型用法代码示例。如果您正苦于以下问题:Python CachingFilePath.remove方法的具体用法?Python CachingFilePath.remove怎么用?Python CachingFilePath.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twext.python.filepath.CachingFilePath
的用法示例。
在下文中一共展示了CachingFilePath.remove方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_collection_in_calendar
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import remove [as 别名]
def test_collection_in_calendar(self):
"""
Make (regular) collection in calendar
"""
calendar_path, calendar_uri = self.mkdtemp("collection_in_calendar")
calPath = FilePath(calendar_path)
calPath.remove()
def mkcalendar_cb(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
def mkcol_cb(response):
response = IResponse(response)
if response.code != responsecode.FORBIDDEN:
self.fail("Incorrect response to nested MKCOL: %s" % (response.code,))
nested_uri = "/".join([calendar_uri, "nested"])
request = SimpleRequest(self.site, "MKCOL", nested_uri)
self.send(request, mkcol_cb)
request = SimpleRequest(self.site, "MKCALENDAR", calendar_uri)
return self.send(request, mkcalendar_cb)
示例2: _test_file_in_calendar
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import remove [as 别名]
def _test_file_in_calendar(self, what, *work):
"""
Creates a calendar collection, then PUTs a resource into that collection
with the data from given stream and verifies that the response code from the
PUT request matches the given response_code.
"""
calendar_path, calendar_uri = self.mkdtemp("calendar")
calPath = FilePath(calendar_path)
calPath.remove()
def mkcalendar_cb(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
if not calPath.isdir():
self.fail("MKCALENDAR did not create a collection")
ds = []
c = 0
for stream, response_code in work:
def put_cb(response, stream=stream, response_code=response_code):
response = IResponse(response)
if response.code != response_code:
self.fail("Incorrect response to %s: %s (!= %s)" % (what, response.code, response_code))
dst_uri = "/".join([calendar_uri, "dst%d.ics" % (c,)])
request = SimpleRequest(self.site, "PUT", dst_uri)
request.headers.setHeader("if-none-match", "*")
request.headers.setHeader("content-type", MimeType("text", "calendar"))
request.stream = stream
ds.append(self.send(request, put_cb))
c += 1
return DeferredList(ds)
request = SimpleRequest(self.site, "MKCALENDAR", calendar_uri)
return self.send(request, mkcalendar_cb)
示例3: test_triggerGroupCacherUpdate
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import remove [as 别名]
def test_triggerGroupCacherUpdate(self):
"""
Verify triggerGroupCacherUpdate can read a pidfile and send a SIGHUP
"""
self.calledArgs = None
def killMethod(pid, sig):
self.calledArgs = (pid, sig)
class StubConfig(object):
def __init__(self, runRootPath):
self.RunRoot = runRootPath
runRootDir = FilePath(self.mktemp())
runRootDir.createDirectory()
pidFile = runRootDir.child("groupcacher.pid")
pidFile.setContent("1234")
testConfig = StubConfig(runRootDir.path)
triggerGroupCacherUpdate(testConfig, killMethod=killMethod)
self.assertEquals(self.calledArgs, (1234, signal.SIGHUP))
runRootDir.remove()
示例4: test_fail_dot_file_put_in_calendar
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import remove [as 别名]
def test_fail_dot_file_put_in_calendar(self):
"""
Make (regular) collection in calendar
"""
calendar_path, calendar_uri = self.mkdtemp("dot_file_in_calendar")
calPath = FilePath(calendar_path)
calPath.remove()
def mkcalendar_cb(response):
response = IResponse(response)
if response.code != responsecode.CREATED:
self.fail("MKCALENDAR failed: %s" % (response.code,))
def put_cb(response):
response = IResponse(response)
if response.code != responsecode.FORBIDDEN:
self.fail("Incorrect response to dot file PUT: %s" % (response.code,))
stream = self.dataPath.child(
"Holidays").child(
"C318AA54-1ED0-11D9-A5E0-000A958A3252.ics"
).open()
try: calendar = str(Component.fromStream(stream))
finally: stream.close()
event_uri = "/".join([calendar_uri, ".event.ics"])
request = SimpleRequest(self.site, "PUT", event_uri)
request.headers.setHeader("content-type", MimeType("text", "calendar"))
request.stream = MemoryStream(calendar)
self.send(request, put_cb)
request = SimpleRequest(self.site, "MKCALENDAR", calendar_uri)
return self.send(request, mkcalendar_cb)
示例5: AttachmentStorageTransport
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import remove [as 别名]
class AttachmentStorageTransport(StorageTransportBase):
_TEMPORARY_UPLOADS_DIRECTORY = "Temporary"
def __init__(self, attachment, contentType, dispositionName, creating=False, migrating=False):
super(AttachmentStorageTransport, self).__init__(
attachment, contentType, dispositionName)
fileDescriptor, fileName = self._temporaryFile()
# Wrap the file descriptor in a file object we can write to
self._file = os.fdopen(fileDescriptor, "w")
self._path = CachingFilePath(fileName)
self._hash = hashlib.md5()
self._creating = creating
self._migrating = migrating
self._txn.postAbort(self.aborted)
def _temporaryFile(self):
"""
Returns a (file descriptor, absolute path) tuple for a temporary file within
the Attachments/Temporary directory (creating the Temporary subdirectory
if it doesn't exist). It is the caller's responsibility to remove the
file.
"""
attachmentRoot = self._txn._store.attachmentsPath
tempUploadsPath = attachmentRoot.child(self._TEMPORARY_UPLOADS_DIRECTORY)
if not tempUploadsPath.exists():
tempUploadsPath.createDirectory()
return tempfile.mkstemp(dir=tempUploadsPath.path)
@property
def _txn(self):
return self._attachment._txn
def aborted(self):
"""
Transaction aborted - clean up temp files.
"""
if self._path.exists():
self._path.remove()
def write(self, data):
if isinstance(data, buffer):
data = str(data)
self._file.write(data)
self._hash.update(data)
@inlineCallbacks
def loseConnection(self):
"""
Note that when self._migrating is set we only care about the data and don't need to
do any quota checks/adjustments.
"""
# FIXME: this should be synchronously accessible; IAttachment should
# have a method for getting its parent just as CalendarObject/Calendar
# do.
# FIXME: If this method isn't called, the transaction should be
# prevented from committing successfully. It's not valid to have an
# attachment that doesn't point to a real file.
home = (yield self._txn.calendarHomeWithResourceID(self._attachment._ownerHomeID))
oldSize = self._attachment.size()
newSize = self._file.tell()
self._file.close()
# Check max size for attachment
if not self._migrating and newSize > config.MaximumAttachmentSize:
self._path.remove()
if self._creating:
yield self._attachment._internalRemove()
raise AttachmentSizeTooLarge()
# Check overall user quota
if not self._migrating:
allowed = home.quotaAllowedBytes()
if allowed is not None and allowed < ((yield home.quotaUsedBytes())
+ (newSize - oldSize)):
self._path.remove()
if self._creating:
yield self._attachment._internalRemove()
raise QuotaExceeded()
self._path.moveTo(self._attachment._path)
yield self._attachment.changed(
self._contentType,
self._dispositionName,
self._hash.hexdigest(),
newSize
)
#.........这里部分代码省略.........
示例6: ExtendedAttributesPropertyStoreTests
# 需要导入模块: from twext.python.filepath import CachingFilePath [as 别名]
# 或者: from twext.python.filepath.CachingFilePath import remove [as 别名]
#.........这里部分代码省略.........
self.assertEquals(
decompress(self._getValue(document)), document.root_element.toxml(pretty=False))
def test_delete(self):
"""
L{xattrPropertyStore.delete} deletes the named property.
"""
document = self._makeValue()
self.propertyStore.set(document.root_element)
self.propertyStore.delete(document.root_element.qname())
self.assertRaises(KeyError, self._getValue, document)
def test_deleteNonExistent(self):
"""
L{xattrPropertyStore.delete} does nothing if passed a property which
has no value.
"""
document = self._makeValue()
self.propertyStore.delete(document.root_element.qname())
self.assertRaises(KeyError, self._getValue, document)
def test_deleteErrors(self):
"""
If there is a problem deleting the specified property (aside from the
property not existing), L{xattrPropertyStore.delete} raises
L{HTTPError} with a status code which is determined by the nature of
the problem.
"""
# Remove the file so that deleting extended attributes of it fails with
# EEXIST.
self.resourcePath.remove()
# Try to delete a property from it - and fail.
document = self._makeValue()
error = self.assertRaises(
HTTPError,
self.propertyStore.delete, document.root_element.qname())
# Make sure that the status is NOT FOUND, a roughly reasonable mapping
# of the EEXIST failure.
self.assertEquals(error.response.code, NOT_FOUND)
def test_contains(self):
"""
L{xattrPropertyStore.contains} returns C{True} if the given property
has a value, C{False} otherwise.
"""
document = self._makeValue()
self.assertFalse(
self.propertyStore.contains(document.root_element.qname()))
self._setValue(document, document.toxml())
self.assertTrue(
self.propertyStore.contains(document.root_element.qname()))
def test_containsError(self):
"""
If there is a problem checking if the specified property exists (aside
from the property not existing), L{xattrPropertyStore.contains} raises
L{HTTPError} with a status code which is determined by the nature of
the problem.
"""