Exemplo n.º 1
0
    def _saveImage(self, href):
        # Try to do images only once.
        if href in self.downloadedHrefs:
            return

        fileName = self._generateResourceName(self.imagesDir, href, IZResourceDependencyTypes.IMAGE)
        listener = ZBinaryToWebpageGetterAdapterListener(href, self.listener)
        download = ZHttpBinaryFileDownload(href, fileName, listener)
        self.listener.onWebpageGetterResourceStarted(href, IZResourceDependencyTypes.IMAGE)
        if download.send(None):
            return fileName
        else:
            return None
Exemplo n.º 2
0
 def _verifyHttpURL(self, url):
     tempFilePath = os.path.join(getApplicationModel().getUserProfile().getTempDirectory(), u"tmp_url_mstore_ztest.bin") #$NON-NLS-1$
     downloader = ZHttpBinaryFileDownload(url, tempFilePath)
     try:
         if not downloader.send():
             raise ZException(_extstr(u"mediastorageztest.FileNotFoundError") % url) #$NON-NLS-1$
         ct = downloader.getContentType()
         if not (ct == u"image/png"): #$NON-NLS-1$
             raise ZException(_extstr(u"mediastorageztest.IncorrectContentTypeError") % (ct, url)) #$NON-NLS-1$
         numBytes = downloader.getResponse()
         if numBytes != 222: # Note: the test file is 222 bytes in size
             raise ZException(_extstr(u"mediastorageztest.TestFileWrongSizeError")) #$NON-NLS-1$
     finally:
         if os.path.isfile(tempFilePath):
             os.remove(tempFilePath)
Exemplo n.º 3
0
    def _saveImage(self, href):
        # Try to do images only once.
        if href in self.downloadedHrefs:
            return

        fileName = self._generateResourceName(self.imagesDir, href,
                                              IZResourceDependencyTypes.IMAGE)
        listener = ZBinaryToWebpageGetterAdapterListener(href, self.listener)
        download = ZHttpBinaryFileDownload(href, fileName, listener)
        self.listener.onWebpageGetterResourceStarted(
            href, IZResourceDependencyTypes.IMAGE)
        if download.send(None):
            return fileName
        else:
            return None
Exemplo n.º 4
0
 def _verifyHttpURL(self, url):
     tempFilePath = os.path.join(getApplicationModel().getUserProfile().getTempDirectory(), u"tmp_url_mstore_ztest.bin") #$NON-NLS-1$
     downloader = ZHttpBinaryFileDownload(url, tempFilePath)
     try:
         downloader.send()
         ct = downloader.getContentType()
         numBytes = downloader.getResponse()
         if (ct == u"image/png") and (numBytes == 222): #$NON-NLS-1$
             raise ZException(_extstr(u"mediastorageztest.FileStillExistsError") % url) #$NON-NLS-1$
     finally:
         if os.path.isfile(tempFilePath):
             os.remove(tempFilePath)