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


Python Session.get方法代码示例

本文整理汇总了Python中session.Session.get方法的典型用法代码示例。如果您正苦于以下问题:Python Session.get方法的具体用法?Python Session.get怎么用?Python Session.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在session.Session的用法示例。


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

示例1: get

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import get [as 别名]
    def get(self):
        if 'pairing' in self.request.arguments:
            key = self.get_argument('pairing')
            # validate pairing key

            if 'type' in self.request.arguments:
                if 'session' in self.request.arguments:
                    session = Session.get(self.get_argument('session'))
                    if session:
                        if self.get_argument('type') == 'update':
                            self.writeout( session.get_update() )
                        elif self.get_argument('type') == 'function':
                            queries = self.get_argument('queries')
                            qargs = json.loads(queries)
                            args = [urllib.unquote(arg) for arg in qargs]
                            decoded = [decode_func_args(a) for a in args]
                            for fnargs in decoded:
                                self.writeout( session.handle_function(fnargs) )
                                return
                        else:
                            self.writeout( { 'no':'huh' } )
                        # validate session
                        #self.writeout( [ {'add': {'btapp':{'torrent':{'aotheu':{'hello':23}}}} } ] )
                    else:
                        self.set_status(404)
                else:
                    #logging.info('no session id in args -- %s, %s' % (self.request.uri, self.request.arguments))
                    session = Session.create(Client.instances[0])
                    self.writeout( {'session':session.id} )
            else:
                self.writeout( { 'hey':'whatup' } )
        else:
            self.set_status(403)
开发者ID:kzahel,项目名称:ktorrent,代码行数:35,代码来源:frontend.py

示例2: BaseHandler

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import get [as 别名]
class BaseHandler(tornado.web.RequestHandler):
    def __init__(self, *args, **kwargs):
        super(BaseHandler, self).__init__(*args, **kwargs)
        self.session = Session(self)

    # autosave session to server when request finish
    def on_finish(self):
        self.session.save()

    def get_current_user(self):
        return self.session.get("user", None)
开发者ID:,项目名称:,代码行数:13,代码来源:

示例3: end_session

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import get [as 别名]
def end_session(sid):
    """End a robot control session.  After session is ended, another party
    can then acquire a new session."""
    try:
        # TODO can we move this port stuff to hangouts.py?
        #  The issue was that Session.close deletes the session directory,
        #  which clears out the port storage file.  But we don't want to
        #  stop the hangout before we validate sid & close session.
        session = Session(sid)
        port = session.get('hangout_control_port')
        session.close()
        control.stop_controlserver()
        stop_hangout(port)
        heartbeats.send_session_ended()
        return {'message': "Session ended successfully."}
    except SessionConflict, e:
        abort(409, "Unable to end control session: %s" % str(e))
开发者ID:davemt,项目名称:vistorvebot,代码行数:19,代码来源:server.py

