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


Python ServerLocations.read方法代码示例

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


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

示例1: test_server_locations_callback

# 需要导入模块: from mozprofile.permissions import ServerLocations [as 别名]
# 或者: from mozprofile.permissions.ServerLocations import read [as 别名]
    def test_server_locations_callback(self):
        class CallbackTest(object):
            last_locations = None

            def callback(self, locations):
                self.last_locations = locations

        c = CallbackTest()
        f = self.create_temp_file(self.locations)
        locations = ServerLocations(f.name, c.callback)

        # callback should be for all locations in file
        self.assertEqual(len(c.last_locations), 6)

        # validate arbitrary one
        self.compare_location(c.last_locations[2], 'http', '127.0.0.1', '8888',
                              ['privileged'])

        locations.add_host('a.b.c')

        # callback should be just for one location
        self.assertEqual(len(c.last_locations), 1)
        self.compare_location(c.last_locations[0], 'http', 'a.b.c', '80',
                              ['privileged'])

        # read a second file, which should generate a callback with both
        # locations.
        f = self.create_temp_file(self.locations_no_primary)
        locations.read(f.name)
        self.assertEqual(len(c.last_locations), 2)
开发者ID:luke-chang,项目名称:gecko-1,代码行数:32,代码来源:server_locations.py

示例2: __init__

# 需要导入模块: from mozprofile.permissions import ServerLocations [as 别名]
# 或者: from mozprofile.permissions.ServerLocations import read [as 别名]
    def __init__(self, options, **kwargs):
        self.options = options
        self.server = None
        self.logger = mozlog.getLogger('PEP')

        # create the profile
        enable_proxy = False
        locations = ServerLocations()
        if self.options.proxyLocations:
            if not self.options.serverPath:
                self.logger.warning('Can\'t set up proxy without server path')
            else:
                enable_proxy = True
                for proxyLocation in self.options.proxyLocations:
                    locations.read(proxyLocation, False)
                locations.add_host(host='127.0.0.1',
                                   port=self.options.serverPort,
                                   options='primary,privileged')

        self.profile = self.profile_class(profile=self.options.profilePath,
                                          addons=[os.path.join(here, 'extension')],
                                          locations=locations,
                                          proxy=enable_proxy)

        # fork a server to serve the test related files
        if self.options.serverPath:
            self.runServer()

        tests = []
        # TODO is there a better way of doing this?
        if self.options.testPath.endswith('.js'):
            # a single test file was passed in
            testObj = {}
            testObj['path'] = os.path.realpath(self.options.testPath)
            testObj['name'] = os.path.basename(self.options.testPath)
            testObj['here'] = os.path.dirname(testObj['path'])
            tests.append(testObj)
        else:
            # a test manifest was passed in
            # open and convert the manifest to json
            manifest = TestManifest()
            manifest.read(self.options.testPath)
            tests = manifest.get()

        # create a manifest object to be read by the JS side
        manifestObj = {}
        manifestObj['tests'] = tests
        manifestObj['options'] = options.__dict__

        # write manifest to a JSON file
        jsonManifest = open(os.path.join(here, 'manifest.json'), 'w')
        jsonManifest.write(json.dumps(manifestObj))
        jsonManifest.close()

        # setup environment
        env = os.environ.copy()
        env['MOZ_INSTRUMENT_EVENT_LOOP'] = '1'
        env['MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD'] = str(options.tracerThreshold)
        env['MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL'] = str(options.tracerInterval)
        env['MOZ_CRASHREPORTER_NO_REPORT'] = '1'

        # construct the browser arguments
        cmdargs = []
        # TODO Make browserArgs a list
        cmdargs.extend(self.options.browserArgs)
        cmdargs.extend(['-pep-start', os.path.realpath(jsonManifest.name)])

        # run with managed process handler
        self.runner = self.runner_class(profile=self.profile,
                                        binary=self.options.binary,
                                        cmdargs=cmdargs,
                                        env=env,
                                        process_class=PepProcess)
开发者ID:mozilla,项目名称:peptest,代码行数:75,代码来源:runpeptests.py

示例3: __init__

# 需要导入模块: from mozprofile.permissions import ServerLocations [as 别名]
# 或者: from mozprofile.permissions.ServerLocations import read [as 别名]
    def __init__(self, options, **kwargs):
        self.options = options
        self.server = None
        self.logger = mozlog.getLogger("PEP")

        # create the profile
        enable_proxy = False
        locations = ServerLocations()
        if self.options.proxyLocations:
            if not self.options.serverPath:
                self.logger.warning("Can't set up proxy without server path")
            else:
                enable_proxy = True
                locations.read(self.options.proxyLocations, False)
                locations.add_host(host="127.0.0.1", port=self.options.serverPort, options="primary,privileged")

        self.profile = self.profile_class(
            profile=self.options.profilePath,
            addons=[os.path.join(here, "extension")],
            locations=locations,
            proxy=enable_proxy,
        )

        # fork a server to serve the test related files
        if self.options.serverPath:
            self.runServer()

        tests = []
        # TODO is there a better way of doing this?
        if self.options.testPath.endswith(".js"):
            # a single test file was passed in
            testObj = {}
            testObj["path"] = os.path.realpath(self.options.testPath)
            testObj["name"] = os.path.basename(self.options.testPath)
            testObj["here"] = os.path.dirname(testObj["path"])
            tests.append(testObj)
        else:
            # a test manifest was passed in
            # open and convert the manifest to json
            manifest = TestManifest()
            manifest.read(self.options.testPath)
            tests = manifest.get()

        # create a manifest object to be read by the JS side
        manifestObj = {}
        manifestObj["tests"] = tests
        manifestObj["options"] = options.__dict__

        # write manifest to a JSON file
        jsonManifest = open(os.path.join(here, "manifest.json"), "w")
        jsonManifest.write(json.dumps(manifestObj))
        jsonManifest.close()

        # setup environment
        env = os.environ.copy()
        env["MOZ_INSTRUMENT_EVENT_LOOP"] = "1"
        env["MOZ_INSTRUMENT_EVENT_LOOP_THRESHOLD"] = str(options.tracerThreshold)
        env["MOZ_INSTRUMENT_EVENT_LOOP_INTERVAL"] = str(options.tracerInterval)
        env["MOZ_CRASHREPORTER_NO_REPORT"] = "1"

        # construct the browser arguments
        cmdargs = []
        # TODO Make browserArgs a list
        cmdargs.extend(self.options.browserArgs)
        cmdargs.extend(["-pep-start", os.path.realpath(jsonManifest.name)])

        # run with managed process handler
        self.runner = self.runner_class(
            profile=self.profile, binary=self.options.binary, cmdargs=cmdargs, env=env, process_class=PepProcess
        )
开发者ID:lofter2011,项目名称:Icefox,代码行数:72,代码来源:runpeptests.py


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