Python __builtin__ 模块,isinstance() 实例源码

我们从Python开源项目中,提取了以下39个代码示例,用于说明如何使用__builtin__.isinstance()

项目:fypp    作者:aradi    | 项目源码 | 文件源码
def _get_callable_argspec_py2(func):
    argspec = inspect.getargspec(func)
    if argspec.keywords is not None:
        msg = "variable length keyword argument '{0}' found"\
            .format(argspec.keywords)
        raise FyppFatalError(msg)
    vararg = argspec.varargs
    args = argspec.args
    tuplearg = False
    for elem in args:
        tuplearg = tuplearg or isinstance(elem, list)
    if tuplearg:
        msg = 'tuple argument(s) found'
        raise FyppFatalError(msg)
    defaults = {}
    if argspec.defaults is not None:
        for ind, default in enumerate(argspec.defaults):
            iarg = len(args) - len(argspec.defaults) + ind
            defaults[args[iarg]] = default
    return args, defaults, vararg
项目:fypp    作者:aradi    | 项目源码 | 文件源码
def _formatted_exception(exc):
    error_header_formstr = '{file}:{line}: '
    error_body_formstr = 'error: {errormsg} [{errorclass}]'
    if not isinstance(exc, FyppError):
        return error_body_formstr.format(
            errormsg=str(exc), errorclass=exc.__class__.__name__)
    out = []
    if exc.fname is not None:
        if exc.span[1] > exc.span[0] + 1:
            line = '{0}-{1}'.format(exc.span[0] + 1, exc.span[1])
        else:
            line = '{0}'.format(exc.span[0] + 1)
        out.append(error_header_formstr.format(file=exc.fname, line=line))
    out.append(error_body_formstr.format(errormsg=exc.msg,
                                         errorclass=exc.__class__.__name__))
    if exc.cause is not None:
        out.append('\n' + _formatted_exception(exc.cause))
    out.append('\n')
    return ''.join(out)
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def IsValid(self):
        if dmGlobals.TraceFunctionMessages: print 'Property: dmParameters:IsValid'
        bReturn = True

        #validation for Actions
        if isinstance(self, dmAction):
            if (not self.Field in dmGlobals.ALLOWEDVALS):
                bReturn = False
            if not self.Modifier in dmGlobals.ValidValModifiers(self.Field):
                bReturn = False

        #validation for Rules
        elif isinstance(self, dmRule):
            if (not self.Field in dmGlobals.ALLOWEDVALS):
                bReturn = False
            if not self.Modifier in dmGlobals.ValidValModifiers(self.Field):
                bReturn = False

        #TODO: Determine if the value is valid
        if not ValueValid():
            bReturn = false
        return bReturn
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def ParseParameters(self, strParameters):
        """Parses the string containing info for the parameters"""
        if dmGlobals.TraceFunctionMessages: print 'Method: dmParameters:ParseParameters(objParameters)'
        if isinstance(strParameters, str):
            item = strParameters.strip() #strip whitespace from front of string

            item = item.lstrip('<') #remove all instances '<' from front of string
            item = item.rstrip('>') #remove all instances '>' from back of string

            tmpParameters = item.split('.',1) #results in [field, modifier&value]
            self.ParseField(tmpParameters[0]) #sets complete field from field value in created list
            modfierAndValue = tmpParameters[1].split(':',1) #results in [modifier, value]

            self.Modifier = modfierAndValue[0] #set the modifier
            if len(modfierAndValue) > 1: #if a value is present
                self.Value = modfierAndValue[1] #set the value accordingly
            else:
                self.Value = '' #otherwise set Value to empty string for safety purposes

        elif isinstance(strParameters, XElement):
            self.FromXML(strParameters)
        else:
            print 'could not parse Parameter Info' + strParameter
        pass
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def Is(self, book):
        if dmGlobals.TraceFunctionMessages: print 'Method: dmRule:Is(book)'

        getValue = self.GetFieldValue(book, self.Field) #get Value from book
        compareValue = self.FieldConvert(self.ReplaceReferenceStrings(self.Value, book) ,self.Field) #value to compare

        if self.Field in dmGlobals.FIELDSLIST: #deal with list items as individual items

            if len(compareValue) == len(getValue): #only continue if lists are same legnth
                count = 0
                for item in compareValue: #iterate through compare list items
                    for val in getValue: #iterate through book list items
                        if val.lower() == item.lower(): #compare lowercase list items from book (val) to compare list items (item)
                            count = count + 1 #if match increment count
                if count == len(getValue): #if count ends up equal between book list items and compare list items
                    return True #set true
        else:
            if isinstance(getValue, str):
                if getValue.lower() == compareValue.lower():
                    return True
            else:
                if getValue == compareValue: #if values match 
                    return True #set true

        return False #if everything else fails set false
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:watchmen    作者:lycclsltt    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:git_intgrtn_aws_s3    作者:droidlabour    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:MCSManager-fsmodule    作者:Suwings    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:PyMal    作者:cysinfo    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:fypp    作者:aradi    | 项目源码 | 文件源码
def parsefile(self, fobj):
        '''Parses file or a file like object.

        Args:
            fobj (str or file): Name of a file or a file like object.
        '''
        if isinstance(fobj, str):
            if fobj == STDIN:
                self._includefile(None, sys.stdin, STDIN, os.getcwd())
            else:
                inpfp = _open_input_file(fobj)
                self._includefile(None, inpfp, fobj, os.path.dirname(fobj))
                inpfp.close()
        else:
            self._includefile(None, fobj, FILEOBJ, os.getcwd())
