当前位置: 首页>>代码示例>>Python>>正文


Python util.redirect函数代码示例

本文整理汇总了Python中mod_python.util.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了redirect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

def index(req):
 # check if cookie is set for respondent who already participated
 client_cookie = Cookie.get_cookie(req, 'rm-group-a')
 if client_cookie is None:
  Cookie.add_cookie(req, 'rm-group-a', 'true', expires=time.time()+31*24*3600) # expires after 1 month
 else:
  return 'You already participated.'
 
 # load current respondent conditions
 with open(PATH, 'r') as f:
  respondents = yaml.load(f)
  if respondents is None:
   respondents = []

  no_avatar_count = count_str_in_seq(NO_AVATAR, respondents)
  avatar_count = count_str_in_seq(AVATAR, respondents)

  if no_avatar_count <= MIN_RESPONDENTS and avatar_count >= MIN_RESPONDENTS:
   condition = NO_AVATAR
  elif no_avatar_count >= MIN_RESPONDENTS and avatar_count <= MIN_RESPONDENTS:
   condition = AVATAR
  else:
   condition = random.choice([NO_AVATAR, AVATAR])
 
 # write new condition entry
 with open(PATH, 'w') as f:
  respondents.append(condition)
  yaml.dump(respondents, f)
 util.redirect(req, 'welcome' + '-' + condition + '.html')
开发者ID:mchlbrnd,项目名称:rm-group-a,代码行数:29,代码来源:randomize.py

示例2: GetImage

def GetImage(req, dsname):
    req.content_type = "image/gif"
    req.send_http_header()

    directory = os.path.dirname(req.filename)
    infofile = os.path.join(directory,'info_files/' + dsname )

    try:
        info = open(infofile , 'r')

        status = str(info.readline())[0:-1]
        info.close()

        if status=='GOOD':
            util.redirect(req, '../img/green.gif')
        elif status=='BAD':
            util.redirect(req, '../img/red.gif')
        elif status=='DUBIOUS':
            util.redirect(req, '../img/yellow.gif')
        else:
            util.redirect(req, '../img/blue.gif')
    except IOError:
        util.redirect(req, '../img/white.gif')

    return apache.OK
开发者ID:ETHZ,项目名称:ASCore,代码行数:25,代码来源:FormHandler.py

示例3: addfield

def addfield(req,pagelet,field):
	
	system = getSystem()
	
	system.addField(pagelet,Field(field))
	setSystem(system)
	util.redirect(req,"/pantoto-research/pagelets.py")
开发者ID:ankur1990,项目名称:impl,代码行数:7,代码来源:pagelets.py

示例4: index

def index(req):
	"""Näytä kirjautumislomake tai tarkista ohjaa etusivulle jos löytyy kelvolliset kirjautumistiedot."""
	dom = minidom.parse(htmlpath)

	# Jos login-lomakkeen tiedot pyynnössä mukana, tehdään tarkistukset.
	if req.form.getfirst("submit") != None:
		tunnus = req.form.getfirst("tunnus", "")
		salasana = req.form.getfirst("salasana", "")
		virhe = dbutil.verify(tunnus, salasana)
		# Tallennetaan kirjautuminen ja ohjataan etusivulle jos tiedot ok.
		if virhe == 0:
			req.session["kirjautunut"] = "1"
			req.session.save()
			modutil.redirect(req, "index.py")
		# Ilmoitetaan virheistä, jos tiedot väärin.
		if virhe == 1:
			msg = u"Virheellinen salasana!"
		else:
			msg = u"Käyttäjätunnusta ei löydy!"
		dom_errmsg = domutil.getContentElementById("error_text", dom)
		dom_p = dom.createElement("p")
		dom_errmsg.appendChild(dom_p)
		dom_p.appendChild(dom.createTextNode(msg))

	req.content_type = "application/xhtml+xml; charset=utf-8"

	html = dom.toxml("utf-8")
	return html
开发者ID:sosmo,项目名称:koodinaytteet,代码行数:28,代码来源:login.py

示例5: logout

def logout(req):

