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


Python web.py方法代码示例

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


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

示例1: create_lti_session

# 需要导入模块: import web [as 别名]
# 或者: from web import py [as 别名]
def create_lti_session(self, user_id, roles, realname, email, course_id, task_id, consumer_key, outcome_service_url,
                           outcome_result_id, tool_name, tool_desc, tool_url, context_title, context_label):
        """ Creates an LTI cookieless session. Returns the new session id"""

        self._destroy_session()  # don't forget to destroy the current session (cleans the threaded dict from web.py)
        self._session.load('')  # creates a new cookieless session
        session_id = self._session.session_id

        self._session.lti = {
            "email": email,
            "username": user_id,
            "realname": realname,
            "roles": roles,
            "task": (course_id, task_id),
            "outcome_service_url": outcome_service_url,
            "outcome_result_id": outcome_result_id,
            "consumer_key": consumer_key,
            "context_title": context_title,
            "context_label": context_label,
            "tool_description": tool_desc,
            "tool_name": tool_name,
            "tool_url": tool_url
        }

        return session_id 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:27,代码来源:user_manager.py

示例2: __init__

# 需要导入模块: import web [as 别名]
# 或者: from web import py [as 别名]
def __init__(self, session_storage):
        """
        :param session_storage: a Storage object, where sessions will be saved
        """
        super(CookieLessCompatibleApplication, self).__init__((), globals(), autoreload=False)
        self._session = CookieLessCompatibleSession(self, session_storage)
        self._translations = {}

        # hacky fix until web.py is fixed
        self.processors = [self.fix_unloadhook(x) for x in self.processors] 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:12,代码来源:cookieless_app.py

示例3: init_mapping

# 需要导入模块: import web [as 别名]
# 或者: from web import py [as 别名]
def init_mapping(self, mapping):
        # The following method is copied from the web/utils.py file in order to fix a problem with python3.7+
        # Due to PEP 479 (https://www.python.org/dev/peps/pep-0479/), Python3.7+ won't accept anymore generators raising
        # StopIteration instead returning.
        def group(seq, size):
            """
            Returns an iterator over a series of lists of length size from iterable.
                >>> list(group([1,2,3,4], 2))
                [[1, 2], [3, 4]]
                >>> list(group([1,2,3,4,5], 2))
                [[1, 2], [3, 4], [5]]
            """
            def take(seq, n):
                for i in range(n):
                    # The except clause is the added part to this method
                    try:
                        yield next(seq)
                    except StopIteration:
                        break

            if not hasattr(seq, 'next'):
                seq = iter(seq)
            while True:
                x = list(take(seq, size))
                if x:
                    yield x
                else:
                    break

        self.mapping = [(r"(/@[a-f0-9A-F_]*@)?" +a, b) for a,b in group(mapping, 2)] 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:32,代码来源:cookieless_app.py

示例4: _make_response

# 需要导入模块: import web [as 别名]
# 或者: from web import py [as 别名]
def _make_response(self, content, headers, status):
        return content

# web.py implementation 
开发者ID:yfauser,项目名称:planespotter,代码行数:6,代码来源:mimerender.py

示例5: fix_unloadhook

# 需要导入模块: import web [as 别名]
# 或者: from web import py [as 别名]
def fix_unloadhook(self, orig_func):
        """ Fix web.py that raises StopIterations everywhere.

            The bug in web.py lies (partly) on line 574 of application.py:

                def build_result(result):
                    for r in result:
                        if PY2:
                            yield utils.safestr(r)

            The for loop "r in result" fails as result is a generator that raise sometimes StopIteration.
            This is difficult to fix directly without modifying webpy in a lot of place, so we prefer fixing the symptoms.

            When you do next(x) on a generator, and that this generator raise a StopIteration, next() catches the
            StopIteration and raise in return a RuntimeError(("generator raised StopIteration",)).

            That's what we catch here.

            The generator is then given to another one, then to another one, etc, until it reaches the function
            "unloadhook", that is a preprocessor, and is init by the constructor of the web.application (i.e. the super
            constructor of this class) and is put inside the self.processors array.

            We apply the fix on all processors as we can't find the one that is actually the one created by unloadhook
            by inspection. This should not change anything.
        """
        def fix_generator(orig_generator):
            try:
                yield from orig_generator
            except RuntimeError as e:
                if e.args != ("generator raised StopIteration",):
                    raise

        def fix(x):
            y = orig_func(x)
            # the wsgi process thingy differentiates things that are a generator from things that are not one
            # we need to fix only the generators
            if is_iter(y): # web.py uses this to check for generators. A more "safe" way to do it would be to use
                           # inspect.isgenerator(y) or inspect.isgeneratorfunction(y), but like this we ensure
                           # we mimic the behavior of web.py
                return fix_generator(y)
            return y
        return fix 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:44,代码来源:cookieless_app.py


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