Example #1
0
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
class CustomNetworkAccessManager(QNetworkAccessManager):
    def __init__(self, parent = None):
        super().__init__(parent)
        # set cache
        self._cachePath = QNetworkDiskCache(self)
        cacheLocation = app.settings.get("legacy", "cachelocation")
        self._cachePath.setCacheDirectory(cacheLocation)
        self._cachePath.setMaximumCacheSize(20 * 1024 * 1024)  # 20M
        self.setCache(self._cachePath)

    def createRequest(self, op, request, device = None):
        qurl = request.url()
        if qurl.host() == "homecloud.yuancheng.xunlei.com":
            path = qurl.fileName()
            preprocessor = self.getPreprocessorFor(path)
            if preprocessor:
                request = preprocessor(request)

        return super().createRequest(op, request, device)

    def getPreprocessorFor(self, path):
        return getattr(self, "_preprocess_request_{}".format(path), None)

    @staticmethod
    def _redirectToLocal(request):
        qurl = request.url()
        adapter = app.adapterManager[0]
        host = adapter._xwareClient._options.get("host", "127.0.0.1")
        port = int(adapter._xwareClient._options.get("port", 9000))
        qurl.setHost(host)
        qurl.setPort(port)
        request.setUrl(qurl)
        return request

    @staticmethod
    def _preprocess_request_bind(request):
        # set boxName when binding the device to hostname

        urlQuery = QUrlQuery(request.url())
        queryItems = urlQuery.queryItems()

        for i, item in enumerate(queryItems):
            if item[0] == "boxName":
                queryItems[i] = ("boxName", os.uname().nodename)
        queryItems.append(("ct", "0"),)  # Issue #109, Xunlei bind API changed
        urlQuery.setQueryItems(queryItems)

        # write changes back to request
        qurl = request.url()
        qurl.setQuery(urlQuery)
        request.setUrl(qurl)

        return request

    @forLocalDeviceOnly
    def _preprocess_request_boxSpace(self, request):
        request = self._redirectToLocal(request)
        return request
class CustomNetworkAccessManager(QNetworkAccessManager):
    def __init__(self, parent=None):
        super().__init__(parent)
        # set cache
        self._cachePath = QNetworkDiskCache(self)
        cacheLocation = app.settings.get("legacy", "cachelocation")
        self._cachePath.setCacheDirectory(cacheLocation)
        self._cachePath.setMaximumCacheSize(20 * 1024 * 1024)  # 20M
        self.setCache(self._cachePath)

    def createRequest(self, op, request, device=None):
        qurl = request.url()
        if qurl.host() == "homecloud.yuancheng.xunlei.com":
            path = qurl.fileName()
            preprocessor = self.getPreprocessorFor(path)
            if preprocessor:
                request = preprocessor(request)

        return super().createRequest(op, request, device)

    def getPreprocessorFor(self, path):
        return getattr(self, "_preprocess_request_{}".format(path), None)

    @staticmethod
    def _redirectToLocal(request):
        qurl = request.url()
        adapter = app.adapterManager[0]
        host = adapter._xwareClient._options.get("host", "127.0.0.1")
        port = int(adapter._xwareClient._options.get("port", 9000))
        qurl.setHost(host)
        qurl.setPort(port)
        request.setUrl(qurl)
        return request

    @staticmethod
    def _preprocess_request_bind(request):
        # set boxName when binding the device to hostname

        urlQuery = QUrlQuery(request.url())
        queryItems = urlQuery.queryItems()

        for i, item in enumerate(queryItems):
            if item[0] == "boxName":
                queryItems[i] = ("boxName", os.uname().nodename)
        queryItems.append(("ct", "0"), )  # Issue #109, Xunlei bind API changed
        urlQuery.setQueryItems(queryItems)

        # write changes back to request
        qurl = request.url()
        qurl.setQuery(urlQuery)
        request.setUrl(qurl)

        return request

    @forLocalDeviceOnly
    def _preprocess_request_boxSpace(self, request):
        request = self._redirectToLocal(request)
        return request
