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


Python QNetworkDiskCache.setCacheDirectory方法代码示例

本文整理汇总了Python中PyQt4.QtNetwork.QNetworkDiskCache.setCacheDirectory方法的典型用法代码示例。如果您正苦于以下问题:Python QNetworkDiskCache.setCacheDirectory方法的具体用法?Python QNetworkDiskCache.setCacheDirectory怎么用?Python QNetworkDiskCache.setCacheDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtNetwork.QNetworkDiskCache的用法示例。


在下文中一共展示了QNetworkDiskCache.setCacheDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: construct

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
def construct(path=defaults.CACHE_PATH, size=defaults.CACHE_SIZE):
    log.msg("Initializing cache on %s (maxsize: %d Mb)" % (path, size))
    cache = QNetworkDiskCache()
    cache.setCacheDirectory(path)
    cache.setMaximumCacheSize(size * 1024**2)
    cache.cacheSize()  # forces immediate initialization
    return cache
开发者ID:0xmilk,项目名称:splash,代码行数:9,代码来源:cache.py

示例2: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def __init__(self, diskCacheEnabled, parent = None):
        QNetworkAccessManager.__init__(self, parent)
        self.finished.connect(self.handleFinished)

        if diskCacheEnabled == 'yes':
            m_networkDiskCache = QNetworkDiskCache()
            m_networkDiskCache.setCacheDirectory(QDesktopServices.storageLocation(QDesktopServices.CacheLocation))
            self.setCache(m_networkDiskCache)
开发者ID:NathanHowell,项目名称:phantomjs-waf,代码行数:10,代码来源:networkaccessmanager.py

示例3: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def __init__(self, diskCacheEnabled, ignoreSslErrors, parent=None):
        QNetworkAccessManager.__init__(self, parent)
        self.m_ignoreSslErrors = ignoreSslErrors

        if parent.m_verbose:
            self.finished.connect(self.handleFinished)

        if diskCacheEnabled == 'yes':
            m_networkDiskCache = QNetworkDiskCache()
            m_networkDiskCache.setCacheDirectory(QDesktopServices.storageLocation(QDesktopServices.CacheLocation))
            self.setCache(m_networkDiskCache)

        do_action('NetworkAccessManagerInit', Bunch(locals()))
开发者ID:10git,项目名称:TheObserver,代码行数:15,代码来源:networkaccessmanager.py

示例4: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def __init__(self, parent=None):
        QObject.__init__(self, parent=None)
        assert QThread.currentThread() is QApplication.instance().thread()

        netmanager = self._NETMANAGER_REF and self._NETMANAGER_REF()
        if netmanager is None:
            netmanager = QNetworkAccessManager()
            cache = QNetworkDiskCache()
            cache.setCacheDirectory(
                os.path.join(settings.widget_settings_dir(),
                             __name__ + ".ImageLoader.Cache")
            )
            netmanager.setCache(cache)
            ImageLoader._NETMANAGER_REF = weakref.ref(netmanager)
        self._netmanager = netmanager
开发者ID:TimothyXie,项目名称:orange3,代码行数:17,代码来源:owimageviewer.py

示例5: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def __init__(self, diskCacheEnabled, ignoreSslErrors, parent=None):
        QNetworkAccessManager.__init__(self, parent)

        self.m_ignoreSslErrors = ignoreSslErrors
        self.m_idCounter = 0
        self.m_ids = {}
        self.m_started = []

        self.finished.connect(self.handleFinished)

        if diskCacheEnabled:
            m_networkDiskCache = QNetworkDiskCache()
            m_networkDiskCache.setCacheDirectory(QDesktopServices.storageLocation(QDesktopServices.CacheLocation))
            self.setCache(m_networkDiskCache)

        do_action('NetworkAccessManagerInit')
开发者ID:antlong,项目名称:jellypy,代码行数:18,代码来源:networkaccessmanager.py

示例6: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
 def __init__(self, *args, **kwargs):
     cache_dir = kwargs.pop("cache_dir", "/tmp/ghost.py")
     cache_size = kwargs.pop("cache_size", 0)
     self._prevent_download = kwargs.pop("prevent_download", [])
     
     super(NetworkAccessManager, self).__init__(*args, **kwargs)
     if cache_size > 0:
         cache = QNetworkDiskCache()
         cache.setCacheDirectory(cache_dir)
         cache.setMaximumCacheSize(cache_size * 1024 * 1024)
         self.setCache(cache)
     
     # Manages the authentication for the proxy
     self.proxyAuthenticationRequired.connect(self._authenticateProxy)
     self.authenticationRequired.connect(self._authenticate)
     
     # Handles redirects
     self.finished.connect(self._replyFinished)