#    util.redirect(req,"../testValue.py/testvalue?test="+repr(req.form))
    config=getConfig(req,req.form['dbname'].value)
    action=req.form['action'].value

    try:
        req.form['logout'].value
        data=kooky2.myCookies(req,'get','',config['dbname'],config['selectedHost'])
        data['username']=''
        data['userpass']=''

        kookied=kooky2.myCookies(req,'save',data,config['dbname'],config['selectedHost'])
        #~ util.redirect(req,"../testValue.py/testvalue?test="+repr(kookied))

    except:
        pass

    if action=='15':
        parameter='?media='+req.form['media']
    else:
#        parameter='?media='+req.form['media']
        parameter='?action='+req.form['action']

    util.redirect(req,"../index.py"+parameter)
开发者ID:henrythemouse,项目名称:3t,代码行数:25,代码来源:myFunctions.py

示例6: authenhandler

def authenhandler(req):
	logger.info("Authentication username: %s", req.user)
	password = req.get_basic_auth_pw()
	if req.user == None:
		util.redirect(req, "/myemsl/error/nopersonid")
		return apache.HTTP_UNAUTHORIZED
	user = req.user
	if user.find('@') != -1:
#FIXME Make this fail on error better
		res = eus2login.eus2login(user, password)
		if not res.has_key('person_id') or not res['person_id']:
			return apache.HTTP_UNAUTHORIZED
		logger.info("Authentication username: %s personid: %s", req.user, res['person_id'])
#FIXME add myemsl_id mapping in when we have it
		req.user = res['person_id']
	else:
		service = 'myemsl'
		auth = pam.BasicPAMAuth(service, user, password)
		if not auth.authenticated:
			return apache.HTTP_UNAUTHORIZED
		newuser = getuserremote.get_user_remote(user, map='fs_map')
		if not newuser:
			logger.error("Failed to get user id for user %s", user)
			return apache.HTTP_UNAUTHORIZED
		req.user = newuser
	return apache.OK
开发者ID:EMSL-MSC,项目名称:pacifica-2.0,代码行数:26,代码来源:__init__.py

示例7: handler

def handler(req):
    req.send_http_header()
    req.content_type = 'text/html;charset=UTF-8'
    session = Session.Session(req,timeout=3600)
    session.load()
    session = session_init(session) 
    oauth_manager = oauthmanager.OAuth_manager(session)
    calender_api = calenderapi.Calender_api(oauth_manager)
    #request parameter 
    formValueList = util.FieldStorage(req)
    #URL에서 파일명 추출
    real_file_name = req.filename[ req.filename.rfind('/')+1:]
    if real_file_name == 'index.html':
        #등록된 accessToken이 있는지 판단
        if oauth_manager.check_access_token():
            template = file(config.index_file).read()
            search_date = formValueList.get('date', '%s-%s'%(time.localtime().tm_year,time.localtime().tm_mon))
            try:
               content = createcalender.Create_calender(int(search_date.split('-')[0]), int(search_date.split('-')[1]), calender_api)
            except ValueError, error:
            #data 형식이 잘못 되었을 경우
               req.write ("ValueError -> %s" % error)
            else:
               req.write (template % content)
        else:
        #등록된 accessToken이 없다면 인증페이지로
            util.redirect(req,'oauth.py');	    
开发者ID:BangC,项目名称:apis,代码行数:27,代码来源:handler.py

示例8: authorize

 def authorize(self):
     
     # already authorized
     if self.get('request_token_key') and self.get('access_token_key'):
         return
     
     # connections to oauth server
     httpconn = httplib.HTTPConnection('%s:%d'%(self.get('oauth_server'), self.get('oauth_port')))
     consumer = liboauth.OAuthConsumer(self.get('consumer_key'), self.get('consumer_secret'))
     signmeth = liboauth.OAuthSignatureMethod_HMAC_SHA1()
     
     # get request token
     oauth_request = liboauth.OAuthRequest.from_consumer_and_token(consumer, http_url=REQUEST_TOKEN_URL)
     oauth_request.sign_request(signmeth, consumer, None)
     httpconn.putrequest(oauth_request.http_method, oauth_request.http_url)
     for k, v in oauth_request.to_header().items():
         httpconn.putheader(k, v)
     httpconn.putheader('Content-Length', 0)
     httpconn.endheaders()
     data  = httpconn.getresponse().read()
     token = liboauth.OAuthToken.from_string(data)
     self.set('request_token_key', token.key)
     self.set('request_token_secret', token.secret)
 
     # add return uri to row
     self.set('data_uri', self._req.uri)
         
     # authorize token
     util.redirect(self._req, "%s?oauth_token=%s"%(AUTHORIZATION_URL,token.key))
