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


Python types.BuiltinMethodType方法代码示例

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


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

示例1: fileopen

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def fileopen(self, file):
        import types
        if repr(type(file)) != "<type 'file'>":
            raise TypeError, 'posixfile.fileopen() arg must be file object'
        self._file_  = file
        # Copy basic file methods
        for maybemethod in dir(file):
            if not maybemethod.startswith('_'):
                attr = getattr(file, maybemethod)
                if isinstance(attr, types.BuiltinMethodType):
                    setattr(self, maybemethod, attr)
        return self

    #
    # New methods
    # 
开发者ID:glmcdona,项目名称:meddle,代码行数:18,代码来源:posixfile.py

示例2: short_repr

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def short_repr(obj):
    if isinstance(obj, (type, types.ModuleType, types.BuiltinMethodType,
                        types.BuiltinFunctionType)):
        return obj.__name__
    if isinstance(obj, types.MethodType):
        try:
            if obj.__self__ is not None:
                return obj.__func__.__name__ + ' (bound)'
            else:
                return obj.__func__.__name__
        except AttributeError:
            # Python < 2.6 compatibility
            if obj.im_self is not None:
                return obj.im_func.__name__ + ' (bound)'
            else:
                return obj.im_func.__name__

    if isinstance(obj, types.FrameType):
        return '%s:%s' % (obj.f_code.co_filename, obj.f_lineno)
    if isinstance(obj, (tuple, list, dict, set)):
        return '%d items' % len(obj)
    return repr(obj)[:40] 
开发者ID:Exa-Networks,项目名称:exaddos,代码行数:24,代码来源:objgraph.py

示例3: __new__

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def __new__(cls, name, bases, attrs):
        if '__tainted__' in attrs:
            raise AttributeError("__taint__ attribute is a special method for Taint metaclass")
        if '__tainttags__' in attrs:
            raise AttributeError("__tainttags__ attribute is a special method for Taint metaclass")
        def taint_dec(func):
            def _taint_dec(*args, **kwds):
                tainted = 0
                tags = []
                for arg in args:
                    tainted = tainted or getattr(arg, '__tainted__', 0)
                    tags.extend(getattr(arg, '__tainttags__', ()))
                for arg in kwds.itervalues():
                    tainted = tainted or getattr(arg, '__tainted__', 0)
                    tags.extend(getattr(arg, '__tainttags__', ()))
                res = func(*args, **kwds)
                res.__tainted__ = tainted
                res.__tags__ = tags
                return res
            return _taint_dec
        newattrs = {key: (taint_dec(val) if isinstance(val, (types.BuiltinMethodType, types.MethodType, types.FunctionType)) else val)
                    for key, val in attrs.iteritems()}
        newattrs['__tainted__'] = 0
        newattrs['__tainttags__'] = []
        return super(Taint, cls).__new__(cls, name, bases, attrs) 
开发者ID:ebranca,项目名称:owasp-pysec,代码行数:27,代码来源:taint.py

示例4: _compute_fields_for_operation

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def _compute_fields_for_operation(self, fields, to_compute):
        row = OpRow(self)
        for name, tup in iteritems(fields):
            field, value = tup
            if isinstance(
                value,
                (
                    types.LambdaType,
                    types.FunctionType,
                    types.MethodType,
                    types.BuiltinFunctionType,
                    types.BuiltinMethodType,
                ),
            ):
                value = value()
            row.set_value(name, value, field)
        for name, field in to_compute:
            try:
                row.set_value(name, field.compute(row), field)
            except (KeyError, AttributeError):
                # error silently unless field is required!
                if field.required and name not in fields:
                    raise RuntimeError("unable to compute required field: %s" % name)
        return row 
开发者ID:web2py,项目名称:pydal,代码行数:26,代码来源:objects.py

示例5: safe_pickle

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def safe_pickle(the_object):
    if type(the_object) is list:
        return [safe_pickle(x) for x in the_object]
    if type(the_object) is dict:
        new_dict = dict()
        for key, value in the_object.items():
            new_dict[key] = safe_pickle(value)
        return new_dict
    if type(the_object) is set:
        new_set = set()
        for sub_object in the_object:
            new_set.add(safe_pickle(sub_object))
        return new_set
    if type(the_object) in [types.ModuleType, types.FunctionType, TypeType, types.BuiltinFunctionType, types.BuiltinMethodType, types.MethodType, types.ClassType, FileType]:
        return None
    return the_object 
开发者ID:jhpyle,项目名称:docassemble,代码行数:18,代码来源:backend.py

示例6: short_repr

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def short_repr(obj):
    if isinstance(obj, (type, types.ModuleType, types.BuiltinMethodType,
                        types.BuiltinFunctionType)):
        return obj.__name__
    if isinstance(obj, types.MethodType):
        if obj.im_self is not None:
            return obj.im_func.__name__ + ' (bound)'
        else:
            return obj.im_func.__name__
    if isinstance(obj, (tuple, list, dict, set)):
        return '%d items' % len(obj)
    if isinstance(obj, weakref.ref):
        return 'all_weakrefs_are_one'
    return repr(obj)[:40] 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:16,代码来源:objgraph.py

