當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。