示例4: complete_openid_auth

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import get [as 别名]
def complete_openid_auth(request, session_id):
    """attempt to resume the session given by the session ID. Check
    the OpenID server response and if it responds that this user is
    who he says he is, then complete the comment posting.

    @param request: Pyblosxom request object

    @param session_id: The session id of the original comment post
    @type session_id: str

    @return: None
    """
    form = request.getForm()
    config = request.getConfiguration()
    data = request.getData()
    import_and_initialize()

    session = Session(request, session_id)
    consumer = get_openid_consumer(request, session)
    if consumer is None:
        return

    query = {}
    for k in form:
        query[k] = form.getfirst(k)

    # Get the session and the data that we need out of it in order to
    # complete the request
    sess = Session(request, session_id)

    # Actual user-filled comment data
    cmt_data = sess.get('data', {})

    # Association
    association = sess.get('association')
    trust_root = sess.get('trust_root')

    try:
        if form.getfirst('openid.mode', None) == 'cancel':
            raise OpenIDCommentError('OpenID authentication cancelled')

        # Make sure that the return_to URL that was sent by the server has
        # the same session ID as the current request
        return_to = query.get('openid.return_to', '')
        if (not association or
            not verify_return_to(return_to, trust_root, session_id)):
            raise OpenIDCommentError('Error handling OpenID response')

        # Ask the OpenID library to check the server's response
        response = consumer.complete(query)
        if response.status == openid.SUCCESS:
            if response.identity_url is None:
                raise OpenIDCommentError('OpenID authentication cancelled')
            else:
                cmt_data['url'] = response.identity_url

                # get the user's nickname using Simple Registration Extension
                sreg_args = response.extensionResponse(
                    'http://openid.net/sreg/1.0', False)
                signon_args = response.extensionResponse(
                    'http://openid.net/signon/1.0', False)
                if 'nickname' in sreg_args:
                    cmt_data['author'] = sreg_args['nickname']
                elif 'sreg.nickname' in signon_args:
                    cmt_data['author'] = signon_args['sreg.nickname']

                save_comment(request, cmt_data)

                for key in comment_form_fields:
                    key = "cmt_%s" % key
                    if key in data:
                        del data[key]

                # Now that we completed the authorization transaction,
                # delete the session.
                sess.delete()
        elif response.status == openid.FAILURE:
            fmt = 'Error handling OpenID response for identity <q>%s</q>'
            raise OpenIDCommentError(fmt % (cgi.escape(response.message),))
        else:
            raise OpenIDCommentError('Error handling OpenID response')
    except OpenIDCommentError, why:
        data['comment_message'] = why[0]
        for field_name in comment_form_fields:
            data['cmt_' + field_name] = cmt_data.get(field_name, '')
开发者ID:dot-Sean,项目名称:snarfed.org,代码行数:87,代码来源:comments_openid.py

示例5: BasePage

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import get [as 别名]
class BasePage(webapp.RequestHandler):
    
    session = None #sessionを拡張
    user = None #現在のユーザー

    def initialize(self,request, response):
        webapp.RequestHandler.initialize(self,request, response)
        self.session = Session(request, response)
        self.get_current_user()

    def add_password(self, user, password):
        self.auth_list.append({'user':user,'pass':password})



    def render_json(self, result):
        self.response.headers['Content-Type'] = 'text/javascript; charset=utf-8'
        callback = re.sub("[^\w\d]","",self.request.get('callback'))
        if callback:
            self.response.out.write(callback + "(")

        simplejson.dump(result,self.response.out, ensure_ascii=False)

        if callback:
            self.response.out.write(");")

    def render(self,path,params):
        if not params:
            params = dict()
        
        static_domain = ''
        domain = ''
        app_version = os.environ.get("CURRENT_VERSION_ID","")
        
        domain = os.environ.get("SERVER_NAME","")
        
        if domain != "www.caffein.tv":
            app_version = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        
        params["app_version"]   = app_version
        params["user"] = self.user

        #username
        username = self.get_username()
        params["username"] = username
        
        path = os.path.join(os.path.dirname(__file__), path)
        self.response.out.write(template.render(path, params))

    def logout(self):
        self.session.set("userkey","")
        self.session.set("username","")
        #セッションIDの振り直し(セキュリティ上重要!)
        self.session.reset_key(self.request, self.response)
        
        
    def get_userkey(self):
        if self.user:
            userkey = self.user.key().name()
        else:
            userkey = "session:" + self.session.get_key()
        return userkey

    def get_username(self): 
        username = self.session.get("username")
        if not username and self.user:
            username = self.user.username
        if not username:
            username = ""
        return username
        
    def get_current_user(self):
        userkey = self.session.get("userkey")
        self.user = None
        if userkey:
            person = memcache.get(userkey)
            if not person:
                person = Person.get_by_key_name(userkey)
                memcache.set(userkey,person,20*24*60*60)
            if person:
                self.user = person
                return True

    def init_pagenation(self):
        try:
            return int(self.request.get('page',1))
        except:
            return 1

    def make_pagenation(self,page,total):
        prev = False
        next = False
        if page > 1:
            prev = True
            
        if int(page) < int(total):
            next = True
            
        #?以降のクエリー(URL)を作成
        query_string = self.request.query_string
#.........这里部分代码省略.........
开发者ID:rakusai,项目名称:bujime,代码行数:103,代码来源:base_page.py


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