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


Python builtins.__name__方法代码示例

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


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

示例1: inspect_build

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def inspect_build(self, module, modname=None, path=None):
        """build astroid from a living module (i.e. using inspect)
        this is used when there is no python source code available (either
        because it's a built-in module or because the .py is not available)
        """
        self._module = module
        if modname is None:
            modname = module.__name__
        try:
            node = build_module(modname, module.__doc__)
        except AttributeError:
            # in jython, java modules have no __doc__ (see #109562)
            node = build_module(modname)
        node.file = node.path = os.path.abspath(path) if path else path
        node.name = modname
        MANAGER.cache_module(node)
        node.package = hasattr(module, "__path__")
        self._done = {}
        self.object_build(node, module)
        return node 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:22,代码来源:raw_building.py

示例2: __str__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def __str__(self):
        rname = self._repr_name()
        cname = type(self).__name__
        if rname:
            string = "%(cname)s.%(rname)s(%(fields)s)"
            alignment = len(cname) + len(rname) + 2
        else:
            string = "%(cname)s(%(fields)s)"
            alignment = len(cname) + 1
        result = []
        for field in self._other_fields + self._astroid_fields:
            value = getattr(self, field)
            width = 80 - len(field) - alignment
            lines = pprint.pformat(value, indent=2, width=width).splitlines(True)

            inner = [lines[0]]
            for line in lines[1:]:
                inner.append(" " * alignment + line)
            result.append("%s=%s" % (field, "".join(inner)))

        return string % {
            "cname": cname,
            "rname": rname,
            "fields": (",\n" + " " * alignment).join(result),
        } 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:27,代码来源:node_classes.py

示例3: igetattr

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def igetattr(self, name, context=None):
        """inferred getattr"""
        if not context:
            context = contextmod.InferenceContext()
        try:
            # avoid recursively inferring the same attr on the same class
            if context.push((self._proxied, name)):
                return

            # XXX frame should be self._proxied, or not ?
            get_attr = self.getattr(name, context, lookupclass=False)
            yield from _infer_stmts(
                self._wrap_attr(get_attr, context), context, frame=self
            )
        except exceptions.AttributeInferenceError as error:
            try:
                # fallback to class.igetattr since it has some logic to handle
                # descriptors
                # But only if the _proxied is the Class.
                if self._proxied.__class__.__name__ != "ClassDef":
                    raise exceptions.InferenceError(**vars(error)) from error
                attrs = self._proxied.igetattr(name, context, class_context=False)
                yield from self._wrap_attr(attrs, context)
            except exceptions.AttributeInferenceError as error:
                raise exceptions.InferenceError(**vars(error)) from error 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:27,代码来源:bases.py

示例4: visit_tuple

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def visit_tuple(self, tuple_node):
        if PY3K or not tuple_node.elts:
            self._checker.add_message("raising-bad-type", node=self._node, args="tuple")
            return

        # On Python 2, using the following is not an error:
        #    raise (ZeroDivisionError, None)
        #    raise (ZeroDivisionError, )
        # What's left to do is to check that the first
        # argument is indeed an exception. Verifying the other arguments
        # is not the scope of this check.
        first = tuple_node.elts[0]
        inferred = utils.safe_infer(first)
        if not inferred or inferred is astroid.Uninferable:
            return

        if (
            isinstance(inferred, astroid.Instance)
            and inferred.__class__.__name__ != "Instance"
        ):
            # TODO: explain why
            self.visit_default(tuple_node)
        else:
            self.visit(inferred) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:26,代码来源:exceptions.py

示例5: serialize

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def serialize(self):
        if getattr(self.value, "__self__", None) and isinstance(self.value.__self__, type):
            klass = self.value.__self__
            module = klass.__module__
            return "%s.%s.%s" % (module, klass.__name__, self.value.__name__), {"import %s" % module}
        # Further error checking
        if self.value.__name__ == '<lambda>':
            raise ValueError("Cannot serialize function: lambda")
        if self.value.__module__ is None:
            raise ValueError("Cannot serialize function %r: No module" % self.value)

        module_name = self.value.__module__

        if '<' not in self.value.__qualname__:  # Qualname can include <locals>
            return '%s.%s' % (module_name, self.value.__qualname__), {'import %s' % self.value.__module__}

        raise ValueError(
            'Could not find function %s in %s.\n' % (self.value.__name__, module_name)
        ) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:21,代码来源:serializer.py

