<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import os <EOL> import re <EOL> from contextlib import contextmanager <EOL> from pants . base . exceptions import TaskError <EOL> class ParseError ( TaskError ) : <EOL> pass <EOL> @ contextmanager <EOL> def raise_on_eof ( infile ) : <EOL> try : <EOL> yield <EOL> except StopIteration : <EOL> filename = getattr ( infile , '<STR_LIT:name>' , None ) or repr ( infile ) <EOL> raise ParseError ( "<STR_LIT>" . format ( filename ) ) <EOL> class AnalysisParser ( object ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def empty_test_header ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> @ property <EOL> def current_test_header ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( '<STR_LIT>' ) <EOL> def validate_analysis ( self , path ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( path ) : <EOL> return <EOL> with open ( path , '<STR_LIT:rb>' ) as infile : <EOL> with raise_on_eof ( infile ) : <EOL> firstline = infile . next ( ) <EOL> if firstline != self . current_test_header : <EOL> raise ParseError ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( path , <EOL> firstline , <EOL> self . current_test_header ) ) <EOL> def is_nonempty_analysis ( self , path ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( path ) : <EOL> return False <EOL> with open ( path , '<STR_LIT:rb>' ) as infile : <EOL> with raise_on_eof ( infile ) : <EOL> expected_header = b'<STR_LIT>' . format ( self . empty_test_header ) <EOL> while infile . next ( ) != expected_header : <EOL> pass <EOL> return self . parse_num_items ( infile . next ( ) ) > <NUM_LIT:0> <EOL> def parse_from_path ( self , infile_path ) : <EOL> """<STR_LIT>""" <EOL> with open ( infile_path , '<STR_LIT:rb>' ) as infile : <EOL> return self . parse ( infile ) <EOL> def parse ( self , infile ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def parse_products_from_path ( self , infile_path , classes_dir ) : <EOL> """<STR_LIT>""" <EOL> with open ( infile_path , '<STR_LIT:rb>' ) as infile : <EOL> return self . parse_products ( infile , classes_dir ) <EOL> def parse_products ( self , infile , classes_dir ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def parse_deps_from_path ( self , infile_path ) : <EOL> """<STR_LIT>""" <EOL> with open ( infile_path , '<STR_LIT:rb>' ) as infile : <EOL> return self . parse_deps ( infile ) <EOL> def parse_deps ( self , infile ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> _num_items_re = re . compile ( r'<STR_LIT>' ) <EOL> def parse_num_items ( self , line ) : <EOL> """<STR_LIT>""" <EOL> matchobj = self . _num_items_re . match ( line ) <EOL> if not matchobj : <EOL> raise ParseError ( '<STR_LIT>' . format ( line ) ) <EOL> return int ( matchobj . group ( <NUM_LIT:1> ) ) <EOL> def rebase_from_path ( self , infile_path , outfile_path , old_base , new_base , java_home = None ) : <EOL> """<STR_LIT>""" <EOL> with open ( infile_path , '<STR_LIT:rb>' ) as infile : <EOL> with open ( outfile_path , '<STR_LIT:wb>' ) as outfile : <EOL> self . rebase ( infile , outfile , old_base , new_base , java_home ) <EOL> def rebase ( self , infile , outfile , old_base , new_base , java_home = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