Example #4
0
 def create(self, parent):
     nam = QNetworkAccessManager(parent)
     diskCache = QNetworkDiskCache(nam)
     cachePath = QStandardPaths.displayName(QStandardPaths.CacheLocation)
     print "cache path:", cachePath
     diskCache.setCacheDirectory(cachePath)
     diskCache.setMaximumCacheSize(100 * 1024 * 1024)  # 设置100M缓存
     nam.setCache(diskCache)
     return nam
class CustomNetworkAccessManager(QNetworkAccessManager):
    _cachePath = None

    def __init__(self, parent = None):
        super().__init__(parent)
        # set cache
        self._cachePath = QNetworkDiskCache(self)
        cacheLocation = app.settings.get("frontend", "cachelocation")
        self._cachePath.setCacheDirectory(cacheLocation)
        self._cachePath.setMaximumCacheSize(20 * 1024 * 1024)  # 20M
        self.setCache(self._cachePath)

    def createRequest(self, op, request, device = None):
        qurl = CompatUrl(request.url())
        if qurl.host() == "homecloud.yuancheng.xunlei.com":
            path = qurl.fileName()
            preprocessor = self.getPreprocessorFor(path)
            if preprocessor:
                request = preprocessor(request)

        return super().createRequest(op, request, device)

    def getPreprocessorFor(self, path):
        return getattr(self, "_preprocess_request_{}".format(path), None)

    @staticmethod
    def _redirectToLocal(request):
        qurl = request.url()
        qurl.setHost("127.0.0.1")
        qurl.setPort(app.etmpy.getLcPort())
        request.setUrl(qurl)
        return request

    @staticmethod
    def _preprocess_request_bind(request):
        # set boxName when binding the device to hostname

        urlQuery = QUrlQuery(request.url())
        queryItems = urlQuery.queryItems()

        for i, item in enumerate(queryItems):
            if item[0] == "boxName":
                queryItems[i] = ("boxName", os.uname().nodename)
        urlQuery.setQueryItems(queryItems)

        # write changes back to request
        qurl = request.url()
        qurl.setQuery(urlQuery)
        request.setUrl(qurl)

        return request

    @forLocalDeviceOnly
    def _preprocess_request_boxSpace(self, request):
        request = self._redirectToLocal(request)
        return request
class CustomNetworkAccessManager(QNetworkAccessManager):
    _cachePath = None

    def __init__(self, parent = None):
        super().__init__(parent)

        # set cache
        self._cachePath = QNetworkDiskCache(self)
        cacheLocation = QGuiApplication.instance().settings.get("frontend", "cachelocation")
        self._cachePath.setCacheDirectory(cacheLocation)
        self._cachePath.setMaximumCacheSize(20 * 1024 * 1024) # 20M
        self.setCache(self._cachePath)
Example #7
0
    def __init__(self):
        super(NetworkAccessManager, self).__init__()
        self.finished.connect(self.finishd)

        self.request_Urls = []
        self.replys = []
        #self.reply.finished.connect(self.finishd)
        cache = QNetworkDiskCache()
        cache.setCacheDirectory('.cache')
        cache.setMaximumCacheSize(1 * 1024 *
                                  1024)  # need to convert cache value to bytes
        self.setCache(cache)
        #self.SIGNAL.connect(self.finished)
        self.ban = (
            '.*\.css',
            '.*\.jpg',
            '.*\.png',
        )
Example #8
0
  print("DEBUG_MODE is {}.".format(conf.DEBUG_MODE))

  # initialize output directory
  from utilities import initOutputDir
  initOutputDir()

  plugin_name = os.path.basename(plugin_dir)
  suite = unittest.TestLoader().discover(plugin_name + ".tests")
  unittest.TextTestRunner(verbosity=2).run(suite)


if __name__ == "__main__":
  import argparse
  parser = argparse.ArgumentParser()
  parser.add_argument("-d", "--debug", type=int, choices=[0, 1, 2],
                      help="debug mode (0: OFF, 1 or 2: ON)")
  args = parser.parse_args()

  QgsApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
  QGISAPP = start_app()

  # set up network disk cache
  manager = QgsNetworkAccessManager.instance()
  cache = QNetworkDiskCache(manager)
  cache.setCacheDirectory(os.path.join(plugin_dir, "tests", "cache"))
  cache.setMaximumCacheSize(50 * 1024 * 1024)
  manager.setCache(cache)

  # run test!
  runTest(args.debug)