<s> import sys <EOL> import os <EOL> from lib . arecibo import post , postaddress <EOL> from App . config import getConfiguration <EOL> from AccessControl import getSecurityManager <EOL> from ZODB . POSException import ConflictError <EOL> from clearwind . arecibo . interfaces import IAreciboConfiguration <EOL> from logging import getLogger <EOL> log = getLogger ( '<STR_LIT>' ) <EOL> headers = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> try : <EOL> import site_configuration <EOL> from site_configuration import config <EOL> log . info ( "<STR_LIT>" % os . path . abspath ( site_configuration . __file__ ) ) <EOL> except : <EOL> config = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:http>" , <EOL> "<STR_LIT>" : { <EOL> <NUM_LIT> : <NUM_LIT:5> , <EOL> <NUM_LIT> : <NUM_LIT:3> , <EOL> <NUM_LIT> : <NUM_LIT:1> , <EOL> } , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , ] <EOL> } <EOL> def get ( context ) : <EOL> cfg = config . copy ( ) <EOL> qu = context . getSiteManager ( ) . queryUtility ( IAreciboConfiguration , name = '<STR_LIT>' ) <EOL> if not qu : <EOL> return cfg <EOL> if qu . account_number : <EOL> cfg [ "<STR_LIT>" ] = qu . account_number <EOL> if qu . transport == "<STR_LIT>" : <EOL> cfg [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> return cfg <EOL> def arecibo ( context , ** kw ) : <EOL> cfg = get ( context ) <EOL> if kw . get ( "<STR_LIT>" ) in cfg [ "<STR_LIT>" ] : <EOL> return <EOL> if not cfg [ "<STR_LIT>" ] : <EOL> msg = "<STR_LIT>" <EOL> log . error ( '<STR_LIT>' , msg ) <EOL> return <EOL> req = context . REQUEST <EOL> error = post ( ) <EOL> mail_possible = not not context . MailHost . smtp_host <EOL> if mail_possible and cfg [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> error . transport = "<STR_LIT>" <EOL> if kw . get ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> status = <NUM_LIT> <EOL> elif kw . get ( "<STR_LIT>" ) == '<STR_LIT>' : <EOL> status = <NUM_LIT> <EOL> else : <EOL> status = <NUM_LIT> <EOL> priority = cfg [ "<STR_LIT>" ] . get ( status , cfg [ "<STR_LIT>" ] ) <EOL> error . set ( "<STR_LIT>" , cfg [ "<STR_LIT>" ] ) <EOL> error . set ( "<STR_LIT>" , priority ) <EOL> error . set ( "<STR_LIT>" , req . get ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> if req . get ( "<STR_LIT>" ) : <EOL> error . set ( "<STR_LIT:url>" , "<STR_LIT>" % ( req [ '<STR_LIT>' ] , req [ '<STR_LIT>' ] ) ) <EOL> else : <EOL> error . set ( "<STR_LIT:url>" , req [ '<STR_LIT>' ] ) <EOL> if kw . get ( "<STR_LIT>" ) : <EOL> error . set ( "<STR_LIT>" , kw . get ( "<STR_LIT>" ) ) <EOL> error . set ( "<STR_LIT>" , req . get ( "<STR_LIT>" , req . get ( '<STR_LIT>' , '<STR_LIT>' ) ) ) <EOL> error . set ( "<STR_LIT:type>" , kw . get ( "<STR_LIT>" ) ) <EOL> error . set ( "<STR_LIT:status>" , status ) <EOL> error . set ( "<STR_LIT>" , "<STR_LIT:\n>" . join ( [ "<STR_LIT>" % ( k , req [ k ] ) for k in headers if req . get ( k ) ] ) ) <EOL> if status != <NUM_LIT> : <EOL> error . set ( "<STR_LIT>" , kw . get ( "<STR_LIT>" ) ) <EOL> usr = getSecurityManager ( ) . getUser ( ) <EOL> error . set ( "<STR_LIT:username>" , "<STR_LIT>" % ( usr . getId ( ) , usr . getUserName ( ) ) ) <EOL> error . set ( "<STR_LIT>" , kw . get ( "<STR_LIT>" ) ) <EOL> if error . transport == "<STR_LIT:http>" : <EOL> try : <EOL> error . send ( ) <EOL> except ConflictError : <EOL> raise <EOL> except : <EOL> exctype , value = sys . exc_info ( ) [ : <NUM_LIT:2> ] <EOL> msg = "<STR_LIT>" % ( exctype , value ) <EOL> log . error ( '<STR_LIT>' , msg ) <EOL> elif error . transport == "<STR_LIT>" : <EOL> try : <EOL> context . MailHost . send ( error . _msg_body ( ) ) <EOL> except ConflictError : <EOL> raise <EOL> except : <EOL> exctype , value = sys . exc_info ( ) [ : <NUM_LIT:2> ] <EOL> msg = "<STR_LIT>" % ( exctype , value ) <EOL> log . error ( '<STR_LIT>' , msg ) </s>