开发者ID:handloomweaver,项目名称:Ghost.py,代码行数:20,代码来源:NetworkAccessManager.py

示例7: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
 def __init__(self, proxy, forbidden_extensions, allowed_regex, cache_size=100, cache_dir='.webkit_cache'):
     """
     See WebkitBrowser for details of arguments
 
     cache_size:
         the maximum size of the webkit cache (MB)
     """
     QNetworkAccessManager.__init__(self)
     # and proxy
     self.setProxy(proxy)
     # initialize the manager cache
     QDesktopServices.storageLocation(QDesktopServices.CacheLocation)
     cache = QNetworkDiskCache()
     cache.setCacheDirectory(cache_dir)
     cache.setMaximumCacheSize(cache_size * 1024 * 1024) # need to convert cache value to bytes
     self.setCache(cache)
     self.allowed_regex = allowed_regex
     self.forbidden_extensions = forbidden_extensions
开发者ID:Hack42,项目名称:BusNotifier,代码行数:20,代码来源:webkit.py

示例8: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
 def __init__(self, proxy, allowed_media, allowed_regex, cache_size=100, cache_dir='.webkit_cache'):
     """
     See JQueryBrowser for details of arguments
     cache_size is the maximum size of the webkit cache (MB)
     """
     QNetworkAccessManager.__init__(self)
     # initialize the manager cache
     #QDesktopServices.storageLocation(QDesktopServices.CacheLocation)
     cache = QNetworkDiskCache()
     cache.setCacheDirectory(cache_dir)
     cache.setMaximumCacheSize(cache_size * 1024 * 1024) # need to convert cache value to bytes
     self.setCache(cache)
     self.allowed_regex = allowed_regex
     # allowed content extensions
     self.banned_extensions = common.MEDIA_EXTENSIONS
     for ext in allowed_media:
         if ext in self.banned_extensions:
             self.banned_extensions.remove(ext)
     # and proxy
     self.setProxy(proxy)
开发者ID:gotomypc,项目名称:webscraping,代码行数:22,代码来源:webkit.py

示例9: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
 def __init__(self, proxy, allowed_extensions, cache_size=100, cache_dir='.webkit_cache'):
     """
     proxy is a QNetworkProxy
     allowed_extensions is a list of extensions to allow
     cache_size is the maximum size of the cache (MB)
     """
     QNetworkAccessManager.__init__(self)
     # initialize the manager cache
     cache = QNetworkDiskCache()
     #QDesktopServices.storageLocation(QDesktopServices.CacheLocation)
     cache.setCacheDirectory(cache_dir)
     cache.setMaximumCacheSize(cache_size * 1024 * 1024) # need to convert cache value to bytes
     self.setCache(cache)
     # allowed content extensions
     self.banned_extensions = common.MEDIA_EXTENSIONS
     for ext in allowed_extensions:
         if ext in self.banned_extensions:
             self.banned_extensions.remove(ext)
     # and proxy
     if proxy:
         self.setProxy(proxy)
开发者ID:gerrich,项目名称:qtbot,代码行数:23,代码来源:qt_framework.py

示例10: _fetch_inventory

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def _fetch_inventory(self, url):
        cache_dir = config.cache_dir()
        cache_dir = os.path.join(cache_dir, "help", type(self).__qualname__)

        try:
            os.makedirs(cache_dir)
        except OSError:
            pass

        url = QUrl(self.inventory)
        if not url.isLocalFile():
            # fetch and cache the inventory file.
            manager = QNetworkAccessManager(self)
            cache = QNetworkDiskCache()
            cache.setCacheDirectory(cache_dir)
            manager.setCache(cache)
            req = QNetworkRequest(url)

            self._reply = manager.get(req)
            manager.finished.connect(self._on_finished)
        else:
            self._load_inventory(open(str(url.toLocalFile()), "rb"))
开发者ID:Coding4Sec,项目名称:orange3,代码行数:24,代码来源:provider.py