开发者ID:osm-fr,项目名称:rawedit,代码行数:29,代码来源:rawedit.py

示例9: delSupport

def delSupport(req):
    
#     util.redirect(req,"../testValue.py/testvalue?test="+str(req.form.list))
    config=getConfig(req,req.form['dbname'].value)
    supportID=req.form['supportID']
    supportTableName=req.form['supportTableName']
#     itemID=req.form['itemID']
    fieldInfo=getFieldInfo3(req,config['selectedHost'],config['dbname'],supportTableName)
    
    try:
        action=req.form['delSupport'].lower()
    except:
        try:
            action=req.form['cancel'].lower()
        except:
            action='cancel'

    config=getConfig(req,req.form['dbname'])

#    util.redirect(req,"../testValue.py/testvalue?test="+str(req.form)+"*****"+str(action))
    if action!='cancel':

        # delete the record
        what=doSql(req,"DELETE",supportID,fieldInfo['idField'],config['dbname'],supportTableName,config["selectedHost"],"")
        
        if what[0]:
            parameter="?popup=93&amp;errorMessage="+what[0]
        else:
#            parameter="?media="+mediaRecord
            parameter="?action=23&amp;supportTableName="+supportTableName
    else:
#        parameter="?media="+mediaRecord
        parameter="?action=23&amp;supportTableName="+supportTableName

    util.redirect(req,"/3t/index.py"+parameter)
开发者ID:henrythemouse,项目名称:3t,代码行数:35,代码来源:myFunctions.py

示例10: delItem

def delItem(req):

    config=getConfig(req,req.form['dbname'].value)
    
    try:
        action=req.form['delItem'].lower()
    except:
        try:
            action=req.form['cancel'].lower()
        except:
            action='cancel'

    config=getConfig(req,req.form['dbname'])

    itemID=req.form['itemID']
    selectedHost=config["selectedHost"]
    tableName=config['itemTable']
    idField=config['itemIDfield']
    dbname=config['dbname']
#    util.redirect(req,"../testValue.py/testvalue?test="+str(req.form)+"*****"+str(action))

    if action!='cancel':

        # delete the record
        what=doSql(req,"DELETE",itemID,idField,dbname,tableName,selectedHost,"")
        if what[0]:
            parameter="?popup=93&amp;errorMessage="+what[0]
        else:
            # tell the routine where to return to, home.
            parameter=''
    else:
        # just go home, where ever that is.
        parameter=''

    util.redirect(req,"/3t/index.py"+parameter)
开发者ID:henrythemouse,项目名称:3t,代码行数:35,代码来源:myFunctions.py

示例11: index

def index(req,page="README"):
	# make sure the html fetch operation doesn't timeout too early
	sess = Session(req)
	sess.set_timeout(20)
	sess.save()

        # use the README page as the course index
	if page == "index":
		page = "README"
		
	# fetch the markdown text from dropbox
	link = "%s%s"%(githubRoot,page)
	#req.write(link)
	try:
		if page.endswith('.md') or page == 'README':
			# this is an HTML page
			req.content_type = "text/html"
			# give the page a title
			req.write("<title>ACCAD 5102</title>")
			# grab the stylesheet
			req.write("<style>%s</style>"%urllib2.urlopen("%sscreen.css"%webRoot).read())
			response = urllib2.urlopen(link)
                        #req.write(response.read())
			req.write(markdown.markdown(response.read(), ['tables']))
		else:
			util.redirect(req, link)
	except:
##		raise
##		req.write("error")
##		e = sys.exc_info()[0]
##		req.write(e)
		req.write("<br>This page does not exist yet")
开发者ID:jeisenma,项目名称:ProgrammingConcepts,代码行数:32,代码来源:pcad.py

示例12: use_handler

    def use_handler(self, func):
        
        if self.profile_flag:
            self.profile("start of app handler")

        # Call the application callback function.
        func(self)

        if self.profile_flag:
            self.profile("end of app handler")

        # If a redirect has been requested, redirect now.
        if self.__redirect_url != None: util.redirect(self.__req, self.__redirect_url)
        
        # If no data has been written to the client yet, write any buffered
        # headers and data.
        if not self.__data_written:
            if self.__content_type: self.__req.content_type = self.__content_type
            self.__write_headers()
            self.__write_cookies()
            self.__req.write(self.__buf_data)

        if self.profile_flag:
            self.profile("end of mp handler")

        # Tell Apache the request has been handled successfully.
        raise apache.SERVER_RETURN, self.get_status_mod_python(self.__http_status)
开发者ID:fdgonthier,项目名称:teambox-core,代码行数:27,代码来源:kweb_mp.py

示例13: metadata

def metadata(req,scene=None,filename=None):
    """ show auxilliary metadata files for scenes """

    # init AWS module
    aws = AWS()
    aws.set_scene(scene)
    attr = aws.get_scene_attributes()

    # make sure that name of scene is valid
    if not aws.is_valid_scene_name(scene):
        return "Error: invalid scene requested."

    # make sure that filename is valid
    if not filename in aws.get_metadata_filenames():
        return "Error: invalid filename requested"

    # strip qi/ subdirectory from cloudmask
    filename = re.sub('qi/','',filename)

    # link original file to temporary directory and redirect
    in_path = "%s/%s/metadata/%s_%s" % (aws.get_basedir(),attr['tile'],scene,filename)
    out_path = "/home/institut/www/html/data/sentinel2/metatmp/%s_%s" % (scene,filename)
    out_url = re.sub('/home/institut/www/html','',out_path)

    if os.path.exists(in_path):
        if not os.path.exists(out_path):
            os.symlink(in_path,out_path)
        redirect(req,out_url)
    else:
        return "Error: File %s for scene %s does not exist." % (filename,scene)
开发者ID:openwebcc,项目名称:ba,代码行数:30,代码来源:index.py

示例14: status_img

def status_img(req, id = 0, style = 0):
    db = msgrme_read_db()

    try:
        style = int(style)
    except:
        style = 0

    id = db.check_id(id)
    if not bool(id):
        util.redirect(req, "%s%02d_fln.png" % (IMGDIR, style))
        return ""
    
    info = db.get_info(id)
    s = info[3]

    db.close()
    del db
    
    if s == "NLN":
        util.redirect(req, "%s%02d_nln.png" % (IMGDIR, style))
    elif s == "BSY" or s == 'PHN':
        util.redirect(req, "%s%02d_bsy.png" % (IMGDIR, style))
    elif s == "IDL" or s == "AWY" or s == "BRB" or s == "LUN":
        util.redirect(req, "%s%02d_awy.png" % (IMGDIR, style))
    else:
        util.redirect(req, "%s%02d_fln.png" % (IMGDIR, style))
    
    return ""
开发者ID:techno,项目名称:msgrme,代码行数:29,代码来源:mme.py

示例15: jump4

def jump4(req):
    (status,output)=commands.getstatusoutput('/var/www/script/addUser.sh Jane 123 4.htpasswd')
    if status==0:
        (status,output)=commands.getstatusoutput('/var/www/script/removeUser.sh Jane 2.htpasswd')
        (status,output)=commands.getstatusoutput('/var/www/script/removeUser.sh Jane 3.htpasswd')
        util.redirect(req,"/FlowControl/4.html")
    return apache.OK
开发者ID:jennyzhang8800,项目名称:FlowControl,代码行数:7,代码来源:index.py


注:本文中的mod_python.util.redirect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。