项目:fypp    作者:aradi    | 项目源码 | 文件源码
def _func_import(self, name, *_, **__):
        module = self._scope.get(name, None)
        if module is not None and isinstance(module, types.ModuleType):
            return module
        else:
            msg = "Import of module '{0}' via '__import__' not allowed"\
                  .format(name)
            raise ImportError(msg)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:Encryped-file-system    作者:kittenish    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:isf    作者:w3h    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:kekescan    作者:xiaoxiaoleo    | 项目源码 | 文件源码
def isinstance(obj, t):
        if not __builtin__.isinstance(t, type(())):
            # t is not a tuple
            return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
        else:
            # t is a tuple
            for typ in t:
                if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
                    return True
            return False

# vim:set ts=4 sw=4 sts=4 expandtab:
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:UMOG    作者:hsab    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def __init__(self, strParameters):
        if dmGlobals.TraceFunctionMessages: print 'dmCollection constructor: dmCollection(objParameters)'
        if dmGlobals.TraceGeneralMessages: print 'Compiling Ruleset Collection'
        dmContainer.__init__(self, None, strParameters)
        self.Disabled = dmGroup(self)
        self.Version = System.Version(1,1,9,9)

        if strParameters != None:
            if isinstance(strParameters, XElement):
                self.FromXML(strParameters)
            else:
                self.ParseParameters(strParameters)
        pass
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def __setversion__(self, vItem):
        if dmGlobals.TraceFunctionMessages: print 'Method: dmCollection:__setversion__(objVersion)'
        if isinstance(vItem, System.Version):
            self.Version = vItem
        elif isinstance(vItem, str):
            self.Version = System.Version.Parse(vItem)
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def __init__(self, dmcparent, strParameters=None):
        if dmGlobals.TraceFunctionMessages: print 'dmGroup constructor: dmGroup(dmContainerParent, objParameters)'
        dmContainer.__init__(self, dmcparent, strParameters)
        self.FiltersAndDefaults = dmRuleset(self, None)

        if strParameters != None:
            if isinstance(strParameters, XElement):
                self.FromXML(strParameters)
            else:
                self.ParseParameters(strParameters)
        pass
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def ParseParameters(self, strParameters):
        """Parses Parameters of Group from a string or list of parameters"""
        if dmGlobals.TraceFunctionMessages: print 'Method: dmGroup:ParseParameters(objParameters)'
        if isinstance(strParameters, str) or isinstance(strParameters, list):
            arrParameters = list()
            if isinstance(strParameters, str):
                arrParameters = strParameters.splitlines() #split string into lines
            elif isinstance(strParameters, list):
                arrParameters = strParameters

            nReturn = 0
            #Parse Group Info from line
            if arrParameters[nReturn].startswith(GROUPHEADER):
                GroupInfo = self.ParseNodeInfo(arrParameters[nReturn])
                self.Name = GroupInfo['GROUP'].strip()
                if GroupInfo.haskey('COMMENT'):
                    self.Comment = GroupInfo['COMMENT'].strip()
                if GroupInfo.haskey('FILTERSANDDEFAULTS'):
                    self.FiltersAndDefaults = dmRuleset(self,GroupInfo['FILTERSANDDEFAULTS'].strip())
                #increment nReturn
                nReturn = nReturn + 1

            while nReturn < len(arrParameters) and not arrParameters[nReturn].startswith(GROUPENDER):
                if arrParameters[nReturn].startswith(GROUPHEADER):
                    nReturn = self.ParseGroup(arrParameters, nReturn, self)
                elif arrParameters[nReturn].startswith(RULESETHEADER) or not arrParameters[nReturn].startswith('#'):
                    nReturn = ParseRuleset(arrParameters, nReturn, self)
        elif isinstance(strParameters, XElement):
            self.FromXML(strParameters)
        pass
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def __init__(self, dmcparent, strParameters=None):
        """initializes ruleset instance"""
        if dmGlobals.TraceFunctionMessages: print 'dmRuleset constructor: dmRuleset(objParameters)'
        dmNode.__init__(self, dmcparent, strParameters) #calls base initialize which adds base fields
        self.RulesetMode = 'AND' #sets ruleset mode by default to AND ParseParameters call (from dmNode) later corrrects if and is used
        self.Rules = [] #initializes list of rules
        self.Actions = [] #initializes list of actions

        if strParameters != None:
            if isinstance(strParameters, XElement):
                self.FromXML(strParameters)
            else:
                self.ParseParameters(strParameters)
        pass
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def __init__(self, dmnparent, strParameters):
        """initializes a dmParameter instance"""
        dmNode.__init__(self, dmnparent, strParameters) #calls the base dmNode initializer to initialize further fields
        self.Field = '' #initializes the field
        self.Modifier = '' #initializes the modifier value
        self.Value = '' #initializes the value value

        if strParameters != None:
            if isinstance(strParameters, XElement):
                self.FromXML(strParameters)
            else:
                self.ParseParameters(strParameters)
        pass
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def FieldConvert(self, strValue, strField=None):
        if dmGlobals.TraceFunctionMessages: print 'Method: dmParameters:FieldConvert(stringValue, stringFieldName)'

        FieldValue = self.Field
        if strField != None:
            FieldValue = strField

        theVal = strValue
        try:
            if FieldValue in dmGlobals.ALLOWEDVALS:
                if FieldValue in dmGlobals.FIELDSLIST and not dmGlobals.IsList(strValue):
                    theVal = strValue.Split(Array[str](dmGlobals.CRLISTDELIMITER), StringSplitOptions.RemoveEmptyEntries)
                elif FieldValue in dmGlobals.FIELDSBOOL and not dmGlobals.IsBool(strValue):
                    theVal = dmGlobals.StringToBool(strValue)
                elif FieldValue in dmGlobals.FIELDSDATETIME and not dmGlobals.IsDateTime(strValue):
                    theVal = dmGlobals.StringToDate(strValue)
                elif FieldValue in dmGlobals.FIELDSNUMERIC and not dmGlobals.IsFloat(strValue):
                    theVal = dmGlobals.StringToFloat(strValue)
                elif FieldValue in dmGlobals.FIELDSMANGAYESNO and not dmGlobals.IsMangaYesNo(strValue):
                    theVal = dmGlobals.StringToMangaYesNo(strValue)
                elif FieldValue in dmGlobals.FIELDSYESNO and not dmGlobals.IsYesNo(strValue):
                    theVal = dmGlobals.StringToYesNo(strValue)
                elif FieldValue in dmGlobals.FIELDSPSUEDONUMERIC and not isinstance(strValue,str):
                    try:                    
                        theVal = strValue.ToString()
                    except:
                        pass
            #otherwise just return the value
        except Exception as ex:

            pass
        return theVal
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def isinstance20(a, typea):
        if type(typea) != type(type):
            raise TypeError("TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types")
        return type(typea) != typea
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def reversed(data):
            if not isinstance(data, list):
                data = list(data)
            return data[::-1]