示例11: _fetch_inventory

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def _fetch_inventory(self):
        cache_dir = config.cache_dir()
        cache_dir = os.path.join(cache_dir, "help", "intersphinx")

        try:
            os.makedirs(cache_dir)
        except OSError:
            pass

        url = QUrl(self.inventory)

        if not self.islocal:
            # fetch and cache the inventory file
            manager = QNetworkAccessManager(self)
            cache = QNetworkDiskCache()
            cache.setCacheDirectory(cache_dir)
            manager.setCache(cache)
            req = QNetworkRequest(url)

            self._reply = manager.get(req)
            manager.finished.connect(self._on_finished)
        else:
            self._load_inventory(open(unicode(url.toLocalFile()), "rb"))
开发者ID:pauloortins,项目名称:Computer-Vision-Classes---UFBA,代码行数:25,代码来源:provider.py

示例12: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def __init__(self, parent, args):
        super(NetworkAccessManager, self).__init__(parent)

        self.m_userName = self.m_password = ''
        self.m_ignoreSslErrors = args.ignore_ssl_errors
        self.m_idCounter = 0
        self.m_ids = {}
        self.m_started = []

        if args.cookies_file:
            self.setCookieJar(CookieJar(self, args.cookies_file))

        if args.disk_cache:
            m_networkDiskCache = QNetworkDiskCache()
            m_networkDiskCache.setCacheDirectory(QDesktopServices.storageLocation(QDesktopServices.CacheLocation))
            if args.max_disk_cache_size > 0:
                m_networkDiskCache.setMaximumCacheSize(args.max_disk_cache_size * 1024)
            self.setCache(m_networkDiskCache)

        self.authenticationRequired.connect(self.provideAuthentication)
        self.finished.connect(self.handleFinished)

        do_action('NetworkAccessManagerInit')
开发者ID:Wolfcrush,项目名称:ios-uiautomation,代码行数:25,代码来源:networkaccessmanager.py

示例13: __init__

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
    def __init__(self, parent, auth, cookieFile, diskCacheEnabled, ignoreSslErrors):
        QNetworkAccessManager.__init__(self, parent)

        self.m_ignoreSslErrors = ignoreSslErrors
        self.m_idCounter = 0
        self.m_ids = {}
        self.m_started = []

        self.finished.connect(self.handleFinished)

        if auth:
            self.m_authUser = auth[0]
            self.m_authPass = auth[1]
            self.authenticationRequired.connect(self.provideAuthentication)

        if cookieFile:
            self.setCookieJar(CookieJar(self, cookieFile))

        if diskCacheEnabled:
            m_networkDiskCache = QNetworkDiskCache()
            m_networkDiskCache.setCacheDirectory(QDesktopServices.storageLocation(QDesktopServices.CacheLocation))
            self.setCache(m_networkDiskCache)

        do_action('NetworkAccessManagerInit')
开发者ID:mralexgray,项目名称:phantomjs,代码行数:26,代码来源:networkaccessmanager.py

示例14: GRobot

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]

#.........这里部分代码省略.........
                                'an X instance')

        self.display = display

        if not GRobot._app:
            GRobot._app = QApplication.instance() or QApplication(['GRobot'])
            if plugin_path:
                for p in plugin_path:
                    GRobot._app.addLibraryPath(p)

        self.page = GRobotWebPage(self, GRobot._app)

        QtWebKit.QWebSettings.setMaximumPagesInCache(0)
        QtWebKit.QWebSettings.setObjectCacheCapacities(0, 0, 0)
        QtWebKit.QWebSettings.globalSettings().setAttribute(QtWebKit.QWebSettings.LocalStorageEnabled, True)

        self.page.setForwardUnsupportedContent(True)

        # Page signals
        self.page.loadFinished.connect(self._page_loaded)
        self.page.loadStarted.connect(self._page_load_started)
        self.page.unsupportedContent.connect(self._unsupported_content)

        self.manager = self.page.networkAccessManager()

        #TODO:Think about how to handle the network accessible signal
        #self.manager.networkAccessibleChanged.connect()

        self.manager.finished.connect(self._request_ended)
        self.manager.sslErrors.connect(self._on_manager_ssl_errors)

        # Cache
        self.cache = QNetworkDiskCache()
        self.cache.setCacheDirectory(cache_dir)

        self.manager.setCache(self.cache)

        # Cookie jar
        self.cookie_jar = QNetworkCookieJar()
        self.manager.setCookieJar(self.cookie_jar)

        # User Agent
        self.page.setUserAgent(self.user_agent)

        self.page.networkAccessManager().authenticationRequired \
            .connect(self._authenticate)
        self.page.networkAccessManager().proxyAuthenticationRequired \
            .connect(self._authenticate)

        self.main_frame = self.page.mainFrame()

        self.webview = None

        self.viewport_size = viewport_size

        self.webview = QtWebKit.QWebView()
        self.webview.setPage(self.page)

        self.webview.show() if display else self.webview.hide()

        self.set_viewport_size(*viewport_size)

        self.page.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, plugins_enabled)
        self.page.settings().setAttribute(QtWebKit.QWebSettings.JavaEnabled, java_enabled)
        self.page.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, self.develop)
