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


Python environ.items方法代码示例

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


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

示例1: submit_job

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def submit_job():
    opts = [
        ["--{}".format(key[4:].replace("_", "-")), value]
        for key, value in environ.items()
        if key.startswith("TBV_") and key != "TBV_CLASS"
    ]

    command = [
        "spark-submit",
        "--master", "yarn",
        "--deploy-mode", "client",
        "--class", environ["TBV_CLASS"],
        artifact_file,
    ] + [v for opt in opts for v in opt if v]

    call_exit_errors(command) 
开发者ID:mozilla,项目名称:telemetry-airflow,代码行数:18,代码来源:telemetry_batch_view.py

示例2: cleanup

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def cleanup(self):
        """ Removes temporary file. """
        from os.path import exists
        from os import remove
        # return nodes to parent.
        parent = None if self.parent is None else self.parent()
        if parent is not None:
            for key, value in self.machines.items():
                if key in parent.machines:
                    parent.machines[key] += value
                else:
                    parent.machines[key] = value
            parent['n'] += self['n']
            self.parent = None
            self.machines = {}
            self['n'] = 0
        # remove nodefile, if it exists.
        nodefile, self._nodefile = self._nodefile, None
        if nodefile is not None and exists(nodefile):
            try:
                remove(nodefile)
            except:
                pass 
开发者ID:pylada,项目名称:pylada-light,代码行数:25,代码来源:mpi.py

示例3: _preload_existing_vars

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def _preload_existing_vars(prefix: str) -> Store:
    """Preloads env vars from environ with the given prefix."""
    if not prefix:
        # If prefix is empty just return all the env variables.
        return environ

    prefixed = {}

    # Prefix is not empty, do the search and replacement:
    for env_name, env_value in environ.items():
        if not env_name.startswith(prefix):
            # Skip vars with no prefix.
            continue

        prefixed[env_name.replace(prefix, '', 1)] = env_value

    return prefixed 
开发者ID:sobolevn,项目名称:dump-env,代码行数:19,代码来源:dumper.py

示例4: compare_generic_iter

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def compare_generic_iter(make_it,match):
    """Utility to compare a generic 2.1/2.2+ iterator with an iterable

    If running under Python 2.2+, this tests the iterator using iter()/next(),
    as well as __getitem__.  'make_it' must be a function returning a fresh
    iterator to be tested (since this may test the iterator twice)."""

    it = make_it()
    n = 0
    for item in match:
        if not it[n]==item: raise AssertionError
        n+=1
    try:
        it[n]
    except IndexError:
        pass
    else:
        raise AssertionError("Too many items from __getitem__",it)

    try:
        iter, StopIteration
    except NameError:
        pass
    else:
        # Only test iter mode under 2.2+
        it = make_it()
        if not iter(it) is it: raise AssertionError
        for item in match:
            if not it.next()==item: raise AssertionError
        try:
            it.next()
        except StopIteration:
            pass
        else:
            raise AssertionError("Too many items from .next()",it) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:37,代码来源:test_wsgiref.py

示例5: testMappingInterface

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def testMappingInterface(self):
        test = [('x','y')]
        self.assertEqual(len(Headers([])),0)
        self.assertEqual(len(Headers(test[:])),1)
        self.assertEqual(Headers(test[:]).keys(), ['x'])
        self.assertEqual(Headers(test[:]).values(), ['y'])
        self.assertEqual(Headers(test[:]).items(), test)
        self.assertFalse(Headers(test).items() is test)  # must be copy!

        h=Headers([])
        del h['foo']   # should not raise an error

        h['Foo'] = 'bar'
        for m in h.has_key, h.__contains__, h.get, h.get_all, h.__getitem__:
            self.assertTrue(m('foo'))
            self.assertTrue(m('Foo'))
            self.assertTrue(m('FOO'))
            self.assertFalse(m('bar'))

        self.assertEqual(h['foo'],'bar')
        h['foo'] = 'baz'
        self.assertEqual(h['FOO'],'baz')
        self.assertEqual(h.get_all('foo'),['baz'])

        self.assertEqual(h.get("foo","whee"), "baz")
        self.assertEqual(h.get("zoo","whee"), "whee")
        self.assertEqual(h.setdefault("foo","whee"), "baz")
        self.assertEqual(h.setdefault("zoo","whee"), "whee")
        self.assertEqual(h["foo"],"baz")
        self.assertEqual(h["zoo"],"whee") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:32,代码来源:test_wsgiref.py

示例6: checkOSEnviron

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def checkOSEnviron(self,handler):
        empty = {}; setup_testing_defaults(empty)
        env = handler.environ
        from os import environ
        for k,v in environ.items():
            if k not in empty:
                self.assertEqual(env[k],v)
        for k,v in empty.items():
            self.assertIn(k, env) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:11,代码来源:test_wsgiref.py

