<s> """<STR_LIT>""" <EOL> import string , types <EOL> from twisted . python import deprecate , versions <EOL> def stringyString ( object , indentation = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> braces = '<STR_LIT>' <EOL> sl = [ ] <EOL> if type ( object ) is types . DictType : <EOL> braces = '<STR_LIT:{}>' <EOL> for key , value in object . items ( ) : <EOL> value = stringyString ( value , indentation + '<STR_LIT:U+0020>' ) <EOL> if isMultiline ( value ) : <EOL> if endsInNewline ( value ) : <EOL> value = value [ : - len ( '<STR_LIT:\n>' ) ] <EOL> sl . append ( "<STR_LIT>" % ( indentation , key , value ) ) <EOL> else : <EOL> sl . append ( "<STR_LIT>" % ( indentation , key , <EOL> value [ len ( indentation ) + <NUM_LIT:3> : ] ) ) <EOL> elif type ( object ) in ( types . TupleType , types . ListType ) : <EOL> if type ( object ) is types . TupleType : <EOL> braces = '<STR_LIT>' <EOL> else : <EOL> braces = '<STR_LIT>' <EOL> for element in object : <EOL> element = stringyString ( element , indentation + '<STR_LIT:U+0020>' ) <EOL> sl . append ( string . rstrip ( element ) + '<STR_LIT:U+002C>' ) <EOL> else : <EOL> sl [ : ] = map ( lambda s , i = indentation : i + s , <EOL> string . split ( str ( object ) , '<STR_LIT:\n>' ) ) <EOL> if not sl : <EOL> sl . append ( indentation ) <EOL> if braces : <EOL> sl [ <NUM_LIT:0> ] = indentation + braces [ <NUM_LIT:0> ] + sl [ <NUM_LIT:0> ] [ len ( indentation ) + <NUM_LIT:1> : ] <EOL> sl [ - <NUM_LIT:1> ] = sl [ - <NUM_LIT:1> ] + braces [ - <NUM_LIT:1> ] <EOL> s = string . join ( sl , "<STR_LIT:\n>" ) <EOL> if isMultiline ( s ) and not endsInNewline ( s ) : <EOL> s = s + '<STR_LIT:\n>' <EOL> return s <EOL> def isMultiline ( s ) : <EOL> """<STR_LIT>""" <EOL> return ( string . find ( s , '<STR_LIT:\n>' ) != - <NUM_LIT:1> ) <EOL> def endsInNewline ( s ) : <EOL> """<STR_LIT>""" <EOL> return ( s [ - len ( '<STR_LIT:\n>' ) : ] == '<STR_LIT:\n>' ) <EOL> deprecate . deprecatedModuleAttribute ( <EOL> versions . Version ( "<STR_LIT>" , <NUM_LIT:10> , <NUM_LIT:2> , <NUM_LIT:0> ) , <EOL> "<STR_LIT>" , <EOL> __name__ , "<STR_LIT>" ) <EOL> def docstringLStrip ( docstring ) : <EOL> """<STR_LIT>""" <EOL> if not docstring : <EOL> return docstring <EOL> docstring = string . replace ( docstring , '<STR_LIT:\t>' , '<STR_LIT:U+0020>' * <NUM_LIT:8> ) <EOL> lines = string . split ( docstring , '<STR_LIT:\n>' ) <EOL> leading = <NUM_LIT:0> <EOL> for l in xrange ( <NUM_LIT:1> , len ( lines ) ) : <EOL> line = lines [ l ] <EOL> if string . strip ( line ) : <EOL> while <NUM_LIT:1> : <EOL> if line [ leading ] == '<STR_LIT:U+0020>' : <EOL> leading = leading + <NUM_LIT:1> <EOL> else : <EOL> break <EOL> if leading : <EOL> break <EOL> outlines = lines [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> for l in xrange ( <NUM_LIT:1> , len ( lines ) ) : <EOL> outlines . append ( lines [ l ] [ leading : ] ) <EOL> return string . join ( outlines , '<STR_LIT:\n>' ) <EOL> def greedyWrap ( inString , width = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> outLines = [ ] <EOL> if inString . find ( '<STR_LIT>' ) >= <NUM_LIT:0> : <EOL> paragraphs = string . split ( inString , '<STR_LIT>' ) <EOL> for para in paragraphs : <EOL> outLines . extend ( greedyWrap ( para ) + [ '<STR_LIT>' ] ) <EOL> return outLines <EOL> inWords = string . split ( inString ) <EOL> column = <NUM_LIT:0> <EOL> ptr_line = <NUM_LIT:0> <EOL> while inWords : <EOL> column = column + len ( inWords [ ptr_line ] ) <EOL> ptr_line = ptr_line + <NUM_LIT:1> <EOL> if ( column > width ) : <EOL> if ptr_line == <NUM_LIT:1> : <EOL> pass <EOL> else : <EOL> ptr_line = ptr_line - <NUM_LIT:1> <EOL> ( l , inWords ) = ( inWords [ <NUM_LIT:0> : ptr_line ] , inWords [ ptr_line : ] ) <EOL> outLines . append ( string . join ( l , '<STR_LIT:U+0020>' ) ) <EOL> ptr_line = <NUM_LIT:0> <EOL> column = <NUM_LIT:0> <EOL> elif not ( len ( inWords ) > ptr_line ) : <EOL> outLines . append ( string . join ( inWords , '<STR_LIT:U+0020>' ) ) <EOL> del inWords [ : ] <EOL> else : <EOL> column = column + <NUM_LIT:1> <EOL> return outLines <EOL> wordWrap = greedyWrap <EOL> def removeLeadingBlanks ( lines ) : <EOL> ret = [ ] <EOL> for line in lines : <EOL> if ret or line . strip ( ) : <EOL> ret . append ( line ) <EOL> return ret <EOL> def removeLeadingTrailingBlanks ( s ) : <EOL> lines = removeLeadingBlanks ( s . split ( '<STR_LIT:\n>' ) ) <EOL> lines . reverse ( ) <EOL> lines = removeLeadingBlanks ( lines ) <EOL> lines . reverse ( ) <EOL> return '<STR_LIT:\n>' . join ( lines ) + '<STR_LIT:\n>' <EOL> def splitQuoted ( s ) : <EOL> """<STR_LIT>""" <EOL> out = [ ] <EOL> quot = None <EOL> phrase = None <EOL> for word in s . split ( ) : <EOL> if phrase is None : <EOL> if word and ( word [ <NUM_LIT:0> ] in ( "<STR_LIT>" , "<STR_LIT:'>" ) ) : <EOL> quot = word [ <NUM_LIT:0> ] <EOL> word = word [ <NUM_LIT:1> : ] <EOL> phrase = [ ] <EOL> if phrase is None : <EOL> out . append ( word ) <EOL> else : <EOL> if word and ( word [ - <NUM_LIT:1> ] == quot ) : <EOL> word = word [ : - <NUM_LIT:1> ] <EOL> phrase . append ( word ) <EOL> out . append ( "<STR_LIT:U+0020>" . join ( phrase ) ) <EOL> phrase = None <EOL> else : <EOL> phrase . append ( word ) <EOL> return out <EOL> def strFile ( p , f , caseSensitive = True ) : <EOL> """<STR_LIT>""" <EOL> buf = "<STR_LIT>" <EOL> buf_len = max ( len ( p ) , <NUM_LIT:2> ** <NUM_LIT:2> ** <NUM_LIT:2> ** <NUM_LIT:2> ) <EOL> if not caseSensitive : <EOL> p = p . lower ( ) <EOL> while <NUM_LIT:1> : <EOL> r = f . read ( buf_len - len ( p ) ) <EOL> if not caseSensitive : <EOL> r = r . lower ( ) <EOL> bytes_read = len ( r ) <EOL> if bytes_read == <NUM_LIT:0> : <EOL> return False <EOL> l = len ( buf ) + bytes_read - buf_len <EOL> if l <= <NUM_LIT:0> : <EOL> buf = buf + r <EOL> else : <EOL> buf = buf [ l : ] + r <EOL> if buf . find ( p ) != - <NUM_LIT:1> : <EOL> return True </s>