示例6: test_access_zipped_assets

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def test_access_zipped_assets(
    mock_resource_string,
    mock_resource_isdir,
    mock_resource_listdir,
    mock_safe_mkdir,
    mock_safe_mkdtemp):

  mock_open = mock.mock_open()
  mock_safe_mkdtemp.side_effect = iter(['tmpJIMMEH', 'faketmpDir'])
  mock_resource_listdir.side_effect = iter([['./__init__.py', './directory/'], ['file.py']])
  mock_resource_isdir.side_effect = iter([False, True, False])
  mock_resource_string.return_value = 'testing'

  with mock.patch('%s.open' % python_builtins.__name__, mock_open, create=True):
    temp_dir = DistributionHelper.access_zipped_assets('twitter.common', 'dirutil')
    assert mock_resource_listdir.call_count == 2
    assert mock_open.call_count == 2
    file_handle = mock_open.return_value.__enter__.return_value
    assert file_handle.write.call_count == 2
    assert mock_safe_mkdtemp.mock_calls == [mock.call()]
    assert temp_dir == 'tmpJIMMEH'
    assert mock_safe_mkdir.mock_calls == [mock.call(os.path.join('tmpJIMMEH', 'directory'))] 
开发者ID:pantsbuild,项目名称:pex,代码行数:24,代码来源:test_util.py

示例7: _astroid_bootstrapping

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def _astroid_bootstrapping(astroid_builtin=None):
    """astroid boot strapping the builtins module"""
    # this boot strapping is necessary since we need the Const nodes to
    # inspect_build builtins, and then we can proxy Const
    if astroid_builtin is None:
        astroid_builtin = Astroid_BUILDER.inspect_build(builtins)

    # pylint: disable=redefined-outer-name
    for cls, node_cls in node_classes.CONST_CLS.items():
        if cls is type(None):
            proxy = build_class("NoneType")
            proxy.parent = astroid_builtin
        elif cls is type(NotImplemented):
            proxy = build_class("NotImplementedType")
            proxy.parent = astroid_builtin
        else:
            proxy = astroid_builtin.getattr(cls.__name__)[0]
        if cls in (dict, list, set, tuple):
            node_cls._proxied = proxy
        else:
            _CONST_PROXY[cls] = proxy 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:23,代码来源:raw_building.py

示例8: _is_property

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def _is_property(meth):
    if PROPERTIES.intersection(meth.decoratornames()):
        return True
    stripped = {
        name.split(".")[-1]
        for name in meth.decoratornames()
        if name is not util.Uninferable
    }
    if any(name in stripped for name in POSSIBLE_PROPERTIES):
        return True

    # Lookup for subclasses of *property*
    if not meth.decorators:
        return False
    for decorator in meth.decorators.nodes or ():
        inferred = helpers.safe_infer(decorator)
        if inferred is None or inferred is util.Uninferable:
            continue
        if inferred.__class__.__name__ == "ClassDef":
            for base_class in inferred.bases:
                module, _ = base_class.lookup(base_class.name)
                if module.name == BUILTINS and base_class.name == "property":
                    return True

    return False 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:27,代码来源:bases.py

示例9: __repr__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def __repr__(self):
        result = []
        cname = type(self).__name__
        string = "%(cname)s(%(fields)s)"
        alignment = len(cname) + 1
        for field in sorted(self.attributes()):
            width = 80 - len(field) - alignment
            lines = pprint.pformat(field, indent=2, width=width).splitlines(True)

            inner = [lines[0]]
            for line in lines[1:]:
                inner.append(" " * alignment + line)
            result.append(field)

        return string % {
            "cname": cname,
            "fields": (",\n" + " " * alignment).join(result),
        } 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:20,代码来源:objectmodel.py

