Ejemplo n.º 1
0
class RequestWrapper:
    """This class implements a HTTP request which is compatible with Quixote's
       session management system. It builds a wrapper arround mod_python request
       objects to adapt it to Quixote's classes.
       Intance attributes:
            __request: MPRequest
                Reference to the wrapped mod_python request object
            cookies: Dictionary
                Conatins the received cookies (these found in headers_in)
                indexed by the cookie name
            environ: Dictionary
                Contains a list of different variables or parameters of the
                HTTP request
            response: ResponseWrapper
                Reference to the HTTP response wrapping object
            session: Session
                Refence to the current session associated with the request,
                if any
    """
    def __init__(self, request):
        """Constructor of the class. Initialises the necessesary values. It
            should never be used, use getWrapper method instead.
        """
        self.__request = request
        try:
            self.cookies = parse_cookie(self.__request.headers_in["Cookie"])
        except KeyError, e:
            self.cookies = {}
        self.environ = {"REMOTE_ADDR": _get_remote_ip(request)}
        self.response = ResponseWrapper(request)
        try:
            self.session = request.session
        except AttributeError, e:
            self.session = None
Ejemplo n.º 2
0
def index(req, **params):

    DBMgr.getInstance().startRequest()
    Factory.getDALManager().connect()

    ################### checking protection ###################

    # check if it is a machine that belongs to the CERN domain
    cernDomain = DomainHolder().getById(0) # id 0 means CERN
    if not cernDomain.belongsTo(_get_remote_ip(req)):
        return "Only CERN users can access to this export resource"

    ################### checking params ###################
    if not (params.has_key("sd") and params.has_key("ed") and params.has_key("r")):
        return """Missing parameters. The request should be like this: http://indico.cern.ch/exportReservations.py?sd=2010-09-24&ed=2010-09-25&r=1,18,114,42"""

    try:
        sd = parseDate(params.get("sd"), "%Y-%m-%d")
        ed = parseDate(params.get("ed"), "%Y-%m-%d")
    except ValueError, e:
        return """The format for the dates (sd and ed) must be like this: YYYY-MM-DD"""
Ejemplo n.º 3
0
def index(req, **params):

    DBMgr.getInstance().startRequest()
    Factory.getDALManager().connect()

    ################### checking protection ###################

    # check if it is a machine that belongs to the CERN domain
    cernDomain = DomainHolder().getById(0)  # id 0 means CERN
    if not cernDomain.belongsTo(_get_remote_ip(req)):
        return "Only CERN users can access to this export resource"

    ################### checking params ###################
    if not (params.has_key("sd") and params.has_key("ed")
            and params.has_key("r")):
        return """Missing parameters. The request should be like this: http://indico.cern.ch/exportReservations.py?sd=2010-09-24&ed=2010-09-25&r=1,18,114,42"""

    try:
        sd = parseDate(params.get("sd"), "%Y-%m-%d")
        ed = parseDate(params.get("ed"), "%Y-%m-%d")
    except ValueError, e:
        return """The format for the dates (sd and ed) must be like this: YYYY-MM-DD"""
Ejemplo n.º 4
0
 def getHostIP(self):
     return _get_remote_ip(self._req)
Ejemplo n.º 5
0
            req.status = e.getCode()
            if req.status == apache.HTTP_METHOD_NOT_ALLOWED:
                req.headers_out['Allow'] = 'GET' if req.method == 'POST' else 'POST'

    if result is None and error is None:
        # TODO: usage page
        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
    else:
        if ak and error is None:
            # Commit only if there was an API key and no error
            for _retry in xrange(10):
                dbi.sync()
                if minfo.getRoomBookingModuleActive():
                    Factory.getDALManager().sync()
                normPath, normQuery = normalizeQuery(path, query, remove=('signature', 'timestamp'), separate=True)
                ak.used(_get_remote_ip(req), normPath, normQuery, not onlyPublic)
                try:
                    if minfo.getRoomBookingModuleActive():
                        Factory.getDALManager().disconnect()
                    dbi.endRequest(True)
                except ConflictError:
                    pass # retry
                else:
                    break
        else:
            # No need to commit stuff if we didn't use an API key
            # (nothing was written)
            if minfo.getRoomBookingModuleActive():
                Factory.getDALManager().rollback()
                Factory.getDALManager().disconnect()
            dbi.endRequest(False)
Ejemplo n.º 6
0
 if result is None and error is None:
     # TODO: usage page
     raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
 else:
     if ak and error is None:
         # Commit only if there was an API key and no error
         for _retry in xrange(10):
             dbi.sync()
             if minfo.getRoomBookingModuleActive():
                 Factory.getDALManager().sync()
             normPath, normQuery = normalizeQuery(path,
                                                  query,
                                                  remove=('signature',
                                                          'timestamp'),
                                                  separate=True)
             ak.used(_get_remote_ip(req), normPath, normQuery,
                     not onlyPublic)
             try:
                 if minfo.getRoomBookingModuleActive():
                     Factory.getDALManager().disconnect()
                 dbi.endRequest(True)
             except ConflictError:
                 pass  # retry
             else:
                 break
     else:
         # No need to commit stuff if we didn't use an API key
         # (nothing was written)
         if minfo.getRoomBookingModuleActive():
             Factory.getDALManager().rollback()
             Factory.getDALManager().disconnect()
Ejemplo n.º 7
0
 def getHostIP(self):
     return _get_remote_ip(self._req)