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
python类isinstance()的实例源码
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
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
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
def reversed(data):
if not isinstance(data, list):
data = list(data)
return data[::-1]
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 ---
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
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
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