Changeset 8125 for trunk/anuga_core/source/anuga/caching/caching.py
- Timestamp:
- Mar 4, 2011, 2:34:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/caching/caching.py
r8124 r8125 269 269 # Imports and input checks 270 270 # 271 import t ypes, time, string271 import time, string 272 272 273 273 if not cachedir: … … 285 285 286 286 # Handle the case cache('clear') 287 if type(my_F) == types.StringType:287 if isinstance(my_F, basestring): 288 288 if string.lower(my_F) == 'clear': 289 289 clear_cache(CD,verbose=verbose) … … 291 291 292 292 # Handle the case cache(my_F, 'clear') 293 if type(args) == types.StringType:293 if isinstance(args, basestring): 294 294 if string.lower(args) == 'clear': 295 295 clear_cache(CD,my_F,verbose=verbose) … … 297 297 298 298 # Force singleton arg into a tuple 299 if type(args) != types.TupleType:299 if not isinstance(args, tuple): 300 300 args = tuple([args]) 301 301 302 302 # Check that kwargs is a dictionary 303 if type(kwargs) != types.DictType:303 if not isinstance(kwargs, dict): 304 304 raise TypeError 305 305 … … 309 309 # Get sizes and timestamps for files listed in dependencies. 310 310 # Force singletons into a tuple. 311 if dependencies and type(dependencies) != types.TupleType \ 312 and type(dependencies) != types.ListType: 311 if dependencies and not isinstance(dependencies, (tuple, list)): 313 312 dependencies = tuple([dependencies]) 314 313 deps = get_depstats(dependencies) … … 833 832 """ 834 833 835 import time, string , types834 import time, string 836 835 837 836 # Assess whether cached result exists - compressed or not. … … 1043 1042 """ 1044 1043 1045 import time, os, sys , types1044 import time, os, sys 1046 1045 1047 1046 (argsfile, compressed) = myopen(CD+FN+'_'+file_types[1], 'wb', compression) … … 1077 1076 """ 1078 1077 1079 import time, os, sys , types1078 import time, os, sys 1080 1079 1081 1080 (datafile, compressed1) = myopen(CD+FN+'_'+file_types[0],'wb',compression) … … 1415 1414 """ 1416 1415 1417 from types import TupleType, ListType, DictType, InstanceType1418 1419 1416 # Keep track of unique id's to protect against infinite recursion 1420 1417 if ids is None: ids = {} … … 1437 1434 1438 1435 # Compare recursively based on argument type 1439 if type(A) in [TupleType, ListType]:1436 if isinstance(A, (tuple, list)): 1440 1437 N = len(A) 1441 1438 if len(B) != N: … … 1447 1444 identical = False; break 1448 1445 1449 elif type(A) == DictType:1446 elif isinstance(A, dict): 1450 1447 if len(A) != len(B): 1451 1448 identical = False … … 1461 1458 identical = num.alltrue(A==B) 1462 1459 1463 elif type(A) == InstanceType:1460 elif type(A) == types.InstanceType: 1464 1461 # Take care of special case where elements are instances 1465 1462 # Base comparison on attributes … … 1520 1517 """ 1521 1518 1522 import types,string1519 import string 1523 1520 1524 1521 if type(my_F) == types.FunctionType: … … 1549 1546 get_bytecode(my_F) 1550 1547 """ 1551 1552 import types1553 1548 1554 1549 if type(my_F) == types.FunctionType: … … 1601 1596 """ 1602 1597 1603 import types1604 1605 1598 d = {} 1606 1599 if dependencies: … … 1620 1613 1621 1614 for FN in expanded_dependencies: 1622 if not type(FN) == types.StringType:1615 if not isinstance(FN, basestring): 1623 1616 errmsg = 'ERROR (caching.py): Dependency must be a string.\n' 1624 1617 errmsg += ' Dependency given: %s' %FN … … 2096 2089 """ 2097 2090 2098 import types2099 2100 2091 sortlist = [] 2101 2092 keylist = Dict.keys() 2102 2093 for key in keylist: 2103 2094 rec = Dict[key] 2104 if not type(rec) in [types.ListType, types.TupleType]:2095 if not isinstance(rec, (list, tuple)): 2105 2096 rec = [rec] 2106 2097 … … 2390 2381 """ 2391 2382 2392 import types2393 2394 2383 if level > 10: 2395 2384 # Protect against circular structures … … 2398 2387 WasTruncated = 0 2399 2388 2400 if not type(args) in [types.TupleType, types.ListType, types.DictType]:2401 if type(args) == types.StringType:2389 if not isinstance(args, (tuple, list, dict)): 2390 if isinstance(args, basestring): 2402 2391 argstr = argstr + "'"+str(args)+"'" 2403 2392 else: … … 2413 2402 argstr = argstr + str(args) 2414 2403 else: 2415 if type(args) == types.DictType:2404 if isinstance(args, dict): 2416 2405 argstr = argstr + "{" 2417 2406 for key in args.keys(): … … 2425 2414 2426 2415 else: 2427 if type(args) == types.TupleType:2416 if isinstance(args, tuple): 2428 2417 lc = '(' 2429 2418 rc = ')' … … 2440 2429 # Strip off trailing comma and space unless singleton tuple 2441 2430 # 2442 if type(args) == types.TupleTypeand len(args) == 1:2431 if isinstance(args, tuple) and len(args) == 1: 2443 2432 argstr = argstr[:-1] 2444 2433 else:
Note: See TracChangeset
for help on using the changeset viewer.