def request(self): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) form = WebOpenIDChangePasswordForm() if self.method == 'POST': if form.validates(self.query): password_manager.set(self.query['password']) session['no_password'] = False return web.found( _secure_homedomain(web.ctx) + web.url('/account')) web.header('Content-type', 'text/html') return render.password( home_url=_secure_homedomain(web.ctx) + web.url('/'), logged_in=session.logged_in, logout_url=_secure_homedomain(web.ctx) + web.url('/account/logout'), change_password_url=_secure_homedomain(web.ctx) + web.url('/account/change_password'), no_password=session.get('no_password', False), form=form, )
def POST(self): form = web.input( poster=utils.get_default_name(), title='', syntax='text', body='', do_preview=None, ) is_valid, error = utils.check_captcha(web.ctx['ip'], form) if not is_valid or form.do_preview is not None: return render.post( user=form.poster, title=form.title, syntax=form.syntax, body=form.body, captcha_error=error, preview=form.do_preview is not None, ) utils.save_poster(form.poster) if form.body.strip() == '': return web.seeother(web.url('/')) paste_id = db.add_paste( form.poster, form.title.strip(), [(form.body, form.syntax)], ) return web.seeother(web.url('/%d' % (paste_id,)))
def request(self): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) form = WebOpenIDChangePasswordForm() if self.method == 'POST': if form.validates(self.query): password_manager.set(self.query['password']) session['no_password'] = False return web.found( homedomain(web.ctx) + web.url('/account')) web.header('Content-type', 'text/html') return render.password( home_url=homedomain(web.ctx) + web.url('/'), logged_in=session.logged_in, logout_url=homedomain(web.ctx) + web.url('/account/logout'), change_password_url=homedomain(web.ctx) + web.url( '/account/change_password'), no_password=session.get('no_password', False), form=form, )
def request(self): return_to = self.query.get('return_to', web.ctx.homedomain + web.url('/account')) data = filter(lambda item: item[0] not in ['password'], self.query.items()) form = WebOpenIDLoginForm(password_manager)() session['no_password'] = False if self.method == 'POST': try: if form.validates(self.query): session.login() data.append(('logged_in', True)) return web.found(return_to + '?' + web.http.urlencode(dict(data))) except PasswordManager.NoPassword: session['no_password'] = True session.login() data.append(('logged_in', True)) return web.found(return_to + '?' + web.http.urlencode(dict(data))) web.header('Content-type', 'text/html') return render.login( logged_in=session.logged_in, login_url=web.ctx.homedomain + web.url('/account/login'), logout_url=web.ctx.homedomain + web.url('/account/logout'), change_password_url=web.ctx.homedomain + web.url('/account/change_password'), no_password=session.get('no_password', False), form=form, query=data, )
def request(self): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) items = [ (( item[1], web.ctx.homedomain + web.url('/account/trusted/%s/delete' % item[0]) )) for item in trust_root_store.items() ] removed = session.get('trusted_removed_successful', False) session['trusted_removed_successful'] = False web.header('Content-type', 'text/html') return render.trusted( logged_in=session.logged_in, logout_url=web.ctx.homedomain + web.url('/account/logout'), change_password_url=web.ctx.homedomain + web.url('/account/change_password'), no_password=session.get('no_password', False), trusted=items, removed=removed, )
def request(self, trusted_id): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) try: trust_root = dict(trust_root_store.items())[trusted_id] except: return web.notfound() if self.method == 'POST': trust_root_store.delete(trust_root) session['trusted_removed_successful'] = True return web.found(web.ctx.homedomain + web.url('/account/trusted')) web.header('Content-type', 'text/html') return render.trusted_confirm( logged_in=session.logged_in, logout_url=web.ctx.homedomain + web.url('/account/logout'), change_password_url=web.ctx.homedomain + web.url('/account/change_password'), check_trusted_url=web.ctx.homedomain + web.url('/account/trusted'), trusted_remove_url=web.ctx.homedomain + web.url('/account/trusted/%s/delete' % trusted_id), no_password=session.get('no_password', False), trust_root=trust_root, )
def apicall(self,type1): web.header('Content-Type','text/html; charset=utf-8', unique=True) access_token = {} f1 = open(settings.get_home_dir() + 'token.txt','r') str1 = f1.read() f1.close() l1 = str1.split(';') if '1' == l1[2].replace(r'ss=',''): access_token['oauth_token'] = l1[0].replace(r'ot=','') access_token['oauth_token_secret'] = l1[1].replace(r'ots=','') if web.url().startswith('/api/'): url1 = web.url().replace(r'/api/','',1) i1 = web.input().copy() #for new twitter ,home_timeline #home timeline pop_earned = not -1 == url1.find('statuses/home_timeline') or\ not -1 == url1.find('statuses/user_timeline') or\ not -1 == url1.find('statuses/show') if pop_earned: if i1.has_key('earned'): i1.pop('earned') rv = twitUtil.MakeApiCall(access_token,url1,type1,dict(i1)) if url1.endswith('.json'): rv = self.sub_url(rv) return rv
def main(): print """----------- Vault Automation Test -----------""" print """This program executes some test cases to evaluate VAULT""" host = raw_input('Enter the IP Address of the host: ') user = raw_input("Enter the Username of the host: ") password = raw_input("Enter the Password of the host: ") ch = raw_input("Enter the choice of connectivity (SSH/WEB)? ") if (ch == "SSH" or ch == "ssh"): handle = connect.connect(host, user, password) out, err = connect.sendcmd(handle, "uname -a") print("The Machine Details are %s \n" % out.readlines()[0]) out, err = connect.sendcmd(handle, 'vault') print("The Vault Status is %s \n" % out.readlines()) elif (ch == "WEB" or ch == "web"): port = raw_input("Enter the port number of the request: ") handle = web.request(host, "sys/health", port) print web.url(handle + "sys/seal-status") else: print("Enter the Right Choice ! \n") sys.exit() print "\nBEGIN: Test Case Execution ---->\n" print "Basic TestCase: " print """"""
def request(self): web.header('Content-type', 'text/html') return render.base( logged_in=True, #session.logged_in, #login_url=web.ctx.homedomain + web.url('/account/login'), #logout_url=web.ctx.homedomain + web.url('/account/logout'), #change_password_url=web.ctx.homedomain + web.url('/account/change_password'), #check_trusted_url=web.ctx.homedomain + web.url('/account/trusted'), no_password=session.get('no_password', False), endpoint=web.ctx.homedomain + web.url('/endpoint'), yadis=web.ctx.homedomain + web.url('/yadis.xrds'), homedomain=web.ctx.homedomain, )
def GET(self, id = None): section = web.url().split('/')[1] i = web.input(page = 1) order = {'algorithm': 'subid DESC', 'problem': 'pid', 'contest': 'cid DESC', 'accounts': 'uid' } # FIXME group = {'algorithm': 'subid', 'problem': 'pid', 'contest': 'cid', 'accounts': 'uid' } # FIXME what = 'subid, uid, pid, addr, lang, created, stat, time, mmem' where = str((id == None) or ('%s = %s' % (group[section], str(id)))) page = int(i.page) limit = 19 # Perfect size for my beloved X61 Thinkpad screen! offset = (page - 1) * limit query = db.select('shots', None, what, where, 'subid DESC', None, #order[section], group[section], FIXME limit, offset) return renderer[section].status(query)
def GET(self): url = web.url() filename = url[url.rfind('/file=') + 6:url.rfind('&')] signature = url[url.rfind('signature=') + 10:] if not (self.server_check(filename, signature)): self.send_response(500) return
def login_required(): if not users.get_current_user(): if renderer.get_mode() == 'html': # Redirect to a login page, coming back here when done. raise web.found(users.create_login_url(web.url())) elif renderer.get_mode() == 'json': # Return an error in JSON. renderer.addData('error', 'Not logged in.') return renderer.render('apionly.html')
def GET(self): user = users.get_current_user() if user: # Is logged in. raise web.found('/profile') else: # Not logged in - redirect to login. raise web.found(users.create_login_url(web.url()))
def notFound(filename): web.expires(60) web.header('Content-Type', 'text/html') s = """<p>You were looking for "%s".</p>""" % filename s += """<p>(on host %s)</p>""" % web.ctx.host s += """<p>(that is, URL="%s")</p>""" % web.url() s += """<p>alas.</p>""" web.notfound() return s
def link_to(obj_type, obj=None, method=None, **kw): link = "/a/" + obj_type if obj is not None: link += "/" + str(obj.get("id")) if method: link += "/" + method # Remove none values from kw params = dict((k, v) for k, v in kw.iteritems() if v is not None) return web.url(link, **params)
def GET(self): url = web.url() if url == '/': url = '/index' user = users.get_current_user() if user: user_url = users.create_logout_url('/') else: user_url = users.create_login_url('/manage') return template.render('templates%s.html' % url, {'user':user,'user_url':user_url})
def get_nextprev(self, key, rev, offset): """Returns next url when offset is 1 and prev url when offset is -1. """ i = web.input(_method="GET") where = index().prepare_where(i) items = [(row.key, row.revision) for row in db.select('reports', where=where, order="time desc", vars=i)] try: row_index = items.index((key, int(rev))) key, rev = items[row_index+offset] return web.url("/diff%s@%s" % (key, rev), **i) except IndexError: return None
def GET(self, name=None): name = web.url() lname = name.split("/") web.header('Content-Type', 'application/json') if lname[1] in specific_filters: dao = DAO.DAO() if len(lname) > 2: pass else: status, finaltags, msg = dao.getTagsByCategory(lname[1]) return json.dumps({"%ss" % lname[1]: finaltags}) return json.dumps(lname)
def GET(self, page_num=None): mime_type = utils.get_preferred_mimetype( ('text/html', 'application/atom+xml'), 'text/html') if mime_type == 'text/html': if page_num is None: return web.seeother(web.url('/pastes/1')) return self.recent(int(page_num)) if mime_type == 'application/atom+xml': return self.feed() # Should never be called. return web.notacceptable()
def GET(self): name = web.input(term = 'super mario') result_list = [] set_name = name['term'].lower()+':star' results = r.zrevrange(set_name,0,10) if ALLOW_THIRD_PARTY_ACCESS: web.header('Access-Control-Allow-Origin','*') if 'term' in web.input(): key = 'sug:'+web.url()+'?term='+web.input()['term'] key = key.replace(' ','+') cache.set(key, json.dumps(results), CACHE_DURATION) return json.dumps(results)
def request(self): return_to = self.query.get( 'return_to', _secure_homedomain(web.ctx) + web.url('/account')) data = filter(lambda item: item[0] not in ['password'], self.query.items()) form = WebOpenIDLoginForm(password_manager)() session['no_password'] = False if self.method == 'POST': try: if form.validates(self.query): session.login() data.append(('logged_in', True)) return web.found(return_to + '?' + web.http.urlencode(dict(data))) except PasswordManager.NoPassword: session['no_password'] = True session.login() data.append(('logged_in', True)) return web.found(return_to + '?' + web.http.urlencode(dict(data))) web.header('Content-type', 'text/html') return render.login( home_url=_secure_homedomain(web.ctx) + web.url('/'), logged_in=session.logged_in, login_url=_secure_homedomain(web.ctx) + web.url('/account/login'), logout_url=_secure_homedomain(web.ctx) + web.url('/account/logout'), change_password_url=_secure_homedomain(web.ctx) + web.url('/account/change_password'), no_password=session.get('no_password', False), form=form, query=data, )
def request(self, trusted_id): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) try: trust_root = dict(trust_root_store.items())[trusted_id] except: return web.notfound() if self.method == 'POST': trust_root_store.delete(trust_root) session['trusted_removed_successful'] = True return web.found( _secure_homedomain(web.ctx) + web.url('/account/trusted')) web.header('Content-type', 'text/html') return render.trusted_confirm( home_url=_secure_homedomain(web.ctx) + web.url('/'), logged_in=session.logged_in, logout_url=_secure_homedomain(web.ctx) + web.url('/account/logout'), change_password_url=_secure_homedomain(web.ctx) + web.url('/account/change_password'), check_trusted_url=_secure_homedomain(web.ctx) + web.url('/account/trusted'), trusted_remove_url=_secure_homedomain(web.ctx) + web.url('/account/trusted/%s/delete' % trusted_id), no_password=session.get('no_password', False), trust_root=trust_root, )
def request(self): # check for login request = server.request(web.ctx.homedomain + web.url('/endpoint'), self.query) try: response = request.process(session.logged_in) except OpenIDResponse.NoneRequest: return web.badrequest() except OpenIDResponse.LogInNeed: # redirect request to login form return WebOpenIDLoginRequired(self.query) except OpenIDResponse.DecisionNeed: # redirect request to decision page in restricted area return web.found(web.ctx.homedomain + web.url('/account/decision', **self.query)) if self.query.get('logged_in', False): session.logout() return render_openid_to_response(response)
def GET(self): try: data = web.input() if len(data) == 0: logger.info(web.url() + ' access without data') return "wrong access" signature = data.signature timestamp = data.timestamp nonce = data.nonce echostr = data.echostr token = 'snoopytx20180412' try: check_signature(token, signature, timestamp, nonce) # print(web.url() + 'data: ' + str(data) + ' get: ' + nonce + ' return: ' + echostr) logger.info(web.url() + 'data: ' + str(data) + ' get: ' + nonce + ' return: ' + echostr) return echostr except InvalidSignatureException as e: logger.warning(web.url() + ' ' + e + ' wrong signature') # print('wrong signature') except Exception as Argument: # print(web.url() + ' data: ' + str(data) + ' get: ' + nonce + ' return: ' + Argument) logger.warning(web.url() + ' wrong: ' + str(Argument)) return False
def logging(): dbconn = db.connect('db.sqlite3') cur = dbconn.cursor() cur.execute( ''' INSERT INTO log (timestamp, ip, url, query, method, status, cookie) VALUES (?,?,?,?,?,?,?) ''', [ int(time.time()), web.ctx['ip'], web.url(), web.ctx['query'], web.ctx['method'], web.ctx['status'], web.cookies().get('checkin-cookie-key') ]) dbconn.commit() dbconn.close()
def request(self): # check for login request = server.request(web.ctx.homedomain + web.url('/endpoint'), self.query) try: response = request.process(session.logged_in) except OpenIDResponse.NoneRequest: return web.badrequest() if self.query.get('logged_in', False): session.logout() return render_openid_to_response(response)
def request(self): web.header('Content-type', 'text/html') return render.base( home_url=_secure_homedomain(web.ctx) + web.url('/'), logged_in=session.logged_in, login_url=_secure_homedomain(web.ctx) + web.url('/account/login'), logout_url=_secure_homedomain(web.ctx) + web.url('/account/logout'), change_password_url=_secure_homedomain(web.ctx) + web.url('/account/change_password'), check_trusted_url=_secure_homedomain(web.ctx) + web.url('/account/trusted'), no_password=session.get('no_password', False), endpoint=_secure_homedomain(web.ctx) + web.url('/endpoint'), yadis=_secure_homedomain(web.ctx) + web.url('/yadis.xrds'), )
def request(self): # check for login request = server.request( _secure_homedomain(web.ctx) + web.url('/endpoint'), self.query) try: response = request.process(session.logged_in) except OpenIDResponse.NoneRequest: return web.badrequest() except OpenIDResponse.LogInNeed: # redirect request to login form return WebOpenIDLoginRequired(self.query) except OpenIDResponse.DecisionNeed: # redirect request to decision page in restricted area return web.found( _secure_homedomain(web.ctx) + web.url('/account/decision', **self.query)) if self.query.get('logged_in', False): session.logout() return render_openid_to_response(response)
def request(self): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) items = [((item[1], _secure_homedomain(web.ctx) + web.url('/account/trusted/%s/delete' % item[0]))) for item in trust_root_store.items()] removed = session.get('trusted_removed_successful', False) session['trusted_removed_successful'] = False web.header('Content-type', 'text/html') return render.trusted( home_url=_secure_homedomain(web.ctx) + web.url('/'), logged_in=session.logged_in, logout_url=_secure_homedomain(web.ctx) + web.url('/account/logout'), change_password_url=_secure_homedomain(web.ctx) + web.url('/account/change_password'), no_password=session.get('no_password', False), trusted=items, removed=removed, )
def render(self, template_name): # Determine the mode from the parameters. if self.get_mode() == 'html': self.addTemplate('uri', web.url()) template = self.template_lookup.get_template(template_name) return template.render(**self.data) elif self.get_mode() == 'json': # Filter the data. Only data/data-list go out. outputdata = {} web.header('Content-Type', 'application/json') for key, value in self.data.iteritems(): if self.types[key] == 'data' or self.types[key] == 'data-list': outputdata[key] = self.prepareToJson(value) return json.dumps(outputdata) else: # Not a supported mode. return None
def _setup_xmlinfo(self): root = etree.Element('request') n = etree.SubElement(root, 'querytime') n.text = datetime.today().strftime("%Y-%m-%d %H:%M:%S%z") n = etree.SubElement(root, 'queryvalue') n.text = web.url() n = etree.SubElement(root, 'cachekey') n.text = self.cachekey; n = etree.SubElement(root, 'backendtime') n.text = '%.2f' % self._backendtime n = etree.SubElement(root, 'time') n.text = self._time.strftime("%Y-%m-%d %H:%M") conc = lambda x: x['type']+ ':' + x['value'] n = etree.SubElement(root, 'from') n.text = conc(self._query) n = etree.SubElement(root, 'filters') n.text = str(self._filters) self.xmlinfo = etree.tostring(root, method='xml', encoding='UTF-8')
def request(self): import openid.consumer web.header('Content-type', 'application/xrds+xml') return """<?xml version="1.0" encoding="UTF-8"?> <xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)"> <XRD> <Service priority="0"> <Type>%s</Type> <Type>%s</Type> <URI>%s</URI> <LocalID>%s</LocalID> </Service> </XRD> </xrds:XRDS>\n""" %\ ( openid.consumer.discover.OPENID_2_0_TYPE, openid.consumer.discover.OPENID_1_0_TYPE, _secure_homedomain(web.ctx) + web.url('/endpoint'), _secure_homedomain(web.ctx), )
def request(self): import openid.consumer web.header('Content-type', 'application/xrds+xml') return """<?xml version="1.0" encoding="UTF-8"?> <xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)"> <XRD> <Service priority="0"> <Type>%s</Type> <Type>%s</Type> <URI>%s</URI> <LocalID>%s</LocalID> </Service> </XRD> </xrds:XRDS>\n""" %\ ( openid.consumer.discover.OPENID_2_0_TYPE, openid.consumer.discover.OPENID_1_0_TYPE, web.ctx.homedomain + web.url('/endpoint'), web.ctx.homedomain, )
def POST(self): section = web.url().split('/')[1] i = web.input( identity = None, passwd = None ) identity = i.identity passwd = i.passwd what = 'uid, email, username, password' where = "(email='%s' OR username='******')" % (identity, identity) query = db.select('users', None, what, where) if len(list(query)) == 0: return renderer.login(1) # username / email not found row = query[0] hash = SHA256.new() hash.update(secret.salt) hash.update(row.email) hash.update(passwd) shadow = hash.digest() # TODO: implement HTTP Digest Authentication :-fsck yeah! # https://github.com/mahrud/webpy_http-digest-auth if shadow.encode('hex') == row.password: session.auth = True session.time = time.time() session.uid = row.uid session.email = row.email session.uname = row.username return web.seeother("/") else: return renderer.login(2, identity) # wrong password
def GET(self): ret = getPosts() posts = list(ret.get('posts')) if checkLogin(): userId = db['users'].find_one( {'username': web.ctx.session.get('username')})['_id'] else: userId = None url = web.url() query = dict(web.input()) nextPage = prevPage = None if ret.get('nextPage'): query['page'] = str(ret.get('nextPage')) nextPage = addQuery(url, query) if ret.get('prevPage'): query['page'] = str(ret.get('prevPage')) prevPage = addQuery(url, query) return render.index({ 'posts': posts, 'userId': userId, 'type': web.input(type=None).type, 'nextPage': nextPage, 'prevPage': prevPage })
def POST(self): section = web.url().split('/')[1] i = web.input(code={}) uid = int(i.uid) pid = int(i.pid) cid = int(i.cid) orig = '%s/sources/%s' % (os.getcwd(), i.code.filename) code = file(orig, 'w') code.write(i.code.value) code.close() lang = i.lang subid = db.insert('shots', # subid has AUTO_INCREMENT, uid = uid, pid = pid, cid = cid, addr = orig, lang = lang, mode = 0 # mode[i.cid] #FIXME # created is set to CURRENT_TIMESTAMP, # TODO: update `access` by judge # TODO: update `modify` by judge ) addr = '%s/sources/%d-%s' % (os.getcwd(), subid, i.code.filename) shutil.move(orig, addr) db.update('shots', where = "subid=%d" % subid, addr = addr ) jucs.submit(subid, uid, pid, lang, addr) raise web.seeother('/algorithm/status/%s' % (subid))
def add_stylesheet(path): if web.url(path) not in context.stylesheets: context.stylesheets.append(web.url(path)) return ""
def base_url(): return web.url()
def request(self): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) request = server.request(web.ctx.homedomain + web.url('/endpoint'), self.query) try: response = request.process(logged_in=True) except OpenIDResponse.NoneRequest: return web.badrequest() except OpenIDResponse.DecisionNeed: if self.method == 'POST': if self.query.get('logout', False): session.logout() if self.query.has_key('approve'): response = request.approve() elif self.query.has_key('always'): response = request.always() else: response = request.decline() else: data = filter( lambda item: item[0] not in [ 'approve', 'always', 'logged_in', 'logout' ], self.query.items()) sreg_request = sreg.SRegRequest.fromOpenIDRequest(request.request) profile = None if sreg_request.required or sreg_request.optional: try: hcards = HCardParser().parse_url(request.request.identity) if hcards: hcard = hcards.next() profile = hcard.profile(sreg_request.required, sreg_request.optional) except: pass logout_form = WebOpenIDLogoutForm() logout_form.fill({'logout': self.query.get('logged_in', False)}) web.header('Content-type', 'text/html') return render.verify( logged_in=session.logged_in, logout_url=web.ctx.homedomain + web.url('/account/logout'), change_password_url=web.ctx.homedomain + web.url('/account/change_password'), no_password=session.get('no_password', False), decision_url=web.ctx.homedomain + web.url('/account/decision'), identity=request.request.identity, trust_root=request.request.trust_root, profile=profile, logout_form=logout_form, query=data, ) return render_openid_to_response(response)
def WebOpenIDLoginRequired(query): query['return_to'] = _secure_homedomain(web.ctx) + web.url(web.ctx.path) return web.found( _secure_homedomain(web.ctx) + web.url('/account/login', **query))
def POST(self): try: xml = web.data() msg = parse_message(xml) if msg.type == 'text': content = msg.content if content.startswith(('表情包:', '表情包:')): words = ''.join(content.replace(':', ':').split(':')[1:]) wechat_client = WeChatClient( appid='wx19a2591b2a719add', secret='c46fa65dbc2803b90431fbf9c803cbd4', ) access_token = wechat_client.access_token json_data = pics.upload_pic(pics.get_random_pic(words), access_token) # print(json_data) if 'errcode' not in json_data: media_id = json_data['media_id'] reply = ImageReply(message=msg) reply.media_id = media_id # print(web.url() + ' get_pic. words: ' + words + ' return: ' + str(json_data)) logger.info(web.url() + ' get_pic. words: ' + words + ' return: ' + str(json_data)) else: reply = TextReply(message=msg) reply.content = json_data['link'] logger.warning(web.url() + ' get_pic faild,return link. words:' + words + ' return: ' + json_data['link']) elif content.startswith(('影视:', '影视:')): words = ''.join(content.replace(':', ':').split(':')[1:]) if words == '': string = '没有输入要搜索的名字!' logger.info(web.url() + ' get_movie without words') else: data = search(words) data1 = data[0] data2 = data[1] if len(data1) != 0: string = '' if len(data1) <= 12: for each in data1: string += '%s %s %s %s\n' % (each[0], each[1], each[3], each[4]) else: for each in data1[:12]: string += '%s %s %s %s\n' % (each[0], each[1], each[3], each[4]) elif len(data2) != 0: string = '' if len(data2) <= 12: for each in data2: string += '%s %s %s %s\n' % (each[0], each[1], each[3], each[4]) else: for each in data2[:12]: string += '%s %s %s %s\n' % (each[0], each[1], each[3], each[4]) else: string = '竟然没有搜索到!!!\n请检查名称输入的是否正确,请尽量使用中文哦' # print(web.url() + ' get_pic. words: ' + words + ' data: ' + str(data) + ' return: ' + string) logger.info(web.url() + ' get_movie. words: ' + words + ' data: ' + str(data) + ' return: ' + string) reply = TextReply(message=msg) reply.content = string elif content.startswith(('在线:', '在线:')): words = ''.join(content.replace(':', ':').split(':')[1:]) if words == '': string = '没有输入要搜索的名字!' logger.info(web.url() + ' see_movie without words') else: data = get_link(words) if data: string = data else: string = '竟然没有搜索到!!!\n请检查名称输入的是否正确,请试试英文名哦' # print(web.url() + ' see_pic. words: ' + words + ' data: ' + str(data) + ' return: ' + string) logger.info(web.url() + ' see_movie. words: ' + words + ' data: ' + str(data) + ' return: ' + string) reply = TextReply(message=msg) reply.content = string else: reply = TextReply(message=msg) response = get_response(content) logger.info(web.url() + ' turing. words: ' + content + ' response: ' + response) reply.content = response elif msg.type == 'event' and msg.event: mscontent = msg.event if mscontent == "subscribe": string = '终于等到你!欢迎关注Snoopy同学~\n' \ '输入"表情包:xxx"获取自定义文字的表情\n' \ '输入"影视:xxx"获取电影的网盘链接\n' \ '输入"在线:xxx"获取在线观看视频的链接,需要复制到浏览器使用哦~' reply = TextReply(message=msg) reply.content = string elif mscontent == "unsubscribe": string = '有什么不足之处还请谅解,我会慢慢改进,欢迎您以后再来' reply = TextReply(message=msg) reply.content = string # 转换成 XML reply_xml = reply.render() return reply_xml except Exception as e: logger.error(e) # print(e) return "success"
def request(self): session.logout() return web.found(web.ctx.homedomain + web.url('/account/login'))
def request(self): session.logout() return web.found( _secure_homedomain(web.ctx) + web.url('/account/login'))
def WebOpenIDLoginRequired(query): query['return_to'] = web.ctx.homedomain + web.url(web.ctx.path) return web.found(web.ctx.homedomain + web.url('/account/login', **query))
def store_values(self,obj,orm): f = self.get_form(obj,orm) #make a dictionary of fieldname,[] combinations for all "multiple" dropdrowns #so we give those the correct default value to web.input #to get lists as values instead of a single value. #see http://webpy.org/cookbook/input listfields = dict([(field.name,[]) for field in f.inputs if isinstance(field,form.Dropdown) and field.attrs.get('multiple',False)]) source=dict([(k,form.utils.intget(v) or v) for k,v in web.input(**listfields).items()]) if not f.validates(source=source): #Validation failed. Back to the form with the error message ID = self.__class__.ID TITLE = self.__class__.TITLE return render.form(f,ID,TITLE,web.url()) else: #The form validated. Store the values in the db values = [] for col in get_simple_columns(obj): #set the simple column values values.append((col.name,f[col.name].value or None)) for attr in get_relation_attributes(obj): #get the relation attributes and set them. target = attr.property.mapper.entity #target class pkey = f[attr.key].value #primary key value from the form val = orm.query(target).get(pkey) #get target instance from pkey values.append((attr.key,val)) for attr in get_multi_relation_attributes(obj): target = attr.property.mapper.entity #target class vals=[] for v in f[attr.key].value: val = orm.query(target).get(v) #get target instance from pkey vals.append(val) values.append((attr.key,vals)) inst = obj() for k,v in values: if isinstance(v,list): for val in v: getattr(inst,k).append(val) else: setattr(inst,k,v) orm.add(inst) orm.commit() log.debug('changes committed') #handle the resulting redirection. if 'HTTP_X_REQUESTED_WITH' in web.ctx.environ.keys(): #we're dealing with an ajax request if f['redirect'].value == 'form': #back to the form with the same values. f.fill(source=dict([(k.name,k.value) for k in f.inputs if isinstance(k,form.Dropdown) or isinstance(k,form.Hidden)])) return render.form(f,self.__class__.ID,self.__class__.TITLE, web.url()) else: #show the added item #return web.seeother('/%s'%inst.id) log.debug('returning show page'); return web.seeother('/%s'%inst.id) elif f['redirect'].value == 'form': #redirect to the form again, empty values in the form first f.fill(source=dict([(k.name,None) for k in f.inputs])) return render.form(f,self.__class__.ID,self.__class__.TITLE, web.url()) else: #redirect to the list page return web.seeother('/')
def add_javascript(path): if web.url(path) not in context.javascripts: context.javascripts.append(web.url(path)) return ""
def request(self): # check for login if not session.logged_in: return WebOpenIDLoginRequired(self.query) request = server.request( _secure_homedomain(web.ctx) + web.url('/endpoint'), self.query) try: response = request.process(logged_in=True) except OpenIDResponse.NoneRequest: return web.badrequest() except OpenIDResponse.DecisionNeed: if self.method == 'POST': if self.query.get('logout', False): session.logout() if self.query.has_key('approve'): response = request.approve() elif self.query.has_key('always'): response = request.always() else: response = request.decline() else: data = filter( lambda item: item[0] not in ['approve', 'always', 'logged_in', 'logout'], self.query.items()) sreg_request = sreg.SRegRequest.fromOpenIDRequest( request.request) profile = None if sreg_request.required or sreg_request.optional: try: hcards = HCardParser().parse_url( request.request.identity) if hcards: hcard = hcards.next() profile = hcard.profile(sreg_request.required, sreg_request.optional) except: pass logout_form = WebOpenIDLogoutForm() logout_form.fill( {'logout': self.query.get('logged_in', False)}) web.header('Content-type', 'text/html') return render.verify( home_url=_secure_homedomain(web.ctx) + web.url('/'), logged_in=session.logged_in, logout_url=_secure_homedomain(web.ctx) + web.url('/account/logout'), change_password_url=_secure_homedomain(web.ctx) + web.url('/account/change_password'), no_password=session.get('no_password', False), decision_url=_secure_homedomain(web.ctx) + web.url('/account/decision'), identity=request.request.identity, trust_root=request.request.trust_root, profile=profile, logout_form=logout_form, query=data, ) return render_openid_to_response(response)