Example #1
0
def application(environ, start_response):
    path = environ.get('PATH_INFO', '').lstrip('/')
    for regex, controller in urls:
        match = re.search(regex, path)
        if match:
            request = Request(environ)
            try:
                postgres_handle = PostgresHandle(smarttypes.connection_string)
                try:
                    session = None
                    if request.cookies.get('session'):
                        session = TwitterSession.get_by_request_key(
                            request.cookies['session'], postgres_handle)
                    response_dict = controller(request, session,
                                               postgres_handle)
                    web_response = WebResponse(request, controller.__name__,
                                               response_dict, session)
                    response_headers = web_response.get_response_headers()
                    response_string = web_response.get_response_str()
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.commit()
                    status_code = '200 OK'
                except RedirectException, (redirect_ex):
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.commit()
                    status_code = '303 See Other'
                    response_headers = [('Location', redirect_ex.redirect_url)]
                    response_string = [""]
                except:
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.rollback()
                    raise
                finally:
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.close()

                #start response
                start_response(status_code, response_headers)
                return response_string

            except Exception:
                #can't use print statements with mod_wsgi
                error_string = traceback.format_exc()
                start_response('500 Internal Server Error',
                               [('Content-Type', 'text/plain')])
                if smarttypes.config.IS_PROD:
                    email_utils.send_email(
                        '*****@*****.**',
                        ['*****@*****.**', '*****@*****.**'],
                        error_string, 'smarttypes site error')
                return [error_string]
Example #2
0
def application(environ, start_response):
    path = environ.get('PATH_INFO', '').lstrip('/')
    for regex, controller in urls:
        match = re.search(regex, path)
        if match:
            request = Request(environ)
            try:
                postgres_handle = PostgresHandle(smarttypes.connection_string)
                try:
                    session = None
                    if request.cookies.get('session'):
                        session = TwitterSession.get_by_request_key(request.cookies['session'], postgres_handle)
                    response_dict = controller(request, session, postgres_handle)
                    web_response = WebResponse(request, controller.__name__, response_dict, session)
                    response_headers = web_response.get_response_headers()
                    response_string = web_response.get_response_str()
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.commit()
                    status_code = '200 OK'
                except RedirectException, (redirect_ex):
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.commit()
                    status_code = '303 See Other'
                    response_headers = [('Location', redirect_ex.redirect_url)]
                    response_string = [""]
                except:
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.rollback()
                    raise
                finally:
                    if getattr(postgres_handle, '_connection', False):
                        postgres_handle.connection.close()

                #start response
                start_response(status_code, response_headers)
                return response_string

            except Exception:
                #can't use print statements with mod_wsgi
                error_string = traceback.format_exc()
                start_response('500 Internal Server Error', [('Content-Type', 'text/plain')])
                if smarttypes.config.IS_PROD:
                    email_utils.send_email('*****@*****.**',
                        ['*****@*****.**', '*****@*****.**'],
                        error_string, 'smarttypes site error')
                return [error_string]
 def wrapper1(request):
     postgres_handle = PostgresHandle(smarttypes.connection_string)
     PostgresBaseModel.postgres_handle = postgres_handle
     try: 
         response_dict = controller(request)
         web_response = WebResponse(request, controller.__name__, response_dict)
         response_headers = web_response.get_response_headers()
         response_string = web_response.get_response_str()
         if getattr(postgres_handle, '_connection', False):
             postgres_handle.connection.commit()
         status_code = '200 OK'
         
     except RedirectException, (redirect_ex):                
         if getattr(postgres_handle, '_connection', False):
             postgres_handle.connection.commit()
         status_code = '303 See Other'
         response_headers = [('Location', redirect_ex.redirect_url)]
         response_string = [""]