项目:watcher    作者:nosmokingbandit    | 项目源码 | 文件源码
def reversed(data):
            if not isinstance(data, list):
                data = list(data)
            reversed_data = []
            for index in xrange(len(data)-1, -1, -1):
                reversed_data.append(data[index])
            return reversed_data

# --- sorted() from Python 2.4 ---
项目:hackathon    作者:vertica    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def pow(x, y, z=_SENTINEL):
        """
        pow(x, y[, z]) -> number

        With two arguments, equivalent to x**y.  With three arguments,
        equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
        """
        # Handle newints
        if isinstance(x, newint):
            x = long(x)
        if isinstance(y, newint):
            y = long(y)
        if isinstance(z, newint):
            z = long(z)

        try:
            if z == _SENTINEL:
                return _builtin_pow(x, y)
            else:
                return _builtin_pow(x, y, z)
        except ValueError:
            if z == _SENTINEL:
                return _builtin_pow(x+0j, y)
            else:
                return _builtin_pow(x+0j, y, z)

    # ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
    #     callable = __builtin__.callable
项目:CRDataManager    作者:NobahdiAtoll    | 项目源码 | 文件源码
def SetFieldValue(self, book, newValue, strField=None):
        """Determines the proper write to book technique (Standard or Custom Field) and applies value"""
        if dmGlobals.TraceFunctionMessages: print 'Method: dmAction:SetValue(book, objNewValue, stringFieldName)'

        FieldValue = self.Field

        if strField != None:
            FieldValue = strField

        previousVal = self.GetFieldValue(book, FieldValue)

        newVal = newValue

        strReport = ''            
        if FieldValue in dmGlobals.FIELDSLIST:
            if dmGlobals.SortLists:
                newVal.sort()
            newVal = dmGlobals.CRLISTDELIMITER.join(newVal)
            previousVal = dmGlobals.CRLISTDELIMITER.join(previousVal)

        if FieldValue in dmGlobals.ALLOWEDVALS:
            try:
                if FieldValue in dmGlobals.FIELDSNUMERIC:
                    setattr(book, FieldValue, dmGlobals.StringToFloat(newVal)) #convert to float
                else:
                    setattr(book, FieldValue, newVal.ToString())
                #prepare the report
                strReport = '    Field: ' + FieldValue + '    Action: ' + self.ToString()
                strReport = strReport + System.Environment.NewLine + '        Previous Value: ' + dmGlobals.ToString(previousVal)
                strReport = strReport + System.Environment.NewLine + '        New Value: ' + dmGlobals.ToString(newVal) + '\r\n'
            except Exception as er:
                #report errors instead
                strReport = '    An unexpected error occured in Action: ' + self.ToString() + '    Parent Ruleset : ' + self.Parent.Name
                if isinstance(er, dmConversionError):
                    strReport = strReport + ' Error' + er.msg
                pass
        else:
            self.SetCustomField(book, FieldValue, newVal)
            #prepare the report
            if strReport != '': strReport = System.Environment.NewLine
            strReport = '    CustomField: ' + self.Field + '    Action: ' + self.ToString()
            strReport = strReport + System.Environment.NewLine + '        Previous Value: ' + dmGlobals.ToString(previousVal)
            strReport = strReport + System.Environment.NewLine + '        New Value: ' + dmGlobals.ToString(newVal)
        return strReport