示例7: _randbelow

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type,
                   Method=_MethodType, BuiltinMethod=_BuiltinMethodType):
        "Return a random int in the range [0,n).  Raises ValueError if n==0."

        getrandbits = self.getrandbits
        # Only call self.getrandbits if the original random() builtin method
        # has not been overridden or if a new getrandbits() was supplied.
        if type(self.random) is BuiltinMethod or type(getrandbits) is Method:
            k = n.bit_length()  # don't use (n-1) here because n can be 1
            r = getrandbits(k)          # 0 <= r < 2**k
            while r >= n:
                r = getrandbits(k)
            return r
        # There's an overriden random() method but no new getrandbits() method,
        # so we can only use random() from here.
        random = self.random
        if n >= maxsize:
            _warn("Underlying random() generator does not supply \n"
                "enough bits to choose from a population range this large.\n"
                "To remove the range limitation, add a getrandbits() method.")
            return int(random() * n)
        rem = maxsize % n
        limit = (maxsize - rem) / maxsize   # int(limit * maxsize) % n == 0
        r = random()
        while r >= limit:
            r = random()
        return int(r*maxsize) % n

## -------------------- sequence methods  ------------------- 
开发者ID:war-and-code,项目名称:jawfish,代码行数:31,代码来源:random.py

示例8: inspect_format_method

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def inspect_format_method(callable):
    if not isinstance(callable, (types.MethodType,
                                 types.BuiltinMethodType)) or \
       callable.__name__ not in ('format', 'format_map'):
        return None
    obj = callable.__self__
    if isinstance(obj, string_types):
        return obj 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:sandbox.py

示例9: inspect_format_method

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def inspect_format_method(callable):
    if not isinstance(callable, (types.MethodType,
                                 types.BuiltinMethodType)) or \
       callable.__name__ != 'format':
        return None
    obj = callable.__self__
    if isinstance(obj, string_types):
        return obj 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,代码来源:sandbox.py

示例10: __getattr__

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def __getattr__(self, attr):
        real = getattr(self.repo, attr)
        if type(real) in [
            types.FunctionType,
            types.BuiltinFunctionType,
            types.BuiltinMethodType,
        ]:

            def fake(*args, **kwargs):
                resp = real(*args, **kwargs)
                if isinstance(resp, _pygit2.Walker):
                    resp = FakeWalker(resp)
                elif isinstance(resp, _pygit2.Diff):
                    resp = FakeDiffer(resp)
                return resp

            return fake
        elif isinstance(real, dict):
            real_getitem = real.__getitem__

            def fake_getitem(self, item):
                return real_getitem(item)

            real.__getitem__ = fake_getitem
            return real
        else:
            return real 
开发者ID:Pagure,项目名称:pagure,代码行数:29,代码来源:perfrepo.py

示例11: _randbelow

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def _randbelow(self, n, _log=_log, int=int, _maxwidth=1L<<BPF,
                   _Method=_MethodType, _BuiltinMethod=_BuiltinMethodType): 
开发者ID:glmcdona,项目名称:meddle,代码行数:4,代码来源:random.py

示例12: _randbelow

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def _randbelow(self, n, _log=_log, _int=int, _maxwidth=1L<<BPF,
                   _Method=_MethodType, _BuiltinMethod=_BuiltinMethodType): 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:random.py

示例13: _randbelow

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def _randbelow(self, n, int=int, maxsize=1<<BPF, type=type,
                   Method=_MethodType, BuiltinMethod=_BuiltinMethodType):
        "Return a random int in the range [0,n).  Raises ValueError if n==0."

        random = self.random
        getrandbits = self.getrandbits
        # Only call self.getrandbits if the original random() builtin method
        # has not been overridden or if a new getrandbits() was supplied.
        if type(random) is BuiltinMethod or type(getrandbits) is Method:
            k = n.bit_length()  # don't use (n-1) here because n can be 1
            r = getrandbits(k)          # 0 <= r < 2**k
            while r >= n:
                r = getrandbits(k)
            return r
        # There's an overridden random() method but no new getrandbits() method,
        # so we can only use random() from here.
        if n >= maxsize:
            _warn("Underlying random() generator does not supply \n"
                "enough bits to choose from a population range this large.\n"
                "To remove the range limitation, add a getrandbits() method.")
            return int(random() * n)
        rem = maxsize % n
        limit = (maxsize - rem) / maxsize   # int(limit * maxsize) % n == 0
        r = random()
        while r >= limit:
            r = random()
        return int(r*maxsize) % n

## -------------------- sequence methods  ------------------- 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:31,代码来源:random.py

示例14: __iter__

# 需要导入模块: import types [as 别名]
# 或者: from types import BuiltinMethodType [as 别名]
def __iter__(self):
        """ iterator generator for public values/properties
            It only returns the properties that are public.
        """
        attributes = [attr for attr in dir(self)
                      if not attr.startswith('__') and \
                      not attr.startswith('_') and \
                      not isinstance(getattr(self, attr), (types.MethodType,
                                                           types.BuiltinFunctionType,
                                                           types.BuiltinMethodType))
                      ]
        for att in attributes:
            yield (att, getattr(self, att))
    #---------------------------------------------------------------------- 
开发者ID:Esri,项目名称:ArcREST,代码行数:16,代码来源:services.py


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