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


Python twisted.python方法代码示例

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


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

示例1: ensure_outgoing_proxy_dependencies

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def ensure_outgoing_proxy_dependencies():
    """Make sure that we have the necessary dependencies to connect to
    outgoing HTTP/SOCKS proxies.

    Raises OutgoingProxyDepsFailure in case of error.
    """

    # We can't connect to outgoing proxies without txsocksx.
    try:
        import txsocksx
    except ImportError:
        raise OutgoingProxyDepsFailure("We don't have txsocksx. Can't do proxy. Please install txsocksx.")

    # We also need a recent version of twisted ( >= twisted-13.2.0)
    import twisted
    from twisted.python import versions
    if twisted.version < versions.Version('twisted', 13, 2, 0):
        raise OutgoingProxyDepsFailure("Outdated version of twisted (%s). Please upgrade to >= twisted-13.2.0" % twisted.version.short()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:network.py

示例2: spewer

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def spewer(frame, s, ignored):
    """
    A trace function for sys.settrace that prints every function or method call.
    """
    from twisted.python import reflect
    if 'self' in frame.f_locals:
        se = frame.f_locals['self']
        if hasattr(se, '__class__'):
            k = reflect.qual(se.__class__)
        else:
            k = reflect.qual(type(se))
        print('method %s of %s at %s' % (
                frame.f_code.co_name, k, id(se)))
    else:
        print('function %s in %s, line %s' % (
                frame.f_code.co_name,
                frame.f_code.co_filename,
                frame.f_lineno)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:util.py

示例3: test_loadPackagesAndModules

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_loadPackagesAndModules(self):
        """
        Verify that we can locate and load packages, modules, submodules, and
        subpackages.
        """
        for n in ['os',
                  'twisted',
                  'twisted.python',
                  'twisted.python.reflect']:
            m = namedAny(n)
            self.failUnlessIdentical(
                modules.getModule(n).load(),
                m)
            self.failUnlessIdentical(
                self.findByIteration(n).load(),
                m) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_modules.py

示例4: spewer

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def spewer(frame, s, ignored):
    """A trace function for sys.settrace that prints every function or method call."""
    from twisted.python import reflect
    if frame.f_locals.has_key('self'):
        se = frame.f_locals['self']
        if hasattr(se, '__class__'):
            k = reflect.qual(se.__class__)
        else:
            k = reflect.qual(type(se))
        print 'method %s of %s at %s' % (
            frame.f_code.co_name, k, id(se)
        )
    else:
        print 'function %s in %s, line %s' % (
            frame.f_code.co_name,
            frame.f_code.co_filename,
            frame.f_lineno) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,代码来源:util.py

示例5: _setgroups_until_success

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def _setgroups_until_success(l):
        while(1):
            # NASTY NASTY HACK (but glibc does it so it must be okay):
            # In case sysconfig didn't give the right answer, find the limit
            # on max groups by just looping, trying to set fewer and fewer
            # groups each time until it succeeds.
            try:
                setgroups(l)
            except ValueError:
                # This exception comes from python itself restricting
                # number of groups allowed.
                if len(l) > 1:
                    del l[-1]
                else:
                    raise
            except OSError, e:
                if e.errno == errno.EINVAL and len(l) > 1:
                    # This comes from the OS saying too many groups
                    del l[-1]
                else:
                    raise
            else:
                # Success, yay!
                return 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:util.py

示例6: test_attributeExceptions

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_attributeExceptions(self):
        """
        If segments on the end of a fully-qualified Python name represents
        attributes which aren't actually present on the object represented by
        the earlier segments, L{namedAny} should raise an L{AttributeError}.
        """
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.nosuchmoduleintheworld")
        # ImportError behaves somewhat differently between "import
        # extant.nonextant" and "import extant.nonextant.nonextant", so test
        # the latter as well.
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.nosuch.modulein.theworld")
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.python.reflect.Summer.nosuchattributeintheworld") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_reflect.py

示例7: doWarnings

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def doWarnings():
    import twisted
    from twisted.python import versions
    if (twisted.version < versions.Version('twisted', 8, 0, 0)):
        LOG.warning("You should get Twisted 8 or later.  Previous versions "
                    "have some bugs that affect Dtella.")

    try:
        import dtella.bridge
    except ImportError:
        # Don't warn about GMP for clients, because verifying a signature
        # is fast enough without it (~1ms on a Core2)
        pass
    else:
        import Crypto.PublicKey
        try:
            import Crypto.PublicKey._fastmath
        except ImportError:
            LOG.warning("Your version of PyCrypto was compiled without "
                        "GMP (fastmath).  Signing messages will be slower.") 
开发者ID:ffledgling,项目名称:dtella,代码行数:22,代码来源:core.py

示例8: getPluginDirs

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def getPluginDirs():
    warnings.warn(
        "twisted.python.util.getPluginDirs is deprecated since Twisted 12.2.",
        DeprecationWarning, stacklevel=2)
    import twisted
    systemPlugins = os.path.join(os.path.dirname(os.path.dirname(
                            os.path.abspath(twisted.__file__))), 'plugins')
    userPlugins = os.path.expanduser("~/TwistedPlugins")
    confPlugins = os.path.expanduser("~/.twisted")
    allPlugins = filter(os.path.isdir, [systemPlugins, userPlugins, confPlugins])
    return allPlugins 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:util.py

示例9: addPluginDir

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def addPluginDir():
    warnings.warn(
        "twisted.python.util.addPluginDir is deprecated since Twisted 12.2.",
        DeprecationWarning, stacklevel=2)
    sys.path.extend(getPluginDirs()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:util.py

示例10: test_extrasRequiresDevDeps

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_extrasRequiresDevDeps(self):
        """
        L{_EXTRAS_REQUIRE}'s C{dev} extra contains setuptools requirements for
        the tools required for Twisted development.
        """
        deps = _EXTRAS_REQUIRE['dev']
        self.assertIn('pyflakes >= 1.0.0', deps)
        self.assertIn('twisted-dev-tools >= 0.0.2', deps)
        self.assertIn('python-subunit', deps)
        self.assertIn('sphinx >= 1.3.1', deps)
        if not _PY3:
            self.assertIn('twistedchecker >= 0.4.0', deps)
            self.assertIn('pydoctor >= 16.2.0', deps) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_setup.py

示例11: test_namedModuleLookup

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_namedModuleLookup(self):
        """
        L{namedModule} should return the module object for the name it is
        passed.
        """
        from twisted.python import monkey
        self.assertIs(
            reflect.namedModule("twisted.python.monkey"), monkey) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_reflect.py

示例12: test_namedAnyPackageLookup

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_namedAnyPackageLookup(self):
        """
        L{namedAny} should return the package object for the name it is passed.
        """
        import twisted.python
        self.assertIs(
            reflect.namedAny("twisted.python"), twisted.python) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_reflect.py

示例13: test_namedAnyModuleLookup

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_namedAnyModuleLookup(self):
        """
        L{namedAny} should return the module object for the name it is passed.
        """
        from twisted.python import monkey
        self.assertIs(
            reflect.namedAny("twisted.python.monkey"), monkey) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_reflect.py

示例14: test_invalidNames

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_invalidNames(self):
        """
        Passing a name which isn't a fully-qualified Python name to L{namedAny}
        should result in one of the following exceptions:
         - L{InvalidName}: the name is not a dot-separated list of Python
           objects
         - L{ObjectNotFound}: the object doesn't exist
         - L{ModuleNotFound}: the object doesn't exist and there is only one
           component in the name
        """
        err = self.assertRaises(reflect.ModuleNotFound, reflect.namedAny,
                                'nosuchmoduleintheworld')
        self.assertEqual(str(err), "No module named 'nosuchmoduleintheworld'")

        # This is a dot-separated list, but it isn't valid!
        err = self.assertRaises(reflect.ObjectNotFound, reflect.namedAny,
                                "@#$@(#.!@(#!@#")
        self.assertEqual(str(err), "'@#$@(#.!@(#!@#' does not name an object")

        err = self.assertRaises(reflect.ObjectNotFound, reflect.namedAny,
                                "tcelfer.nohtyp.detsiwt")
        self.assertEqual(
            str(err),
            "'tcelfer.nohtyp.detsiwt' does not name an object")

        err = self.assertRaises(reflect.InvalidName, reflect.namedAny, '')
        self.assertEqual(str(err), 'Empty module name')

        for invalidName in ['.twisted', 'twisted.', 'twisted..python']:
            err = self.assertRaises(
                reflect.InvalidName, reflect.namedAny, invalidName)
            self.assertEqual(
                str(err),
                "name must be a string giving a '.'-separated list of Python "
                "identifiers, not %r" % (invalidName,)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:37,代码来源:test_reflect.py

示例15: test_requireModuleRequestedImport

# 需要导入模块: import twisted [as 别名]
# 或者: from twisted import python [as 别名]
def test_requireModuleRequestedImport(self):
        """
        When module import succeed it returns the module and not the default
        value.
        """
        from twisted.python import monkey
        default = object()

        self.assertIs(
            reflect.requireModule('twisted.python.monkey', default=default),
            monkey,
            ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_reflect.py


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