<s> import os <EOL> import re <EOL> import subprocess <EOL> from . errors import FileTypeError <EOL> EXTENSIONS = { <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" , "<STR_LIT:e>" , "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] <EOL> } <EOL> """<STR_LIT>""" <EOL> EXT_RE = re . compile ( r'<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> def file ( path_or_f ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( path_or_f , "<STR_LIT>" ) : <EOL> return path_or_f <EOL> else : <EOL> path = path_or_f <EOL> path = os . path . expanduser ( path ) <EOL> if not os . path . isfile ( path ) : <EOL> raise FileTypeError ( "<STR_LIT>" % path ) <EOL> match = EXT_RE . search ( path ) <EOL> if match is None : <EOL> raise FileTypeError ( "<STR_LIT>" % path ) <EOL> elif match . groups ( ) [ <NUM_LIT:0> ] not in EXTENSIONS : <EOL> raise FileTypeError ( "<STR_LIT>" % path ) <EOL> else : <EOL> return path <EOL> def open_file ( path_or_f ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( path_or_f , "<STR_LIT>" ) : <EOL> return path_or_f <EOL> else : <EOL> path = path_or_f <EOL> match = EXT_RE . search ( path ) <EOL> ext = match . groups ( ) [ <NUM_LIT:0> ] <EOL> p = subprocess . Popen ( <EOL> EXTENSIONS [ ext ] + [ path ] , <EOL> stdout = subprocess . PIPE , <EOL> stderr = open ( os . devnull , "<STR_LIT:w>" ) <EOL> ) <EOL> return p . stdout </s>
