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


Python session.get_session函数代码示例

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


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

示例1: tenant_group_update

def tenant_group_update(id, tenant_id, values, session=None):
    if not session:
        session = get_session()
    with session.begin():
        tenant_ref = tenant_group_get(id, tenant_id, session)
        tenant_ref.update(values)
        tenant_ref.save(session=session)
开发者ID:juvvadi,项目名称:keystone,代码行数:7,代码来源:api.py

示例2: put

    def put(self, path, data, metadata={}, reduced_redundancy=False, encrypt_key=False, callback=None):
        """
        Stores data at given path
        :param string path: Path or 'key' for created/updated object
        :param bytes data: Data to write
        :param dict metadata: Metadata to store with this data
        :param bool reduced_redundancy: Whether to reduce storage redundancy or not?
        :param bool encrypt_key: Encrypt data?
        :param callable callback: Called function once done
        """
        storage_class = 'REDUCED_REDUNDANCY' if reduced_redundancy else 'STANDARD'

        args = dict(
            callback=callback,
            Bucket=self._bucket,
            Key=self._clean_key(path),
            Body=data,
            Metadata=metadata,
            StorageClass=storage_class,
        )

        if encrypt_key:
            args['ServerSideEncryption'] = 'AES256'

        my_session = session_handler.get_session(self._endpoint is not None)
        session = Botocore(service='s3', region_name=self._region,
                           operation='PutObject', session=my_session,
                           endpoint_url=self._endpoint)

        session.call(**args)
开发者ID:aoqfonseca,项目名称:aws,代码行数:30,代码来源:bucket.py

示例3: log_annotation

def log_annotation(collection, document, status, action, args):
    """
    Logs an annotation operation of type action in the given document
    of the given collection. Status is an arbitrary string marking the
    status of processing the request and args a dictionary giving
    the arguments of the action.
    """

    l = ann_logger()

    if not l:
        return False

    try:
        user = get_session()['user']
    except KeyError:
        user = 'anonymous'

    # avoid redundant logging (assuming first two args are
    # collection and document)
    # TODO: get rid of the assumption, parse the actual args
    other_args = args[2:]

    # special case for "log only" action: don't redundantly
    # record the uninformative action name, but treat the
    # first argument as the 'action'.
    if action == 'logAnnotatorAction':
        action = other_args[0]
        other_args = other_args[1:]

    l.info('%s\t%s\t%s\t%s\t%s\t%s' % (_detab(user), _detab(collection), 
                                       _detab(document), _detab(status), 
                                       _detab(action),
                                       '\t'.join([_detab(unicode(a)) for a in other_args])))
开发者ID:TsujiiLaboratory,项目名称:brat,代码行数:34,代码来源:annlog.py

示例4: post

    def post(self, key):
        """ Add a tag by the current user on a given photo """
        current_session = session.get_session()
        if not current_session or not current_session.is_active():
            self.error(403)
            return

        try:
            user = current_session['me']
        except KeyError:
            self.error(403)
            return

        try:
            photo = models.Photo.get(controllers.unquote(key))
        except db.BadKeyError:
            self.error(400)
            return

        tag = self.request.get('tag')

        logging.error(self.request.body)
        if not comment:
            logging.error('no tag')
            self.error(400)
            return

        # Prevent double tag
        tag = photo.tag_set.filter('tag = ', tag).filter('user = ', user).get()
        if not tag:
            tag = models.Tag(tag=tag, photo=photo, user=user)
            tag.put()

        self.redirect('/photos/%s' % key)
开发者ID:tmandarano,项目名称:Project-C,代码行数:34,代码来源:photo.py

示例5: user_update

def user_update(id, values, session=None):
    if not session:
        session = get_session()
    with session.begin():
        user_ref = user_get(id, session)
        user_ref.update(values)
        user_ref.save(session=session)
开发者ID:juvvadi,项目名称:keystone,代码行数:7,代码来源:api.py

示例6: get_buyhistory

def get_buyhistory(itemid):
    """ get buy history, first page only
    
    :param itemid: itemid for item
    :returns: list of (price/sold, sold/price, date) tuple
    """
    s = get_session()
    content = s.get('http://item.taobao.com/item.htm?id={}'.format(itemid)).content
    url = re.compile(r'detail:params="(.*?),showBuyerList').search(content).group(1)
    url += '&callback=jsonp'
    patjsonp = re.compile(r'jsonp\((.*?)\);?', re.DOTALL)
    s = get_blank_session()
    s.headers['Referer'] = 'http://detail.tmall.com/item.htm'
    try:
        content = s.get(url+'&callback=jsonp', timeout=30).content
        content = content.replace('\\"', '"')
        if content == 'jsonp({"status":1111,"wait":5})':
            print 'baned, sleeping for 5 mins'
            time.sleep(5*60)
            return get_buyhistory(itemid)
        ret1 = re.compile('<em class="tb-rmb-num">([^<]+)</em>.*?<td class="tb-amount">(\d+)</td>.*?<td class="tb-time">([^>]+)</td>', re.DOTALL).findall(content)
        ret2 = re.compile('<em>(\d+)</em>.*?<td>(\d+)</td>.*?<td>([^<]+)</td>', re.DOTALL).findall(content)
        ret1.extend(ret2)
        return ret1
    except:
        print '!!!', itemid
        traceback.print_exc()
