def _read_pyc(source, pyc, trace=(lambda x: None)):
 try:
  fp = open(pyc, 'rb')
 except IOError:
  return None
 with fp:
  try:
   mtime = int(source.mtime())
   size = source.size()
   data = fp.read(12)
  except EnvironmentError as e:
   trace(('_read_pyc(%s): EnvironmentError %s' % (source, e)))
   return None
  if ((len(data) != 12) or (data[:4] != imp.get_magic()) or (struct.unpack('<ll', data[4:]) != (mtime, size))):
   trace(('_read_pyc(%s): invalid or out of date pyc' % source))
   return None
  try:
   co = marshal.load(fp)
  except Exception as e:
   trace(('_read_pyc(%s): marshal.load error %s' % (source, e)))
   return None
  if (not isinstance(co, types.CodeType)):
   trace(('_read_pyc(%s): not a code object' % source))
   return None
  return co

def _read_pyc ( source , pyc , trace = ( lambda x : None ) ) : try : fp = open ( pyc , 'rb' ) except IOError : return None with fp : try : mtime = int ( source . mtime ( ) ) size = source . size ( ) data = fp . read ( 12 ) except EnvironmentError as e : trace ( ( '_read_pyc(%s): EnvironmentError %s' % ( source , e ) ) ) return None if ( ( len ( data ) != 12 ) or ( data [ : 4 ] != imp . get_magic ( ) ) or ( struct . unpack ( '<ll' , data [ 4 : ] ) != ( mtime , size ) ) ) : trace ( ( '_read_pyc(%s): invalid or out of date pyc' % source ) ) return None try : co = marshal . load ( fp ) except Exception as e : trace ( ( '_read_pyc(%s): marshal.load error %s' % ( source , e ) ) ) return None if ( not isinstance ( co , types . CodeType ) ) : trace ( ( '_read_pyc(%s): not a code object' % source ) ) return None return co
possibly read a pytest pyc containing rewritten code .