<s> '''<STR_LIT>''' <EOL> from arelle . webserver . bottle import Bottle , request , response , static_file <EOL> from arelle . Cntlr import LogFormatter <EOL> import os , io , sys , time , threading , uuid <EOL> from arelle import Version <EOL> from arelle . FileSource import FileNamedStringIO <EOL> _os_pid = os . getpid ( ) <EOL> def startWebserver ( _cntlr , options ) : <EOL> """<STR_LIT>""" <EOL> global imagesDir , cntlr , optionsPrototype <EOL> cntlr = _cntlr <EOL> imagesDir = cntlr . imagesDir <EOL> optionValuesTypes = _STR_NUM_TYPES + ( type ( None ) , ) <EOL> optionsPrototype = dict ( ( option , value if isinstance ( value , _STR_NUM_TYPES ) else None ) <EOL> for option in dir ( options ) <EOL> for value in ( getattr ( options , option ) , ) <EOL> if isinstance ( value , optionValuesTypes ) and not option . startswith ( '<STR_LIT:_>' ) ) <EOL> host , sep , portServer = options . webserver . partition ( "<STR_LIT::>" ) <EOL> port , sep , server = portServer . partition ( "<STR_LIT::>" ) <EOL> app = Bottle ( ) <EOL> GETorPOST = ( '<STR_LIT:GET>' , '<STR_LIT:POST>' ) <EOL> GET = '<STR_LIT:GET>' <EOL> POST = '<STR_LIT:POST>' <EOL> app . route ( '<STR_LIT>' , GET , login_form ) <EOL> app . route ( '<STR_LIT>' , POST , login_submit ) <EOL> app . route ( '<STR_LIT>' , GET , logout ) <EOL> app . route ( '<STR_LIT>' , GET , arelleIcon ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GETorPOST , validation ) <EOL> app . route ( '<STR_LIT>' , GET , image ) <EOL> app . route ( '<STR_LIT>' , GET , diff ) <EOL> app . route ( '<STR_LIT>' , GET , configure ) <EOL> app . route ( '<STR_LIT>' , GET , stopWebServer ) <EOL> app . route ( '<STR_LIT>' , POST , quickbooksServer ) <EOL> app . route ( '<STR_LIT>' , GET , quickbooksGLrequest ) <EOL> app . route ( '<STR_LIT>' , GET , quickbooksGLrequest ) <EOL> app . route ( '<STR_LIT>' , GET , quickbooksGLrequest ) <EOL> app . route ( '<STR_LIT>' , GET , quickbooksGLresponse ) <EOL> app . route ( '<STR_LIT>' , GET , quickbooksWebPage ) <EOL> app . route ( '<STR_LIT>' , GET , localhostCertificate ) <EOL> app . route ( '<STR_LIT>' , GET , localhostCertificate ) <EOL> app . route ( '<STR_LIT>' , GET , helpREST ) <EOL> app . route ( '<STR_LIT>' , GET , about ) <EOL> app . route ( '<STR_LIT:/>' , GET , indexPageREST ) <EOL> if server == "<STR_LIT>" : <EOL> app . route ( '<STR_LIT>' , GETorPOST , cgiInterface ) <EOL> if server == "<STR_LIT>" : <EOL> return app <EOL> elif server == "<STR_LIT>" : <EOL> if sys . stdin is None : <EOL> sys . stdin = open ( os . devnull , '<STR_LIT:r>' ) <EOL> app . run ( server = server ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif server : <EOL> app . run ( host = host , port = port or <NUM_LIT> , server = server ) <EOL> else : <EOL> app . run ( host = host , port = port or <NUM_LIT> ) <EOL> def cgiInterface ( cgiAppPath ) : <EOL> if not request . query : <EOL> return indexPageCGI ( ) <EOL> elif '<STR_LIT>' in request . query : <EOL> return about ( cgiAppPath + "<STR_LIT>" ) <EOL> elif '<STR_LIT>' in request . query : <EOL> return helpREST ( ) <EOL> elif '<STR_LIT:image>' in request . query : <EOL> return image ( request . query . image ) <EOL> else : <EOL> return indexPageCGI ( ) <EOL> def login_form ( ) : <EOL> """<STR_LIT>""" <EOL> return _ ( '''<STR_LIT>''' ) <EOL> def login_submit ( ) : <EOL> """<STR_LIT>""" <EOL> name = request . forms . get ( '<STR_LIT:name>' ) <EOL> password = request . forms . get ( '<STR_LIT:password>' ) <EOL> if checkLogin ( name , password ) : <EOL> return _ ( "<STR_LIT>" ) . format ( name ) <EOL> else : <EOL> return _ ( "<STR_LIT>" ) <EOL> def checkLogin ( _user , _password ) : <EOL> """<STR_LIT>""" <EOL> global user <EOL> user = _user <EOL> return True <EOL> def logout ( ) : <EOL> """<STR_LIT>""" <EOL> global user <EOL> user = None <EOL> return _ ( "<STR_LIT>" ) <EOL> def arelleIcon ( ) : <EOL> """<STR_LIT>""" <EOL> return static_file ( "<STR_LIT>" , root = imagesDir , mimetype = '<STR_LIT>' ) <EOL> def image ( imgFile ) : <EOL> """<STR_LIT>""" <EOL> return static_file ( imgFile , root = imagesDir ) <EOL> validationOptions = { <EOL> "<STR_LIT>" : ( "<STR_LIT>" , True ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , None ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , True ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , True ) , <EOL> "<STR_LIT>" : ( "<STR_LIT>" , None ) , <EOL> } <EOL> validationKeyVarName = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> class Options ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> for option , defaultValue in optionsPrototype . items ( ) : <EOL> setattr ( self , option , defaultValue ) <EOL> supportedViews = { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' } <EOL> def validation ( file = None ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> flavor = request . query . flavor or '<STR_LIT>' <EOL> media = request . query . media or '<STR_LIT:html>' <EOL> requestPathParts = request . urlparts [ <NUM_LIT:2> ] . split ( '<STR_LIT:/>' ) <EOL> isValidation = '<STR_LIT>' == requestPathParts [ - <NUM_LIT:1> ] or '<STR_LIT>' == requestPathParts [ - <NUM_LIT:2> ] <EOL> view = request . query . view <EOL> viewArcrole = request . query . viewArcrole <EOL> if request . method == '<STR_LIT:POST>' : <EOL> mimeType = request . get_header ( "<STR_LIT:Content-Type>" ) <EOL> if mimeType . startswith ( "<STR_LIT>" ) : <EOL> _upload = request . files . get ( "<STR_LIT>" ) <EOL> if not _upload or not _upload . filename . endswith ( "<STR_LIT>" ) : <EOL> errors . append ( _ ( "<STR_LIT>" ) ) <EOL> sourceZipStream = None <EOL> else : <EOL> sourceZipStream = _upload . file <EOL> elif mimeType not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( mimeType ) ) <EOL> sourceZipStream = request . body <EOL> else : <EOL> sourceZipStream = None <EOL> if not view and not viewArcrole : <EOL> if requestPathParts [ - <NUM_LIT:1> ] in supportedViews : <EOL> view = requestPathParts [ - <NUM_LIT:1> ] <EOL> if isValidation : <EOL> if view or viewArcrole : <EOL> errors . append ( _ ( "<STR_LIT>" ) ) <EOL> if media not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:html>' , '<STR_LIT>' , '<STR_LIT:text>' ) and not ( sourceZipStream and media == '<STR_LIT>' ) : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( media ) ) <EOL> elif view or viewArcrole : <EOL> if media not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:html>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( media ) ) <EOL> elif requestPathParts [ - <NUM_LIT:1> ] not in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> errors . append ( _ ( "<STR_LIT>" ) ) <EOL> if ( flavor not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> and not flavor . startswith ( '<STR_LIT>' ) and not flavor . startswith ( '<STR_LIT>' ) ) : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( flavor ) ) <EOL> if view and view not in supportedViews : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( view ) ) <EOL> if errors : <EOL> errors . insert ( <NUM_LIT:0> , _ ( "<STR_LIT>" ) + ( file or request . query . file or '<STR_LIT>' ) ) <EOL> return errorReport ( errors , media ) <EOL> options = Options ( ) <EOL> isFormulaOnly = False <EOL> for key , value in request . query . items ( ) : <EOL> if key == "<STR_LIT:file>" : <EOL> setattr ( options , "<STR_LIT>" , value ) <EOL> elif key == "<STR_LIT>" : <EOL> if value . startswith ( "<STR_LIT>" ) or value . startswith ( "<STR_LIT>" ) : <EOL> setattr ( options , "<STR_LIT>" , True ) <EOL> elif value == "<STR_LIT>" : <EOL> isFormulaOnly = True <EOL> setattr ( options , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif value == "<STR_LIT>" : <EOL> isFormulaOnly = True <EOL> setattr ( options , "<STR_LIT>" , "<STR_LIT>" ) <EOL> elif value == "<STR_LIT>" : <EOL> setattr ( options , "<STR_LIT>" , "<STR_LIT:none>" ) <EOL> elif key in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> pass <EOL> elif key in validationOptions : <EOL> optionKey , optionValue = validationOptions [ key ] <EOL> setattr ( options , optionKey , optionValue if optionValue is not None else value ) <EOL> elif key in validationKeyVarName : <EOL> setattr ( options , validationKeyVarName [ key ] , value or True ) <EOL> elif not value : <EOL> setattr ( options , key , True ) <EOL> else : <EOL> setattr ( options , key , value ) <EOL> if file : <EOL> setattr ( options , "<STR_LIT>" , file . replace ( '<STR_LIT:;>' , '<STR_LIT:/>' ) ) <EOL> requestPathParts = set ( request . urlparts [ <NUM_LIT:2> ] . split ( '<STR_LIT:/>' ) ) <EOL> viewFile = None <EOL> if isValidation : <EOL> if not isFormulaOnly : <EOL> setattr ( options , "<STR_LIT>" , True ) <EOL> elif view : <EOL> viewFile = FileNamedStringIO ( media ) <EOL> setattr ( options , view + "<STR_LIT>" , viewFile ) <EOL> elif viewArcrole : <EOL> viewFile = FileNamedStringIO ( media ) <EOL> setattr ( options , "<STR_LIT>" , viewArcrole ) <EOL> setattr ( options , "<STR_LIT>" , viewFile ) <EOL> return runOptionsAndGetResult ( options , media , viewFile , sourceZipStream ) <EOL> def runOptionsAndGetResult ( options , media , viewFile , sourceZipStream = None ) : <EOL> """<STR_LIT>""" <EOL> if media == "<STR_LIT>" and not viewFile : <EOL> responseZipStream = io . BytesIO ( ) <EOL> else : <EOL> responseZipStream = None <EOL> successful = cntlr . run ( options , sourceZipStream , responseZipStream ) <EOL> if media == "<STR_LIT>" : <EOL> response . content_type = '<STR_LIT>' <EOL> elif media == "<STR_LIT>" : <EOL> response . content_type = '<STR_LIT>' <EOL> elif media == "<STR_LIT>" : <EOL> response . content_type = '<STR_LIT>' <EOL> elif media == "<STR_LIT:text>" : <EOL> response . content_type = '<STR_LIT>' <EOL> elif media == "<STR_LIT>" : <EOL> response . content_type = '<STR_LIT>' <EOL> else : <EOL> response . content_type = '<STR_LIT>' <EOL> if successful and viewFile : <EOL> result = viewFile . getvalue ( ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) . replace ( "<STR_LIT>" , "<STR_LIT:&>" ) <EOL> viewFile . close ( ) <EOL> elif media == "<STR_LIT>" : <EOL> responseZipStream . seek ( <NUM_LIT:0> ) <EOL> result = responseZipStream . read ( ) <EOL> responseZipStream . close ( ) <EOL> cntlr . logHandler . clearLogBuffer ( ) <EOL> elif media == "<STR_LIT>" : <EOL> result = cntlr . logHandler . getXml ( ) <EOL> elif media == "<STR_LIT>" : <EOL> result = cntlr . logHandler . getJson ( ) <EOL> elif media == "<STR_LIT:text>" : <EOL> _logFormat = request . query . logFormat <EOL> if _logFormat : <EOL> _stdLogFormatter = cntlr . logHandler . formatter <EOL> cntlr . logHandler . formatter = LogFormatter ( _logFormat ) <EOL> result = cntlr . logHandler . getText ( ) <EOL> if _logFormat : <EOL> cntlr . logHandler . formatter = _stdLogFormatter <EOL> del _stdLogFormatter <EOL> else : <EOL> result = htmlBody ( tableRows ( cntlr . logHandler . getLines ( ) , header = _ ( "<STR_LIT>" ) ) ) <EOL> return result <EOL> def diff ( ) : <EOL> """<STR_LIT>""" <EOL> if not request . query . fromDTS or not request . query . toDTS or not request . query . report : <EOL> return _ ( "<STR_LIT>" ) <EOL> options = Options ( ) <EOL> setattr ( options , "<STR_LIT>" , request . query . fromDTS ) <EOL> setattr ( options , "<STR_LIT>" , request . query . toDTS ) <EOL> fh = FileNamedStringIO ( request . query . report ) <EOL> setattr ( options , "<STR_LIT>" , fh ) <EOL> cntlr . run ( options ) <EOL> reportContents = fh . getvalue ( ) <EOL> fh . close ( ) <EOL> response . content_type = '<STR_LIT>' <EOL> return reportContents <EOL> def configure ( ) : <EOL> """<STR_LIT>""" <EOL> if not request . query . proxy and not request . query . plugins and not request . query . packages and '<STR_LIT>' not in request . query : <EOL> return _ ( "<STR_LIT>" ) <EOL> options = Options ( ) <EOL> if request . query . proxy : <EOL> setattr ( options , "<STR_LIT>" , request . query . proxy ) <EOL> if request . query . plugins : <EOL> setattr ( options , "<STR_LIT>" , request . query . plugins ) <EOL> if request . query . packages : <EOL> setattr ( options , "<STR_LIT>" , request . query . packages ) <EOL> if '<STR_LIT>' in request . query : <EOL> setattr ( options , "<STR_LIT>" , True ) <EOL> cntlr . run ( options ) <EOL> response . content_type = '<STR_LIT>' <EOL> return htmlBody ( tableRows ( cntlr . logHandler . getLines ( ) , header = _ ( "<STR_LIT>" ) ) ) <EOL> def stopWebServer ( ) : <EOL> """<STR_LIT>""" <EOL> def stopSoon ( delaySeconds ) : <EOL> time . sleep ( delaySeconds ) <EOL> import signal <EOL> os . kill ( _os_pid , signal . SIGTERM ) <EOL> thread = threading . Thread ( target = lambda : stopSoon ( <NUM_LIT> ) ) <EOL> thread . daemon = True <EOL> thread . start ( ) <EOL> response . content_type = '<STR_LIT>' <EOL> return htmlBody ( tableRows ( ( time . strftime ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" , ) , <EOL> header = _ ( "<STR_LIT>" ) ) ) <EOL> def quickbooksServer ( ) : <EOL> """<STR_LIT>""" <EOL> from arelle import CntlrQuickBooks <EOL> response . content_type = '<STR_LIT>' <EOL> return CntlrQuickBooks . server ( cntlr , request . body , request . urlparts ) <EOL> def quickbooksGLrequest ( qbReport = None , file = None ) : <EOL> """<STR_LIT>""" <EOL> from arelle . CntlrQuickBooks import supportedQbReports , qbRequest <EOL> from arelle . ModelValue import dateTime <EOL> errors = [ ] <EOL> requestPathParts = request . urlparts [ <NUM_LIT:2> ] . split ( '<STR_LIT:/>' ) <EOL> viewRequested = "<STR_LIT>" == requestPathParts [ - <NUM_LIT:1> ] <EOL> media = request . query . media or '<STR_LIT:html>' <EOL> fromDate = request . query . fromDate <EOL> toDate = request . query . toDate <EOL> if qbReport not in supportedQbReports : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( <EOL> qbReport , '<STR_LIT:U+002CU+0020>' . join ( supportedQbReports ) ) ) <EOL> if media not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:html>' ) : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( media ) ) <EOL> if not fromDate or dateTime ( fromDate ) is None : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( fromDate ) ) <EOL> if not toDate or dateTime ( toDate ) is None : <EOL> errors . append ( _ ( "<STR_LIT>" ) . format ( toDate ) ) <EOL> if errors : <EOL> return errorReport ( errors , media ) <EOL> ticket = qbRequest ( qbReport , fromDate , toDate , file ) <EOL> result = htmlBody ( tableRows ( [ _ ( "<STR_LIT>" ) ] , header = _ ( "<STR_LIT>" ) ) , script = '''<STR_LIT>''' . format ( ticket , media , viewRequested ) ) <EOL> return result <EOL> def quickbooksGLresponse ( ) : <EOL> """<STR_LIT>""" <EOL> from arelle import CntlrQuickBooks <EOL> ticket = request . query . ticket <EOL> media = request . query . media <EOL> viewRequested = request . query . view <EOL> status = CntlrQuickBooks . qbRequestStatus . get ( ticket ) <EOL> if not status : <EOL> return htmlBody ( tableRows ( [ _ ( "<STR_LIT>" ) ] , header = _ ( "<STR_LIT>" ) ) ) <EOL> if status . startswith ( "<STR_LIT>" ) : <EOL> CntlrQuickBooks . qbRequestStatus . pop ( ticket , None ) <EOL> return errorReport ( [ status [ <NUM_LIT> : ] ] , media ) <EOL> if status != "<STR_LIT>" or ticket not in CntlrQuickBooks . xbrlInstances : <EOL> return htmlBody ( tableRows ( [ _ ( "<STR_LIT>" ) . format ( status ) ] , <EOL> header = _ ( "<STR_LIT>" ) ) , <EOL> script = '''<STR_LIT>''' ) <EOL> CntlrQuickBooks . qbRequestStatus . pop ( ticket ) <EOL> instanceUuid = CntlrQuickBooks . xbrlInstances [ ticket ] <EOL> CntlrQuickBooks . xbrlInstances . pop ( ticket ) <EOL> options = Options ( ) <EOL> setattr ( options , "<STR_LIT>" , instanceUuid ) <EOL> viewFile = FileNamedStringIO ( media ) <EOL> setattr ( options , "<STR_LIT>" , viewFile ) <EOL> return runOptionsAndGetResult ( options , media , viewFile ) <EOL> def quickbooksWebPage ( ) : <EOL> return htmlBody ( _ ( '''<STR_LIT>''' ) ) <EOL> def localhostCertificate ( ) : <EOL> """<STR_LIT>""" <EOL> return '''<STR_LIT>''' <EOL> def helpREST ( ) : <EOL> """<STR_LIT>""" <EOL> return htmlBody ( _ ( '''<STR_LIT>''' ) + <EOL> ( _ ( '''<STR_LIT>''' ) <EOL> if cntlr . isGAE else <EOL> _ ( '''<STR_LIT>''' ) ) + <EOL> _ ( '''<STR_LIT>''' ) + <EOL> ( _ ( '''<STR_LIT>''' ) if cntlr . isGAE else '<STR_LIT>' ) + <EOL> '<STR_LIT>' ) <EOL> def about ( arelleImgFile = None ) : <EOL> from lxml import etree <EOL> """<STR_LIT>""" <EOL> return htmlBody ( _ ( '''<STR_LIT>''' ) % ( arelleImgFile or '<STR_LIT>' , <EOL> cntlr . __version__ , <EOL> cntlr . systemWordSize , <EOL> Version . version , <EOL> sys . version_info [ <NUM_LIT:0> ] , sys . version_info [ <NUM_LIT:1> ] , sys . version_info [ <NUM_LIT:2> ] , <EOL> etree . LXML_VERSION [ <NUM_LIT:0> ] , etree . LXML_VERSION [ <NUM_LIT:1> ] , etree . LXML_VERSION [ <NUM_LIT:2> ] ) ) <EOL> def indexPageREST ( ) : <EOL> """<STR_LIT>""" <EOL> return htmlBody ( _ ( '''<STR_LIT>''' ) ) <EOL> def indexPageCGI ( ) : <EOL> """<STR_LIT>""" <EOL> return htmlBody ( _ ( '''<STR_LIT>''' ) ) <EOL> def htmlBody ( body , script = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> return '''<STR_LIT>''' % ( script , body ) <EOL> def tableRows ( lines , header = None ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( <EOL> ( "<STR_LIT>" % header if header else "<STR_LIT>" ) + <EOL> "<STR_LIT:\n>" . join ( "<STR_LIT>" % line . replace ( "<STR_LIT:&>" , "<STR_LIT>" ) . replace ( "<STR_LIT:<>" , "<STR_LIT>" ) for line in lines ) ) <EOL> def errorReport ( errors , media = "<STR_LIT:html>" ) : <EOL> """<STR_LIT>""" <EOL> if media == "<STR_LIT:text>" : <EOL> response . content_type = '<STR_LIT>' <EOL> return '<STR_LIT:\n>' . join ( errors ) <EOL> else : <EOL> response . content_type = '<STR_LIT>' <EOL> return htmlBody ( tableRows ( errors , header = _ ( "<STR_LIT>" ) ) ) <EOL> def multipartResponse ( parts ) : <EOL> boundary = '<STR_LIT>' % ( uuid . uuid1 ( ) , ) <EOL> response . content_type = '<STR_LIT>' % ( boundary , ) <EOL> buf = [ ] <EOL> for filename , contentType , content in parts : <EOL> buf . append ( "<STR_LIT:\r\n>" + boundary + "<STR_LIT:\r\n>" ) <EOL> buf . append ( '<STR_LIT>' . format ( filename ) ) <EOL> buf . append ( '<STR_LIT>' . format ( contentType ) ) <EOL> buf . append ( '<STR_LIT>' . format ( len ( content ) ) ) <EOL> buf . append ( '<STR_LIT:\r\n>' ) <EOL> buf . append ( content ) <EOL> buf . append ( "<STR_LIT:\r\n>" + boundary + "<STR_LIT:\r\n>" ) <EOL> s = '<STR_LIT>' . join ( buf ) <EOL> response . content_length = len ( s ) <EOL> return s </s>