开发者ID:mobishift2011,项目名称:data007,代码行数:27,代码来源:tbitem.py

示例7: model_query

def model_query(model, *args, **kwargs):
    """Query helper that accounts for context's `read_deleted` field.

    :param context: context to query under
    :param session: if present, the session to use
    :param read_deleted: if present, overrides context's read_deleted field.
    :param project_only: if present and context is user-type, then restrict
            query to match the context's project_id. If set to 'allow_none',
            restriction includes project_id = None.
    """
    session = kwargs.get('session') or get_session()
    read_deleted = kwargs.get('read_deleted') or 'no'

    query = session.query(model, *args)

    if read_deleted == 'no':
        query = query.filter_by(deleted=False)
    elif read_deleted == 'yes':
        pass  # omit the filter to include deleted and active
    elif read_deleted == 'only':
        query = query.filter_by(deleted=True)
    else:
        raise Exception(
                _("Unrecognized read_deleted value '%s'") % read_deleted)

    return query
开发者ID:tpiperatgod,项目名称:turtle-web,代码行数:26,代码来源:dbapi.py

示例8: login

def login(user, password):
    if not _is_authenticated(user, password):
        raise InvalidAuthError

    get_session()['user'] = user
    Messager.info('Hello!')
    return {}
开发者ID:AlexErmer,项目名称:CollaborativePDFAnnotation,代码行数:7,代码来源:auth.py

示例9: authorized

	def authorized(cls, identity):
		with get_session() as session:
			user = session.query( cls ).filter(cls.name == identity).first()
			if not user:
				return False
			else:
				return True
开发者ID:WeiShiwei,项目名称:tornado_glearn,代码行数:7,代码来源:orm.py

示例10: onp_check_session

def onp_check_session(request):
    if not _check_args(request, "session_id"):
        return not_enough_args(request)
    sess = session.get_session(request["session_id"])
    if not _session_checker(request, sess):
        return not_enough_rights(request)
    return {"error_code": 0, "id": request["id"], "admin_priv": sess["admin_priv"], "roles": sess["roles"]}
开发者ID:BHYCHIK,项目名称:Olimpiade-manager,代码行数:7,代码来源:onp_api.py

示例11: get_all

 def get_all(cls,
             session=None,
             columns=None,
             offset=None,
             limit=None,
             order_by=None,
             lock_mode=None):
     if not session:
         session = Session.get_session()
     if columns:
         if isinstance(columns, (tuple, list)):
             query = session.query(*columns)
         else:
             query = session.query(columns)
             if isinstance(columns, str):
                 query = query.select_from(cls)
     else:
         query = session.query(cls)
     if order_by is not None:
         if isinstance(order_by, (tuple, list)):
             query = query.order_by(*order_by)
         else:
             query = query.order_by(order_by)
     if offset:
         query = query.offset(offset)
     if limit:
         query = query.limit(limit)
     if lock_mode:
         query = query.with_lockmode(lock_mode)
     return query.all()
开发者ID:fz1989,项目名称:NERV_OJ,代码行数:30,代码来源:base.py

示例12: count_all

 def count_all(cls, session=None, lock_mode=None):
     if not session:
         session = Session.get_session()
     query = session.query(func.count('*')).select_from(cls)
     if lock_mode:
         query = query.with_lockmode(lock_mode)
     return query.scalar()
开发者ID:fz1989,项目名称:NERV_OJ,代码行数:7,代码来源:base.py

示例13: tenant_group_get

def tenant_group_get(id, tenant, session=None):
    if not session:
        session = get_session()
    result = session.query(models.Group).filter_by(id=id, \
            tenant_id=tenant).first()

    return result
开发者ID:juvvadi,项目名称:keystone,代码行数:7,代码来源:api.py

示例14: get_by_all

    def get_by_all(cls,
                   key,
                   value,
                   session=None,
                   columns=None,
                   lock_mode=None):

        if not session:
            session = Session.get_session()
        if hasattr(cls, key):
            scalar = False
            if columns:
                if isinstance(columns, (tuple, list)):
                    query = session.query(*columns)
                else:
                    scalar = True
                    query = session.query(columns)
            else:
                query = session.query(cls)
            if lock_mode:
                query = query.with_lockmode(lock_mode)
            query = query.filter(getattr(cls, key) == value)
            if scalar:
                return query.scalar()
            return query.all()
        return None
开发者ID:fz1989,项目名称:NERV_OJ,代码行数:26,代码来源:base.py

示例15: tenant_group_is_empty

def tenant_group_is_empty(id, session=None):
    if not session:
        session = get_session()
    a_user = session.query(models.UserGroupAssociation).filter_by(
        group_id=id).first()
    if a_user != None:
        return False
    return True
开发者ID:juvvadi,项目名称:keystone,代码行数:8,代码来源:api.py


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