示例10: __new__

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def __new__(cls, *args, **kwargs):
        # Append the values from the AGeneratorType unto this object.
        ret = super().__new__(cls, *args, **kwargs)
        astroid_builtins = astroid.MANAGER.astroid_cache[builtins.__name__]
        generator = astroid_builtins.get("async_generator")
        if generator is None:
            # Make it backward compatible.
            generator = astroid_builtins.get("generator")

        for name, values in generator.locals.items():
            method = values[0]
            patched = lambda cls, meth=method: meth

            setattr(type(ret), "py" + name, property(patched))

        return ret 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:18,代码来源:objectmodel.py

示例11: _get_exception_class

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def _get_exception_class(cls):
    if cls in _exception_classes_cache:
        return _exception_classes_cache[cls]

    # subclass the exception class' to provide a version of __str__ that supports _remote_tb
    class Derived(cls):
        def __str__(self):
            try:
                text = cls.__str__(self)
            except Exception:
                text = "<Unprintable exception>"
            if hasattr(self, "_remote_tb"):
                text += "\n\n========= Remote Traceback (%d) =========\n%s" % (
                    self._remote_tb.count("\n\n========= Remote Traceback") + 1, self._remote_tb)
            return text
        def __repr__(self):
            return str(self)
    
    Derived.__name__ = cls.__name__
    Derived.__module__ = cls.__module__
    _exception_classes_cache[cls] = Derived
    return Derived 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:24,代码来源:vinegar.py

示例12: patch_critical_objects

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def patch_critical_objects(stdout='', stderr='', return_code=0, flags=FLAGS):
  with contextlib2.ExitStack() as stack:
    retval = (stdout, stderr, return_code)

    flags.gcloud_path = 'gcloud'
    flags.run_uri = _RUN_URI
    flags.kubectl = _KUBECTL
    flags.kubeconfig = _KUBECONFIG

    stack.enter_context(mock.patch(builtins.__name__ + '.open'))
    stack.enter_context(mock.patch(vm_util.__name__ + '.PrependTempDir'))

    # Save and return the temp_file mock here so that we can access the write()
    # call on the instance that the mock returned. This allows us to verify
    # that the body of the file is what we expect it to be (useful for
    # verifying that the pod.yml body was written correctly).
    temp_file = stack.enter_context(
        mock.patch(vm_util.__name__ + '.NamedTemporaryFile'))

    issue_command = stack.enter_context(
        mock.patch(vm_util.__name__ + '.IssueCommand', return_value=retval))

    yield issue_command, temp_file 
开发者ID:GoogleCloudPlatform,项目名称:PerfKitBenchmarker,代码行数:25,代码来源:kubernetes_virtual_machine_test.py

示例13: PatchCriticalObjects

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def PatchCriticalObjects(retvals=None):
  """A context manager that patches a few critical objects with mocks."""

  def ReturnVal(*unused_arg, **unused_kwargs):
    del unused_arg
    del unused_kwargs
    return ('', '', 0) if retvals is None else retvals.pop(0)

  with mock.patch(
      vm_util.__name__ + '.IssueCommand',
      side_effect=ReturnVal) as issue_command, mock.patch(
          builtins.__name__ + '.open'), mock.patch(
              vm_util.__name__ +
              '.NamedTemporaryFile'), mock.patch(util.__name__ +
                                                 '.GetDefaultProject'):
    yield issue_command 
开发者ID:GoogleCloudPlatform,项目名称:PerfKitBenchmarker,代码行数:18,代码来源:gce_virtual_machine_test.py

示例14: qname

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def qname(self):
        return self.__class__.__name__


# TODO: Hack to solve the circular import problem between node_classes and objects
# This is not needed in 2.0, which has a cleaner design overall 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:8,代码来源:objects.py

示例15: _io_discrepancy

# 需要导入模块: import builtins [as 别名]
# 或者: from builtins import __name__ [as 别名]
def _io_discrepancy(member):
    # _io module names itself `io`: http://bugs.python.org/issue18602
    member_self = getattr(member, "__self__", None)
    return (
        member_self
        and inspect.ismodule(member_self)
        and member_self.__name__ == "_io"
        and member.__module__ == "io"
    ) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:11,代码来源:raw_building.py


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