Ignore:
Timestamp:
Mar 4, 2011, 2:34:28 PM (14 years ago)
Author:
wilsonr
Message:

Changes to address ticket 360.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga/caching/caching.py

    r8124 r8125  
    269269  # Imports and input checks
    270270  #
    271   import types, time, string
     271  import time, string
    272272
    273273  if not cachedir:
     
    285285
    286286  # Handle the case cache('clear')
    287   if type(my_F) == types.StringType:
     287  if isinstance(my_F, basestring):
    288288    if string.lower(my_F) == 'clear':
    289289      clear_cache(CD,verbose=verbose)
     
    291291
    292292  # Handle the case cache(my_F, 'clear')
    293   if type(args) == types.StringType:
     293  if isinstance(args, basestring):
    294294    if string.lower(args) == 'clear':
    295295      clear_cache(CD,my_F,verbose=verbose)
     
    297297
    298298  # Force singleton arg into a tuple
    299   if type(args) != types.TupleType:
     299  if not isinstance(args, tuple):
    300300    args = tuple([args])
    301301 
    302302  # Check that kwargs is a dictionary
    303   if type(kwargs) != types.DictType:
     303  if not isinstance(kwargs, dict):
    304304    raise TypeError   
    305305   
     
    309309  # Get sizes and timestamps for files listed in dependencies.
    310310  # 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)):
    313312    dependencies = tuple([dependencies])
    314313  deps = get_depstats(dependencies)
     
    833832  """
    834833
    835   import time, string, types
     834  import time, string
    836835
    837836  # Assess whether cached result exists - compressed or not.
     
    10431042  """
    10441043
    1045   import time, os, sys, types
     1044  import time, os, sys
    10461045
    10471046  (argsfile, compressed) = myopen(CD+FN+'_'+file_types[1], 'wb', compression)
     
    10771076  """
    10781077
    1079   import time, os, sys, types
     1078  import time, os, sys
    10801079
    10811080  (datafile, compressed1) = myopen(CD+FN+'_'+file_types[0],'wb',compression)
     
    14151414    """
    14161415
    1417     from types import TupleType, ListType, DictType, InstanceType
    1418    
    14191416    # Keep track of unique id's to protect against infinite recursion
    14201417    if ids is None: ids = {}
     
    14371434 
    14381435    # Compare recursively based on argument type
    1439     if type(A) in [TupleType, ListType]:
     1436    if isinstance(A, (tuple, list)):
    14401437        N = len(A)
    14411438        if len(B) != N:
     
    14471444                    identical = False; break
    14481445                   
    1449     elif type(A) == DictType:
     1446    elif isinstance(A, dict):
    14501447        if len(A) != len(B):
    14511448            identical = False
     
    14611458        identical = num.alltrue(A==B)
    14621459
    1463     elif type(A) == InstanceType:
     1460    elif type(A) == types.InstanceType:
    14641461        # Take care of special case where elements are instances           
    14651462        # Base comparison on attributes     
     
    15201517  """
    15211518
    1522   import types, string
     1519  import string
    15231520
    15241521  if type(my_F) == types.FunctionType:
     
    15491546    get_bytecode(my_F)
    15501547  """
    1551 
    1552   import types
    15531548
    15541549  if type(my_F) == types.FunctionType:
     
    16011596  """
    16021597
    1603   import types
    1604 
    16051598  d = {}
    16061599  if dependencies:
     
    16201613   
    16211614    for FN in expanded_dependencies:
    1622       if not type(FN) == types.StringType:
     1615      if not isinstance(FN, basestring):
    16231616        errmsg = 'ERROR (caching.py): Dependency must be a string.\n'
    16241617        errmsg += '                   Dependency given: %s' %FN
     
    20962089  """
    20972090
    2098   import types
    2099 
    21002091  sortlist  = []
    21012092  keylist = Dict.keys()
    21022093  for key in keylist:
    21032094    rec = Dict[key]
    2104     if not type(rec) in [types.ListType, types.TupleType]:
     2095    if not isinstance(rec, (list, tuple)):
    21052096      rec = [rec]
    21062097
     
    23902381  """
    23912382
    2392   import types
    2393 
    23942383  if level > 10:
    23952384      # Protect against circular structures
     
    23982387  WasTruncated = 0
    23992388
    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):
    24022391      argstr = argstr + "'"+str(args)+"'"
    24032392    else:
     
    24132402      argstr = argstr + str(args)
    24142403  else:
    2415     if type(args) == types.DictType:
     2404    if isinstance(args, dict):
    24162405      argstr = argstr + "{"
    24172406      for key in args.keys():
     
    24252414
    24262415    else:
    2427       if type(args) == types.TupleType:
     2416      if isinstance(args, tuple):
    24282417        lc = '('
    24292418        rc = ')'
     
    24402429      # Strip off trailing comma and space unless singleton tuple
    24412430      #
    2442       if type(args) == types.TupleType and len(args) == 1:
     2431      if isinstance(args, tuple) and len(args) == 1:
    24432432        argstr = argstr[:-1]   
    24442433      else:
Note: See TracChangeset for help on using the changeset viewer.