开发者ID:waitingzeng,项目名称:GRobot,代码行数:69,代码来源:grobot.py

示例15: Ghost

# 需要导入模块: from PyQt4.QtNetwork import QNetworkDiskCache [as 别名]
# 或者: from PyQt4.QtNetwork.QNetworkDiskCache import setCacheDirectory [as 别名]
class Ghost(object):
    """Ghost manages a QWebPage.

    :param user_agent: The default User-Agent header.
    :param wait_timeout: Maximum step duration in second.
    :param wait_callback: An optional callable that is periodically
        executed until Ghost stops waiting.
    :param log_level: The optional logging level.
    :param display: A boolean that tells ghost to displays UI.
    :param viewport_size: A tupple that sets initial viewport size.
    """
    _alert = None
    _confirm_expected = None
    _prompt_expected = None
    _upload_file = None
    _app = None

    def __init__(self, user_agent=default_user_agent, wait_timeout=8,
            wait_callback=None, log_level=logging.WARNING, display=False,
            viewport_size=(800, 600), cache_dir='/tmp/ghost.py'):
        self.http_resources = []

        self.user_agent = user_agent
        self.wait_timeout = wait_timeout
        self.wait_callback = wait_callback

        self.loaded = True

        if not sys.platform.startswith('win') and not 'DISPLAY' in os.environ\
                and not hasattr(Ghost, 'xvfb'):
            try:
                os.environ['DISPLAY'] = ':99'
                Ghost.xvfb = subprocess.Popen(['Xvfb', ':99'])
            except OSError:
                raise Exception('Xvfb is required to a ghost run oustside ' +\
                    'an X instance')

        self.display = display

        if not Ghost._app:
            Ghost._app = QApplication.instance() or QApplication(['ghost'])

        self.page = GhostWebPage(Ghost._app)
        QtWebKit.QWebSettings.setMaximumPagesInCache(0)
        QtWebKit.QWebSettings.setObjectCacheCapacities(0, 0, 0)

        self.page.setForwardUnsupportedContent(True)

        self.set_viewport_size(*viewport_size)

        # Page signals
        self.page.loadFinished.connect(self._page_loaded)
        self.page.loadStarted.connect(self._page_load_started)
        self.page.unsupportedContent.connect(self._unsupported_content)

        self.manager = self.page.networkAccessManager()
        self.manager.finished.connect(self._request_ended)
        # Cache
        self.cache = QNetworkDiskCache()
        self.cache.setCacheDirectory(cache_dir)
        self.manager.setCache(self.cache)
        # Cookie jar
        self.cookie_jar = QNetworkCookieJar()
        self.manager.setCookieJar(self.cookie_jar)
        # User Agent
        self.page.setUserAgent(self.user_agent)

        self.page.networkAccessManager().authenticationRequired\
            .connect(self._authenticate)
        self.page.networkAccessManager().proxyAuthenticationRequired\
            .connect(self._authenticate)

        self.main_frame = self.page.mainFrame()

        logger.setLevel(log_level)

        if self.display:
            self.webview = QtWebKit.QWebView()
            self.webview.setPage(self.page)
            self.webview.show()

    def __del__(self):
        self.exit()

    def capture(self, region=None, selector=None,
            format=QImage.Format_ARGB32_Premultiplied):
        """Returns snapshot as QImage.

        :param region: An optional tupple containing region as pixel
            coodinates.
        :param selector: A selector targeted the element to crop on.
        :param format: The output image format.
        """
        if region is None and selector is not None:
            region = self.region_for_selector(selector)
        if region:
            x1, y1, x2, y2 = region
            w, h = (x2 - x1), (y2 - y1)
            image = QImage(QSize(x2, y2), format)
            painter = QPainter(image)
#.........这里部分代码省略.........
开发者ID:colinjonesx,项目名称:Ghost.py,代码行数:103,代码来源:ghost.py


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