def _read_pyc(source, pyc, trace=lambda x: None):
try:<EOL><INDENT>fp = open(pyc, "<STR_LIT:rb>")<EOL><DEDENT>except IOError:<EOL><INDENT>return None<EOL><DEDENT>with fp:<EOL><INDENT>try:<EOL><INDENT>mtime = int(source.mtime())<EOL>size = source.size()<EOL>data = fp.read(<NUM_LIT:12>)<EOL><DEDENT>except EnvironmentError as e:<EOL><INDENT>trace("<STR_LIT>" % (source, e))<EOL>return None<EOL><DEDENT>if (<EOL>len(data) != <NUM_LIT:12><EOL>or data[:<NUM_LIT:4>] != imp.get_magic()<EOL>or struct.unpack("<STR_LIT>", data[<NUM_LIT:4>:]) != (mtime & <NUM_LIT>, size & <NUM_LIT>)<EOL>):<EOL><INDENT>trace("<STR_LIT>" % source)<EOL>return None<EOL><DEDENT>try:<EOL><INDENT>co = marshal.load(fp)<EOL><DEDENT>except Exception as e:<EOL><INDENT>trace("<STR_LIT>" % (source, e))<EOL>return None<EOL><DEDENT>if not isinstance(co, types.CodeType):<EOL><INDENT>trace("<STR_LIT>" % source)<EOL>return None<EOL><DEDENT>return co<EOL><DEDENT>
Possibly read a pytest pyc containing rewritten code.

    Return rewritten code if successful or None if not.