Show
Ignore:
Timestamp:
08/07/12 08:54:28 (7 years ago)
Author:
albert
Message:

Partial fix for #1084. Additionally, a number of individual test files need to be fixed.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • seattle/trunk/utf/utf.py

    r5637 r5649  
    505505 
    506506  # Execute the program. 
    507   (out, error) = utfutil.execute(popen_args) 
     507  (rawout, error) = utfutil.execute(popen_args) 
     508 
     509  # Get rid of debug output on Android, #1084. 
     510  out = strip_android_debug_messages(rawout) 
    508511   
    509512  # Is this executable suppose to produce any output on standard out? 
     
    661664def print_dashes():  
    662665  print '-' * 80 
     666 
     667 
     668 
     669 
     670def strip_android_debug_messages(rawoutput): 
     671  """ 
     672  Interim fix for #1084: Get rid of stray debugging output on Android 
     673  of the form "dlopen libpython2.6.so" and "dlopen /system/lib/libc.so", 
     674  yet preserve all of the other output (including empty lines). 
     675   
     676  Note that almost the same code is used in trunk/repy/safe.py as of r5639. 
     677  """ 
     678 
     679  # Are we running on Android? 
     680  try: 
     681    import android 
     682  except ImportError: 
     683    # If not, then we are done! 
     684    return rawoutput 
     685 
     686  # If we are, then there is work to do (as of Py4A 2.6.2) 
     687  output = "" 
     688  for line in rawoutput.split("\n"): 
     689    # Preserve empty lines 
     690    if line == "": 
     691      output += "\n" 
     692      continue 
     693    # Suppress debug messages we know can turn up 
     694    wordlist = line.split() 
     695    if wordlist[0]=="dlopen": 
     696      if wordlist[-1]=="/system/lib/libc.so": 
     697        continue 
     698      if wordlist[-1].startswith("libpython") and \ 
     699        wordlist[-1].endswith(".so"): 
     700        # We expect "libpython" + version number + ".so". 
     701        # The version number should be a string convertible to float. 
     702        # If it's not, raise an exception. 
     703        try: 
     704          versionstring = (wordlist[-1].replace("libpython",  
     705            "")).replace(".so", "") 
     706          junk = float(versionstring) 
     707        except TypeError, ValueError: 
     708          raise Exception("Unexpected debug output '" + line +  
     709            "' while evaluating code safety!") 
     710    else: 
     711      output += line + "\n" 
     712 
     713  # Strip off the last newline character we added 
     714  return output[0:-1] 
    663715 
    664716