示例7: testMappingInterface

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def testMappingInterface(self):
        test = [('x','y')]
        self.assertEqual(len(Headers([])),0)
        self.assertEqual(len(Headers(test[:])),1)
        self.assertEqual(Headers(test[:]).keys(), ['x'])
        self.assertEqual(Headers(test[:]).values(), ['y'])
        self.assertEqual(Headers(test[:]).items(), test)
        self.assertIsNot(Headers(test).items(), test)  # must be copy!

        h=Headers([])
        del h['foo']   # should not raise an error

        h['Foo'] = 'bar'
        for m in h.has_key, h.__contains__, h.get, h.get_all, h.__getitem__:
            self.assertTrue(m('foo'))
            self.assertTrue(m('Foo'))
            self.assertTrue(m('FOO'))
            self.assertFalse(m('bar'))

        self.assertEqual(h['foo'],'bar')
        h['foo'] = 'baz'
        self.assertEqual(h['FOO'],'baz')
        self.assertEqual(h.get_all('foo'),['baz'])

        self.assertEqual(h.get("foo","whee"), "baz")
        self.assertEqual(h.get("zoo","whee"), "whee")
        self.assertEqual(h.setdefault("foo","whee"), "baz")
        self.assertEqual(h.setdefault("zoo","whee"), "whee")
        self.assertEqual(h["foo"],"baz")
        self.assertEqual(h["zoo"],"whee") 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:32,代码来源:test_wsgiref.py

示例8: do_GET

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def do_GET(s):
        s.send_response(200)
        s.send_header("content-type", "text/json")
        s.end_headers()
        s.wfile.write(dumps(environ.items()))
        s.wfile.close() 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:8,代码来源:envhttp.py

示例9: compare_generic_iter

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def compare_generic_iter(make_it,match):
    """Utility to compare a generic 2.1/2.2+ iterator with an iterable

    If running under Python 2.2+, this tests the iterator using iter()/next(),
    as well as __getitem__.  'make_it' must be a function returning a fresh
    iterator to be tested (since this may test the iterator twice)."""

    it = make_it()
    n = 0
    for item in match:
        if not it[n]==item: raise AssertionError
        n+=1
    try:
        it[n]
    except IndexError:
        pass
    else:
        raise AssertionError("Too many items from __getitem__",it)

    try:
        iter, StopIteration
    except NameError:
        pass
    else:
        # Only test iter mode under 2.2+
        it = make_it()
        if not iter(it) is it: raise AssertionError
        for item in match:
            if not next(it) == item: raise AssertionError
        try:
            next(it)
        except StopIteration:
            pass
        else:
            raise AssertionError("Too many items from .__next__()", it) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:37,代码来源:test_wsgiref.py

示例10: testMappingInterface

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def testMappingInterface(self):
        test = [('x','y')]
        self.assertEqual(len(Headers()), 0)
        self.assertEqual(len(Headers([])),0)
        self.assertEqual(len(Headers(test[:])),1)
        self.assertEqual(Headers(test[:]).keys(), ['x'])
        self.assertEqual(Headers(test[:]).values(), ['y'])
        self.assertEqual(Headers(test[:]).items(), test)
        self.assertIsNot(Headers(test).items(), test)  # must be copy!

        h = Headers()
        del h['foo']   # should not raise an error

        h['Foo'] = 'bar'
        for m in h.__contains__, h.get, h.get_all, h.__getitem__:
            self.assertTrue(m('foo'))
            self.assertTrue(m('Foo'))
            self.assertTrue(m('FOO'))
            self.assertFalse(m('bar'))

        self.assertEqual(h['foo'],'bar')
        h['foo'] = 'baz'
        self.assertEqual(h['FOO'],'baz')
        self.assertEqual(h.get_all('foo'),['baz'])

        self.assertEqual(h.get("foo","whee"), "baz")
        self.assertEqual(h.get("zoo","whee"), "whee")
        self.assertEqual(h.setdefault("foo","whee"), "baz")
        self.assertEqual(h.setdefault("zoo","whee"), "whee")
        self.assertEqual(h["foo"],"baz")
        self.assertEqual(h["zoo"],"whee") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:33,代码来源:test_wsgiref.py

示例11: testMappingInterface

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def testMappingInterface(self):
        test = [('x','y')]
        self.assertEqual(len(Headers([])),0)
        self.assertEqual(len(Headers(test[:])),1)
        self.assertEqual(Headers(test[:]).keys(), ['x'])
        self.assertEqual(Headers(test[:]).values(), ['y'])
        self.assertEqual(Headers(test[:]).items(), test)
        self.assertIsNot(Headers(test).items(), test)  # must be copy!

        h=Headers([])
        del h['foo']   # should not raise an error

        h['Foo'] = 'bar'
        for m in h.__contains__, h.get, h.get_all, h.__getitem__:
            self.assertTrue(m('foo'))
            self.assertTrue(m('Foo'))
            self.assertTrue(m('FOO'))
            self.assertFalse(m('bar'))

        self.assertEqual(h['foo'],'bar')
        h['foo'] = 'baz'
        self.assertEqual(h['FOO'],'baz')
        self.assertEqual(h.get_all('foo'),['baz'])

        self.assertEqual(h.get("foo","whee"), "baz")
        self.assertEqual(h.get("zoo","whee"), "whee")
        self.assertEqual(h.setdefault("foo","whee"), "baz")
        self.assertEqual(h.setdefault("zoo","whee"), "whee")
        self.assertEqual(h["foo"],"baz")
        self.assertEqual(h["zoo"],"whee") 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:32,代码来源:test_wsgiref.py

