<s> import sys <EOL> sys . path . insert ( <NUM_LIT:0> , '<STR_LIT:..>' ) <EOL> try : <EOL> import fintl <EOL> _ = fintl . gettext <EOL> except ImportError : <EOL> _ = lambda s : s <EOL> __doc__ = """<STR_LIT>""" <EOL> import os <EOL> import imp <EOL> import sys <EOL> import glob <EOL> import time <EOL> import getopt <EOL> import token <EOL> import tokenize <EOL> __version__ = '<STR_LIT>' <EOL> default_keywords = [ '<STR_LIT:_>' , '<STR_LIT>' ] <EOL> DEFAULTKEYWORDS = '<STR_LIT:U+002CU+0020>' . join ( default_keywords ) <EOL> EMPTYSTRING = '<STR_LIT>' <EOL> pot_header = '''<STR_LIT>''' <EOL> def usage ( code , msg = '<STR_LIT>' ) : <EOL> print >> sys . stderr , __doc__ % globals ( ) <EOL> if msg : <EOL> print >> sys . stderr , msg <EOL> sys . exit ( code ) <EOL> escapes = [ ] <EOL> def make_escapes ( pass_iso8859 ) : <EOL> global escapes <EOL> __escapes__ = { } <EOL> __escapes__ [ '<STR_LIT:\\>' ] = '<STR_LIT>' <EOL> __escapes__ [ '<STR_LIT:\t>' ] = '<STR_LIT>' <EOL> __escapes__ [ '<STR_LIT:\r>' ] = '<STR_LIT>' <EOL> __escapes__ [ '<STR_LIT:\n>' ] = '<STR_LIT>' <EOL> __escapes__ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def escape ( s ) : <EOL> if isinstance ( s , unicode ) : <EOL> s = s . encode ( '<STR_LIT:utf-8>' ) <EOL> s = list ( s ) <EOL> for i in range ( len ( s ) ) : <EOL> s [ i ] = __escapes__ . get ( s [ i ] , s [ i ] ) <EOL> return EMPTYSTRING . join ( s ) <EOL> def safe_eval ( s ) : <EOL> return eval ( s , { '<STR_LIT>' : { } } , { } ) <EOL> def normalize ( s ) : <EOL> lines = s . split ( '<STR_LIT:\n>' ) <EOL> if len ( lines ) == <NUM_LIT:1> : <EOL> s = '<STR_LIT:">' + escape ( s ) + '<STR_LIT:">' <EOL> else : <EOL> if not lines [ - <NUM_LIT:1> ] : <EOL> del lines [ - <NUM_LIT:1> ] <EOL> lines [ - <NUM_LIT:1> ] = lines [ - <NUM_LIT:1> ] + '<STR_LIT:\n>' <EOL> for i in range ( len ( lines ) ) : <EOL> lines [ i ] = escape ( lines [ i ] ) <EOL> lineterm = '<STR_LIT>' <EOL> s = '<STR_LIT>' + lineterm . join ( lines ) + '<STR_LIT:">' <EOL> return s <EOL> def containsAny ( str , set ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT:1> in [ c in str for c in set ] <EOL> def _visit_pyfiles ( list , dirname , names ) : <EOL> """<STR_LIT>""" <EOL> if not globals ( ) . has_key ( '<STR_LIT>' ) : <EOL> global _py_ext <EOL> _py_ext = [ triple [ <NUM_LIT:0> ] for triple in imp . get_suffixes ( ) <EOL> if triple [ <NUM_LIT:2> ] == imp . PY_SOURCE ] <EOL> if '<STR_LIT>' in names : <EOL> names . remove ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in names : <EOL> names . remove ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in names : <EOL> names . remove ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in names : <EOL> names . remove ( '<STR_LIT>' ) <EOL> list . extend ( <EOL> [ os . path . join ( dirname , file ) for file in names <EOL> if os . path . splitext ( file ) [ <NUM_LIT:1> ] in _py_ext ] <EOL> ) <EOL> def _get_modpkg_path ( dotted_name , pathlist = None ) : <EOL> """<STR_LIT>""" <EOL> parts = dotted_name . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> if len ( parts ) > <NUM_LIT:1> : <EOL> try : <EOL> file , pathname , description = imp . find_module ( parts [ <NUM_LIT:0> ] , pathlist ) <EOL> if file : file . close ( ) <EOL> except ImportError : <EOL> return None <EOL> if description [ <NUM_LIT:2> ] == imp . PKG_DIRECTORY : <EOL> pathname = _get_modpkg_path ( parts [ <NUM_LIT:1> ] , [ pathname ] ) <EOL> else : <EOL> pathname = None <EOL> else : <EOL> try : <EOL> file , pathname , description = imp . find_module ( <EOL> dotted_name , pathlist ) <EOL> if file : <EOL> file . close ( ) <EOL> if description [ <NUM_LIT:2> ] not in [ imp . PY_SOURCE , imp . PKG_DIRECTORY ] : <EOL> pathname = None <EOL> except ImportError : <EOL> pathname = None <EOL> return pathname <EOL> def getFilesForName ( name ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( name ) : <EOL> if containsAny ( name , "<STR_LIT>" ) : <EOL> files = glob . glob ( name ) <EOL> list = [ ] <EOL> for file in files : <EOL> list . extend ( getFilesForName ( file ) ) <EOL> return list <EOL> name = _get_modpkg_path ( name ) <EOL> if not name : <EOL> return [ ] <EOL> if os . path . isdir ( name ) : <EOL> list = [ ] <EOL> os . path . walk ( name , _visit_pyfiles , list ) <EOL> return list <EOL> elif os . path . exists ( name ) : <EOL> return [ name ] <EOL> return [ ] <EOL> class TokenEater : <EOL> def __init__ ( self , options , vars = None ) : <EOL> self . __options = options <EOL> self . __messages = { } <EOL> self . __state = self . __waiting <EOL> self . __args = [ ] <EOL> self . __lineno = - <NUM_LIT:1> <EOL> self . __freshmodule = <NUM_LIT:1> <EOL> self . __curfile = None <EOL> self . __vars = vars <EOL> def __call__ ( self , ttype , tstring , stup , etup , line ) : <EOL> self . __state ( ttype , tstring , stup [ <NUM_LIT:0> ] ) <EOL> def __waiting ( self , ttype , tstring , lineno ) : <EOL> opts = self . __options <EOL> if opts . docstrings and not opts . nodocstrings . get ( self . __curfile ) : <EOL> if self . __freshmodule : <EOL> if ttype == tokenize . STRING : <EOL> try : <EOL> s = safe_eval ( tstring ) <EOL> except Exception as e : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : tstring , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> print >> sys . stderr , str ( e ) <EOL> else : <EOL> self . __addentry ( [ s ] , lineno , isdocstring = <NUM_LIT:1> ) <EOL> self . __freshmodule = <NUM_LIT:0> <EOL> elif ttype not in ( tokenize . COMMENT , tokenize . NL ) : <EOL> self . __freshmodule = <NUM_LIT:0> <EOL> return <EOL> if ttype == tokenize . NAME and tstring in ( '<STR_LIT:class>' , '<STR_LIT>' ) : <EOL> self . __state = self . __suiteseen <EOL> return <EOL> if ttype == tokenize . NAME and tstring in opts . keywords : <EOL> self . __state = self . __keywordseen <EOL> def __suiteseen ( self , ttype , tstring , lineno ) : <EOL> if ttype == tokenize . OP and tstring == '<STR_LIT::>' : <EOL> self . __state = self . __suitedocstring <EOL> def __suitedocstring ( self , ttype , tstring , lineno ) : <EOL> if ttype == tokenize . STRING : <EOL> try : <EOL> s = safe_eval ( tstring ) <EOL> except Exception as e : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : tstring , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> print >> sys . stderr , str ( e ) <EOL> else : <EOL> self . __addentry ( s , lineno , isdocstring = <NUM_LIT:1> ) <EOL> self . __state = self . __waiting <EOL> elif ttype not in ( tokenize . NEWLINE , tokenize . INDENT , <EOL> tokenize . COMMENT ) : <EOL> self . __state = self . __waiting <EOL> def __keywordseen ( self , ttype , tstring , lineno ) : <EOL> if ttype == tokenize . OP and tstring == '<STR_LIT:(>' : <EOL> self . __args = [ '<STR_LIT>' ] <EOL> self . __lineno = lineno <EOL> self . __depth = <NUM_LIT:0> <EOL> self . __state = self . __scanstring1 <EOL> else : <EOL> self . __state = self . __waiting <EOL> def __scanstring1 ( self , ttype , tstring , lineno ) : <EOL> if ttype == tokenize . OP and tstring == '<STR_LIT:)>' : <EOL> if self . __args [ - <NUM_LIT:1> ] : <EOL> try : <EOL> s = safe_eval ( self . __args [ - <NUM_LIT:1> ] ) <EOL> except Exception as e : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : self . __args [ - <NUM_LIT:1> ] , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> print >> sys . stderr , str ( e ) <EOL> self . __state = self . __waiting <EOL> return <EOL> if type ( s ) == str or type ( s ) == unicode : <EOL> self . __args [ - <NUM_LIT:1> ] = s <EOL> self . __addentry ( self . __args ) <EOL> else : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : s , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> self . __state = self . __waiting <EOL> elif ttype == tokenize . OP and tstring == '<STR_LIT:U+002C>' : <EOL> try : <EOL> s = safe_eval ( self . __args [ - <NUM_LIT:1> ] ) <EOL> except Exception as e : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : self . __args [ - <NUM_LIT:1> ] , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> print >> sys . stderr , str ( e ) <EOL> self . __state = self . __waiting <EOL> return <EOL> if type ( s ) == str or type ( s ) == unicode : <EOL> self . __args [ - <NUM_LIT:1> ] = s <EOL> self . __args . append ( '<STR_LIT>' ) <EOL> self . __state = self . __scanstring2 <EOL> else : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : s , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> self . __state = self . __waiting <EOL> else : <EOL> self . __args [ - <NUM_LIT:1> ] += tstring <EOL> def __scanstring2 ( self , ttype , tstring , lineno ) : <EOL> if ttype == tokenize . OP and tstring == '<STR_LIT:)>' : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> self . __state = self . __waiting <EOL> elif ttype == tokenize . OP and tstring == '<STR_LIT:U+002C>' : <EOL> try : <EOL> s = safe_eval ( self . __args [ - <NUM_LIT:1> ] ) <EOL> except Exception as e : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : self . __args [ - <NUM_LIT:1> ] , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> print >> sys . stderr , str ( e ) <EOL> self . __state = self . __waiting <EOL> return <EOL> s = safe_eval ( self . __args [ - <NUM_LIT:1> ] ) <EOL> if type ( s ) == str or type ( s ) == unicode : <EOL> self . __args [ - <NUM_LIT:1> ] = s <EOL> self . __addentry ( self . __args ) <EOL> self . __state = self . __waiting <EOL> else : <EOL> print >> sys . stderr , ( <EOL> '<STR_LIT>' <EOL> ) % { <EOL> '<STR_LIT>' : s , <EOL> '<STR_LIT:file>' : self . __curfile , <EOL> '<STR_LIT>' : self . __lineno <EOL> } <EOL> self . __state = self . __waiting <EOL> else : <EOL> self . __args [ - <NUM_LIT:1> ] += tstring <EOL> def __addentry ( self , args , lineno = None , isdocstring = <NUM_LIT:0> ) : <EOL> isplural = <NUM_LIT:0> <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> isplural = <NUM_LIT:1> <EOL> if lineno is None : <EOL> lineno = self . __lineno <EOL> exclude = <NUM_LIT:0> <EOL> if args [ <NUM_LIT:0> ] in self . __options . toexclude : <EOL> exclude = <NUM_LIT:1> <EOL> if isplural : <EOL> if args [ <NUM_LIT:1> ] not in self . __options . toexclude : <EOL> exclude = <NUM_LIT:0> <EOL> if not exclude : <EOL> entry = ( self . __curfile , lineno ) <EOL> self . __messages . setdefault ( tuple ( args [ <NUM_LIT:0> : <NUM_LIT:2> ] ) , { } ) [ entry ] = isdocstring <EOL> def set_filename ( self , filename ) : <EOL> self . __curfile = filename <EOL> self . __freshmodule = <NUM_LIT:1> <EOL> def write ( self , fp ) : <EOL> options = self . __options <EOL> timestamp = time . strftime ( '<STR_LIT>' ) <EOL> d = self . __vars . copy ( ) <EOL> d . update ( { '<STR_LIT:time>' : timestamp , '<STR_LIT:version>' : __version__ } ) <EOL> print >> fp , pot_header . format ( ** d ) <EOL> reverse = { } <EOL> for k , v in self . __messages . items ( ) : <EOL> keys = v . keys ( ) <EOL> keys . sort ( ) <EOL> reverse . setdefault ( tuple ( keys ) , [ ] ) . append ( ( k , v ) ) <EOL> rkeys = reverse . keys ( ) <EOL> rkeys . sort ( ) <EOL> for rkey in rkeys : <EOL> rentries = reverse [ rkey ] <EOL> rentries . sort ( ) <EOL> for k , v in rentries : <EOL> isdocstring = sum ( v . values ( ) ) <EOL> v = v . keys ( ) <EOL> v . sort ( ) <EOL> if not options . writelocations : <EOL> pass <EOL> elif options . locationstyle == options . SOLARIS : <EOL> for filename , lineno in v : <EOL> d = { '<STR_LIT:filename>' : filename , '<STR_LIT>' : lineno } <EOL> print >> fp , ( <EOL> '<STR_LIT>' ) % d <EOL> elif options . locationstyle == options . GNU : <EOL> locline = '<STR_LIT>' <EOL> for filename , lineno in v : <EOL> d = { '<STR_LIT:filename>' : filename , '<STR_LIT>' : lineno } <EOL> s = ( '<STR_LIT>' ) % d <EOL> if len ( locline ) + len ( s ) <= options . width : <EOL> locline = locline + s <EOL> else : <EOL> print >> fp , locline <EOL> locline = "<STR_LIT>" + s <EOL> if len ( locline ) > <NUM_LIT:2> : <EOL> print >> fp , locline <EOL> if isdocstring : <EOL> print >> fp , '<STR_LIT>' <EOL> print >> fp , '<STR_LIT>' , normalize ( k [ <NUM_LIT:0> ] ) <EOL> if len ( k ) > <NUM_LIT:1> : <EOL> print >> fp , '<STR_LIT>' , normalize ( k [ <NUM_LIT:1> ] ) <EOL> print >> fp , '<STR_LIT>' <EOL> print >> fp , '<STR_LIT>' <EOL> else : <EOL> print >> fp , '<STR_LIT>' <EOL> def main ( ) : <EOL> global default_keywords <EOL> try : <EOL> opts , args = getopt . getopt ( <EOL> sys . argv [ <NUM_LIT:1> : ] , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:version>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] ) <EOL> except getopt . error , msg : <EOL> usage ( <NUM_LIT:1> , msg ) <EOL> class Options : <EOL> GNU = <NUM_LIT:1> <EOL> SOLARIS = <NUM_LIT:2> <EOL> extractall = <NUM_LIT:0> <EOL> escape = <NUM_LIT:0> <EOL> keywords = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> outpath = '<STR_LIT>' <EOL> outfile = '<STR_LIT>' <EOL> writelocations = <NUM_LIT:1> <EOL> locationstyle = GNU <EOL> verbose = <NUM_LIT:0> <EOL> width = <NUM_LIT> <EOL> excludefilename = '<STR_LIT>' <EOL> docstrings = <NUM_LIT:0> <EOL> nodocstrings = { } <EOL> options = Options ( ) <EOL> locations = { '<STR_LIT>' : options . GNU , <EOL> '<STR_LIT>' : options . SOLARIS , <EOL> } <EOL> files = '<STR_LIT>' <EOL> for opt , arg in opts : <EOL> if opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> usage ( <NUM_LIT:0> ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . extractall = <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . outfile = arg + '<STR_LIT>' <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . escape = <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . docstrings = <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . keywords . append ( arg ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> default_keywords = [ ] <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . writelocations = <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT>' , ) : <EOL> options . writelocations = <NUM_LIT:0> <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . locationstyle = locations . get ( arg . lower ( ) ) <EOL> if options . locationstyle is None : <EOL> usage ( <NUM_LIT:1> , ( '<STR_LIT>' ) % arg ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . outfile = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . outpath = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . verbose = <NUM_LIT:1> <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> print ( '<STR_LIT>' ) % __version__ <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> try : <EOL> options . width = int ( arg ) <EOL> except ValueError : <EOL> usage ( <NUM_LIT:1> , ( '<STR_LIT>' ) % arg ) <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> options . excludefilename = arg <EOL> elif opt in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> fp = open ( arg ) <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> line = fp . readline ( ) <EOL> if not line : <EOL> break <EOL> options . nodocstrings [ line [ : - <NUM_LIT:1> ] ] = <NUM_LIT:1> <EOL> finally : <EOL> fp . close ( ) <EOL> elif opt == '<STR_LIT>' : <EOL> files = arg <EOL> options . keywords . extend ( default_keywords ) <EOL> if options . excludefilename : <EOL> try : <EOL> fp = open ( options . excludefilename ) <EOL> options . toexclude = fp . readlines ( ) <EOL> fp . close ( ) <EOL> except IOError : <EOL> print >> sys . stderr , ( <EOL> "<STR_LIT>" ) % options . excludefilename <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> options . toexclude = [ ] <EOL> expanded = [ ] <EOL> for arg in args : <EOL> if arg == '<STR_LIT:->' : <EOL> expanded . append ( arg ) <EOL> else : <EOL> expanded . extend ( getFilesForName ( arg ) ) <EOL> args = expanded <EOL> if files : <EOL> lines = open ( files ) . readlines ( ) <EOL> for line in lines : <EOL> args . append ( line . strip ( ) ) <EOL> eater = TokenEater ( options ) <EOL> for filename in args : <EOL> if filename == '<STR_LIT:->' : <EOL> if options . verbose : <EOL> print ( '<STR_LIT>' ) <EOL> fp = sys . stdin <EOL> closep = <NUM_LIT:0> <EOL> else : <EOL> if options . verbose : <EOL> print ( '<STR_LIT>' ) % filename <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> from uliweb . core . template import template_file_py <EOL> from cStringIO import StringIO <EOL> text = template_file_py ( filename , skip_extern = True , multilines = True ) <EOL> fp = StringIO ( text ) <EOL> else : <EOL> fp = open ( filename ) <EOL> closep = <NUM_LIT:1> <EOL> try : <EOL> eater . set_filename ( filename ) <EOL> try : <EOL> tokenize . tokenize ( fp . readline , eater ) <EOL> except tokenize . TokenError , e : <EOL> print >> sys . stderr , '<STR_LIT>' % ( <EOL> e [ <NUM_LIT:0> ] , filename , e [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , e [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> finally : <EOL> if closep : <EOL> fp . close ( ) <EOL> if options . outfile == '<STR_LIT:->' : <EOL> fp = sys . stdout <EOL> closep = <NUM_LIT:0> <EOL> else : <EOL> if options . outpath : <EOL> options . outfile = os . path . join ( options . outpath , options . outfile ) <EOL> path = os . path . dirname ( options . outfile ) <EOL> if path : <EOL> if not os . path . exists ( path ) : <EOL> try : <EOL> os . makedirs ( path ) <EOL> except : <EOL> pass <EOL> fp = open ( options . outfile , '<STR_LIT:w>' ) <EOL> closep = <NUM_LIT:1> <EOL> try : <EOL> eater . write ( fp ) <EOL> finally : <EOL> if closep : <EOL> fp . close ( ) <EOL> def extrace_files ( files , outputfile , opts = None , vars = None ) : <EOL> global _py_ext <EOL> import logging <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> opts = opts or { } <EOL> vars = vars or { } <EOL> _py_ext = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> class Options : <EOL> GNU = <NUM_LIT:1> <EOL> SOLARIS = <NUM_LIT:2> <EOL> extractall = <NUM_LIT:0> <EOL> escape = <NUM_LIT:0> <EOL> keywords = [ '<STR_LIT:_>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> outpath = '<STR_LIT>' <EOL> outfile = outputfile <EOL> writelocations = <NUM_LIT:1> <EOL> locationstyle = GNU <EOL> verbose = <NUM_LIT:0> <EOL> width = <NUM_LIT> <EOL> excludefilename = '<STR_LIT>' <EOL> docstrings = <NUM_LIT:0> <EOL> nodocstrings = { } <EOL> toexclude = [ ] <EOL> options = Options ( ) <EOL> options . keywords . extend ( default_keywords ) <EOL> for k , v in opts . items ( ) : <EOL> if v and hasattr ( options , k ) : <EOL> _v = getattr ( options , k ) <EOL> if isinstance ( _v , list ) : <EOL> _v . extend ( v ) <EOL> elif isinstance ( _v , dict ) : <EOL> _v . update ( v ) <EOL> else : <EOL> setattr ( options , k , v ) <EOL> if not isinstance ( files , list ) : <EOL> files = getFilesForName ( files ) <EOL> eater = TokenEater ( options , vars = vars ) <EOL> for filename in files : <EOL> if options . verbose : <EOL> print ( '<STR_LIT>' ) % filename <EOL> if not os . path . exists ( filename ) : <EOL> continue <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> from uliweb . core import template <EOL> from cStringIO import StringIO <EOL> from uliweb . core . template import template_file_py <EOL> text = template_file_py ( filename , skip_extern = True , log = log , multilines = True ) <EOL> fp = StringIO ( text ) <EOL> closep = <NUM_LIT:0> <EOL> else : <EOL> fp = open ( filename ) <EOL> closep = <NUM_LIT:1> <EOL> try : <EOL> eater . set_filename ( filename ) <EOL> try : <EOL> tokenize . tokenize ( fp . readline , eater ) <EOL> except tokenize . TokenError , e : <EOL> print >> sys . stderr , '<STR_LIT>' % ( <EOL> e [ <NUM_LIT:0> ] , filename , e [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] , e [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] ) <EOL> finally : <EOL> if closep : <EOL> fp . close ( ) <EOL> if options . outfile == '<STR_LIT:->' : <EOL> fp = sys . stdout <EOL> closep = <NUM_LIT:0> <EOL> else : <EOL> if options . outpath : <EOL> options . outfile = os . path . join ( options . outpath , options . outfile ) <EOL> path = os . path . dirname ( options . outfile ) <EOL> if path : <EOL> if not os . path . exists ( path ) : <EOL> try : <EOL> os . makedirs ( path ) <EOL> except : <EOL> pass <EOL> fp = open ( options . outfile , '<STR_LIT:w>' ) <EOL> closep = <NUM_LIT:1> <EOL> try : <EOL> eater . write ( fp ) <EOL> finally : <EOL> if closep : <EOL> fp . close ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
