当前位置: 首页>>代码示例>>Python>>正文


Python CachingFilePath.remove方法代码示例

本文整理汇总了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)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:29,代码来源:test_collectioncontents.py

示例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)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:44,代码来源:test_collectioncontents.py

示例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()
开发者ID:azbarcea,项目名称:calendarserver,代码行数:23,代码来源:test_principals.py

示例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)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:38,代码来源:test_collectioncontents.py

示例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
        )

#.........这里部分代码省略.........
开发者ID:red-hood,项目名称:calendarserver,代码行数:103,代码来源:sql_attachment.py

示例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.
        """
开发者ID:anemitz,项目名称:calendarserver,代码行数:70,代码来源:test_xattrprops.py


注:本文中的twext.python.filepath.CachingFilePath.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。