示例12: __new__

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def __new__(cls) -> "Configuration":
        if cls._instance is not None:
            instance = cls._instance
        else:

            instance = super().__new__(cls)
            for key, value_str in environ.items():

                match = fullmatch(
                    r"OPENTELEMETRY_PYTHON_([A-Za-z_][\w_]*)", key
                )

                if match is not None:

                    key = match.group(1)
                    value = value_str  # type: ConfigValue

                    if value_str == "True":
                        value = True
                    elif value_str == "False":
                        value = False
                    else:
                        try:
                            value = int(value_str)
                        except ValueError:
                            pass
                        try:
                            value = float(value_str)
                        except ValueError:
                            pass

                    instance._config_map[key] = value

            cls._instance = instance

        return instance 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:38,代码来源:__init__.py

示例13: _msvc14_get_vc_env

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def _msvc14_get_vc_env(plat_spec):
    """Python 3.8 "distutils/_msvccompiler.py" backport"""
    if "DISTUTILS_USE_SDK" in environ:
        return {
            key.lower(): value
            for key, value in environ.items()
        }

    vcvarsall, vcruntime = _msvc14_find_vcvarsall(plat_spec)
    if not vcvarsall:
        raise distutils.errors.DistutilsPlatformError(
            "Unable to find vcvarsall.bat"
        )

    try:
        out = subprocess.check_output(
            'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
            stderr=subprocess.STDOUT,
        ).decode('utf-16le', errors='replace')
    except subprocess.CalledProcessError as exc:
        raise distutils.errors.DistutilsPlatformError(
            "Error executing {}".format(exc.cmd)
        ) from exc

    env = {
        key.lower(): value
        for key, _, value in
        (line.partition('=') for line in out.splitlines())
        if key and value
    }

    if vcruntime:
        env['py_vcruntime_redist'] = vcruntime
    return env 
开发者ID:pypa,项目名称:setuptools,代码行数:36,代码来源:msvc.py

示例14: acquire

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def acquire(self, other, n=None):
        """ Acquires the processes from another communicator.

            Use at your risk... Family lines could become tangled, eg to which
            communicator will the processes return when self is destroyed? In
            practice, it will return to the parent of self. Is that what you want?

            The processes in other are acquired by self. If n is not None, only n
            processes are acquired, up to the maximum number of processes in other.
            If n is None, then all processes are acquired.

            As always, processes are exclusive owned exclusively. Processes
            acquired by self are no longuer in other.
        """
        if self._nodefile is not None or other._nodefile is not None:
            raise NodeFileExists("Comm already used in other process.")
        if n is not None:
            comm = other.lend(n)
            self.acquire(comm)
            return
        for key, value in other.machines.items():
            if key in self.machines:
                self.machines[key] += value
            else:
                self.machines[key] = value
        self['n'] += other['n']
        other.machines = {}
        other['n'] = 0
        other.parent = None
        other.cleanup() 
开发者ID:pylada,项目名称:pylada-light,代码行数:32,代码来源:mpi.py

示例15: nodefile

# 需要导入模块: from os import environ [as 别名]
# 或者: from os.environ import items [as 别名]
def nodefile(self, dir=None):
        """ Returns name of temporary nodefile.

            This file should be cleaned up once the mpi process is finished by
            calling :py:meth:`~Communicator.cleanup`. It is an error to call this
            function without first cleaning up.  Since only one mpi process should
            be attached to a communicator, this makes sense.
        """
        from tempfile import NamedTemporaryFile
        from ..misc import RelativePath
        from ..process import logger

        if self._nodefile is not None:
            logger.debug('process/mpi.py: old nodefile: %s' % self._nodefile)
            raise NodeFileExists("Please call cleanup first.  nodefile: \"%s\""
                                 % (self._nodefile, ))
        if self['n'] == 0:
            raise MPISizeError("No processes in this communicator.")

        with NamedTemporaryFile(
                dir=RelativePath(dir).path, delete=False,
                prefix='pylada_comm') as file:
            logger.debug('process/mpi.py: new nodefile: %s' % file.name)
            for machine, slots in self.machines.items():
                if slots == 0:
                    continue
                ##file.write('{0} slots={1}\n'.format(machine, slots))
                file.write(machine)
                file.write('\n')
                logger.debug('machine: %s  slots: %s' % (machine, slots))

            self._nodefile = file.name
        return self._nodefile 
开发者ID:pylada,项目名称:pylada-light,代码行数:35,代码来源:mpi.py


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