本文整理汇总了Python中MaKaC.accessControl.AccessWrapper.setSession方法的典型用法代码示例。如果您正苦于以下问题:Python AccessWrapper.setSession方法的具体用法?Python AccessWrapper.setSession怎么用?Python AccessWrapper.setSession使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaKaC.accessControl.AccessWrapper
的用法示例。
在下文中一共展示了AccessWrapper.setSession方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ServiceBase
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setSession [as 别名]
class ServiceBase(RequestHandlerBase):
"""
The ServiceBase class is the basic class for services.
"""
def __init__(self, params, session, req):
"""
Constructor. Initializes provate variables
@param req: HTTP Request provided by the previous layer
"""
RequestHandlerBase.__init__(self, req)
self._reqParams = self._params = params
self._requestStarted = False
self._websession = session
# Fill in the aw instance with the current information
self._aw = AccessWrapper()
self._aw.setIP(self.getHostIP())
self._aw.setSession(session)
self._aw.setUser(session.getUser())
self._target = None
self._startTime = None
self._tohttps = self._req.is_https()
self._endTime = None
self._doProcess = True #Flag which indicates whether the RH process
# must be carried out; this is useful for
# the checkProtection methods
self._tempFilesToDelete = []
# Methods =============================================================
def _getSession( self ):
"""
Returns the web session associated to the received mod_python
request.
"""
return self._websession
def _checkParams(self):
"""
Checks the request parameters (normally overloaded)
"""
pass
def _checkProtection( self ):
"""
Checks protection when accessing resources (normally overloaded)
"""
pass
def _processError(self):
"""
Treats errors occured during the process of a RH, returning an error string.
@param e: the exception
@type e: An Exception-derived type
"""
trace = traceback.format_exception(*sys.exc_info())
return ''.join(trace)
def _deleteTempFiles( self ):
if len(self._tempFilesToDelete) > 0:
for file in self._tempFilesToDelete:
os.remove(file)
def process(self):
"""
Processes the request, analyzing the parameters, and feeding them to the
_getAnswer() method (implemented by derived classes)
"""
ContextManager.set('currentRH', self)
self._setLang()
self._checkParams()
self._checkProtection()
try:
security.Sanitization.sanitizationCheck(self._target,
self._params,
self._aw)
except (HtmlScriptError, HtmlForbiddenTag), e:
raise HTMLSecurityError('ERR-X0','HTML Security problem. %s ' % str(e))
if self._doProcess:
if Config.getInstance().getProfile():
import profile, pstats, random
proffilename = os.path.join(Config.getInstance().getTempDir(), "service%s.prof" % random.random())
result = [None]
profile.runctx("result[0] = self._getAnswer()", globals(), locals(), proffilename)
answer = result[0]
rep = Config.getInstance().getTempDir()
stats = pstats.Stats(proffilename)
stats.strip_dirs()
stats.sort_stats('cumulative', 'time', 'calls')
stats.dump_stats(os.path.join(rep, "IndicoServiceRequestProfile.log"))
os.remove(proffilename)
else:
answer = self._getAnswer()
self._deleteTempFiles()
#.........这里部分代码省略.........
示例2: RH
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setSession [as 别名]
class RH(RequestHandlerBase):
"""This class is the base for request handlers of the application. A request
handler will be instantiated when a web request arrives to mod_python;
the mp layer will forward the request to the corresponding request
handler which will know which action has to be performed (displaying a
web page or performing some operation and redirecting to another page).
Request handlers will be responsible for parsing the parameters coming
from a mod_python request, handle the errors which occurred during the
action to perform, managing the sessions, checking security for each
operation (thus they implement the access control system of the web
interface).
It is important to encapsulate all this here as in case of changing
the web application framework we'll just need to adapt this layer (the
rest of the system wouldn't need any change).
Attributes:
_uh - (URLHandler) Associated URLHandler which points to the
current rh.
_req - (mod_python.Request) mod_python request received for the
current rh.
_requestStarted - (bool) Flag which tells whether a DB transaction
has been started or not.
_websession - ( webinterface.session.sessionManagement.PSession )
Web session associated to the HTTP request.
_aw - (AccessWrapper) Current access information for the rh.
_target - (Locable) Reference to an object which is the destination
of the operations needed to carry out the rh. If set it must
provide (through the standard Locable interface) the methods
to get the url parameters in order to reproduce the access to
the rh.
_reqParams - (dict) Dictionary containing the received HTTP
parameters (independently of the method) transformed into
python data types. The key is the parameter name while the
value should be the received paramter value (or values).
"""
_tohttps = False # set this value to True for the RH that must be HTTPS when there is a BaseSecureURL
_doNotSanitizeFields = []
def __init__( self, req ):
"""Constructor. Initialises the rh setting up basic attributes so it is
able to process the request.
Parameters:
req - (mod_python.Request) mod_python request received for the
current rh.
"""
RequestHandlerBase.__init__(self, req)
self._requestStarted = False
self._websession = None
self._aw = AccessWrapper() #Fill in the aw instance with the current information
self._target = None
self._reqParams = {}
self._startTime = None
self._endTime = None
self._tempFilesToDelete = []
self._doProcess = True #Flag which indicates whether the RH process
# must be carried out; this is useful for
# the checkProtection methods when they
# detect that an inmediate redirection is
# needed
# Methods =============================================================
def getTarget( self ):
return self._target
def _setSession( self ):
"""Sets up a reference to the corresponding web session. It uses the
session manager to retrieve the session corresponding to the
received request and makes sure it is a valid one. In case of having
an invalid session it reset client settings and creates a new one.
"""
if not self._websession:
sm = session.getSessionManager()
try:
self._websession = sm.get_session( self._req )
except session.SessionError:
sm.revoke_session_cookie( self._req )
self._websession = sm.get_session( self._req )
def _getSession( self ):
"""Returns the web session associated to the received mod_python
request.
"""
if not self._websession:
self._setSession()
return self._websession
def _setSessionUser( self ):
"""
"""
self._aw.setUser( self._getSession().getUser() )
def _getRequestParams( self ):
return self._reqParams
def getRequestParams( self ):
return self._getRequestParams()
def _disableCaching(self):
#.........这里部分代码省略.........
示例3: ServiceBase
# 需要导入模块: from MaKaC.accessControl import AccessWrapper [as 别名]
# 或者: from MaKaC.accessControl.AccessWrapper import setSession [as 别名]
class ServiceBase(RequestHandlerBase):
"""
The ServiceBase class is the basic class for services.
"""
def __init__(self, params, remoteHost, session):
"""
Constructor. Initializes provate variables
@param req: HTTP Request provided by the previous layer
"""
self._params = params
self._requestStarted = False
self._websession = session
# Fill in the aw instance with the current information
self._aw = AccessWrapper()
self._aw.setIP(remoteHost)
self._aw.setSession(session)
self._aw.setUser(session.getUser())
self._target = None
self._startTime = None
self._endTime = None
self._doProcess = True #Flag which indicates whether the RH process
# must be carried out; this is useful for
# the checkProtection methods
self._tempFilesToDelete = []
# Methods =============================================================
def _getSession( self ):
"""
Returns the web session associated to the received mod_python
request.
"""
return self._websession
def _checkParams(self):
"""
Checks the request parameters (normally overloaded)
"""
pass
def _checkProtection( self ):
"""
Checks protection when accessing resources (normally overloaded)
"""
pass
def _processError(self):
"""
Treats errors occured during the process of a RH, returning an error string.
@param e: the exception
@type e: An Exception-derived type
"""
trace = traceback.format_exception(*sys.exc_info())
return ''.join(trace)
def _sendEmails( self ):
if hasattr( self, "_emailsToBeSent" ):
for email in self._emailsToBeSent:
GenericMailer.send(GenericNotification(email))
def _deleteTempFiles( self ):
if len(self._tempFilesToDelete) > 0:
for file in self._tempFilesToDelete:
os.remove(file)
def process(self):
"""
Processes the request, analyzing the parameters, and feeding them to the
_getAnswer() method (implemented by derived classes)
"""
self._setLang()
self._checkParams()
self._checkProtection()
try:
security.sanitizationCheck(self._target,
self._params,
self._aw)
except (htmlScriptError, htmlForbiddenTag), e:
raise HTMLSecurityError('ERR-X0','HTML Security problem - you might be using forbidden tags: %s ' % str(e))
if self._doProcess:
answer = self._getAnswer()
self._sendEmails()
self._deleteTempFiles()
return answer