源码

# -*- coding: utf-8 -*-
"""
flask._compat
~~~~~~~~~~~~~ Some py2/py3 compatibility support based on a stripped down
version of six so we don't have to depend on a specific version
of it. :copyright: © 2010 by the Pallets team.
:license: BSD, see LICENSE for more details.
""" import sys PY2 = sys.version_info[0] == 2
_identity = lambda x: x if not PY2:
text_type = str
string_types = (str,)
integer_types = (int,) iterkeys = lambda d: iter(d.keys())
itervalues = lambda d: iter(d.values())
iteritems = lambda d: iter(d.items()) from inspect import getfullargspec as getargspec
from io import StringIO def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
raise value implements_to_string = _identity else:
text_type = unicode
string_types = (str, unicode)
integer_types = (int, long) iterkeys = lambda d: d.iterkeys()
itervalues = lambda d: d.itervalues()
iteritems = lambda d: d.iteritems() from inspect import getargspec
from cStringIO import StringIO exec('def reraise(tp, value, tb=None):\n raise tp, value, tb') def implements_to_string(cls):
cls.__unicode__ = cls.__str__
cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
return cls def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
# This requires a bit of explanation: the basic idea is to make a
# dummy metaclass for one level of class instantiation that replaces
# itself with the actual metaclass.
class metaclass(type):
def __new__(cls, name, this_bases, d):
return meta(name, bases, d)
return type.__new__(metaclass, 'temporary_class', (), {}) # Certain versions of pypy have a bug where clearing the exception stack
# breaks the __exit__ function in a very peculiar way. The second level of
# exception blocks is necessary because pypy seems to forget to check if an
# exception happened until the next bytecode instruction?
#
# Relevant PyPy bugfix commit:
# https://bitbucket.org/pypy/pypy/commits/77ecf91c635a287e88e60d8ddb0f4e9df4003301
# According to ronan on #pypy IRC, it is released in PyPy2 2.3 and later
# versions.
#
# Ubuntu 14.04 has PyPy 2.2.1, which does exhibit this bug.
BROKEN_PYPY_CTXMGR_EXIT = False
if hasattr(sys, 'pypy_version_info'):
class _Mgr(object):
def __enter__(self):
return self
def __exit__(self, *args):
if hasattr(sys, 'exc_clear'):
# Python 3 (PyPy3) doesn't have exc_clear
sys.exc_clear()
try:
try:
with _Mgr():
raise AssertionError()
except:
raise
except TypeError:
BROKEN_PYPY_CTXMGR_EXIT = True
except AssertionError:
pass 解读 本模块主要是做了些兼容处理,主要从python2与其他版本进行比较。从这可以看出python2在编码等方面是有一定差异的,我们了解即可,以下一些关键语句就是对这种差异做兼容处理:
   text_type = unicode
string_types = (str, unicode)
   integer_types = (int, long)
   cls.__str__ = lambda x: x.__unicode__().encode('utf-8')

Flask源码阅读-第三篇(flask\_compat.py)的更多相关文章

  1. Flask源码阅读-第四篇(flask\app.py)

    flask.app该模块2000多行代码,主要完成应用的配置.初始化.蓝图注册.请求装饰器定义.应用的启动和监听,其中以下方法可以重点品读和关注 def setupmethod(f): @setupm ...

  2. SDWebImage源码阅读-第三篇

    这一篇讲讲不常用的一些方法. 1 sd_setImageWithPreviousCachedImageWithURL: placeholderImage: options: progress: com ...

  3. 【原】FMDB源码阅读(三)

    [原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...

  4. 【原】AFNetworking源码阅读(三)

    [原]AFNetworking源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇的话,主要是讲了如何通过构建一个request来生成一个data tas ...

  5. 【原】SDWebImage源码阅读(三)

    [原]SDWebImage源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1.SDWebImageDownloader中的downloadImageWithURL 我们 ...

  6. Redis源码阅读(三)集群-连接初始化

    Redis源码阅读(三)集群-连接建立 对于并发请求很高的生产环境,单个Redis满足不了性能要求,通常都会配置Redis集群来提高服务性能.3.0之后的Redis支持了集群模式. Redis官方提供 ...

  7. 【详解】ThreadPoolExecutor源码阅读(三)

    系列目录 [详解]ThreadPoolExecutor源码阅读(一) [详解]ThreadPoolExecutor源码阅读(二) [详解]ThreadPoolExecutor源码阅读(三) 线程数量的 ...

  8. Flask源码阅读-第一篇(flask包下的__main__.py)

    源码: # -*- coding: utf-8 -*-""" flask.__main__ ~~~~~~~~~~~~~~ Alias for flask.run for ...

  9. 【 js 基础 】【 源码学习 】backbone 源码阅读(三)浅谈 REST 和 CRUD

    最近看完了 backbone.js 的源码,这里对于源码的细节就不再赘述了,大家可以 star 我的源码阅读项目(https://github.com/JiayiLi/source-code-stud ...

随机推荐

  1. Vue音乐项目笔记(五)

    1.搜索列表的点击删除.删除全部的交互事件 https://blog.csdn.net/weixin_40814356/article/details/80496097 seach组件中放search ...

  2. 【洛谷p1932】A+B A-B A*B A/B A%B Problem

    (emmmm) 这道题成功让我见识到了Dev撤回的高端大气上档(dàng)次. A+B A-B A*B A/B A%B Problem[传送门](真是个优秀的高精) 算法:::::::(模板题弄这么费 ...

  3. 6月5 Smarty变量调节器

    变量调节器:<{$a|变量调节器}> 主要修改此页面的信息来了解变量调节器:test0605/main.php和模板文件:main0605.html 1.利用给定的变量调节器 capita ...

  4. WDA基础七:TABStrip

    这个组件很少用. 一般用这个,是为了页面好看,还有就是布局排版的问题,因为多个页签其实占的是一块地... 新建ELEMENT TABStrip,右键tabstrip,插入页签,需要几个加几个... 加 ...

  5. CRM 价格批导

    日了,好多代码....COPY别人的,懒得改了 *----------------------------------------------------------------------* *** ...

  6. MySql(六)单表查询

    十.单表查询 一.单表查询的语法 SELECT 字段1,字段2... FROM 表名 WHERE 条件 GROUP BY field HAVING 筛选 ORDER BY field LIMIT 限制 ...

  7. ASP.NET controller TO view 数据传递

    https://stackify.com/viewbag/ In the case of ASP.NET MVC, you have three ways to pass data from the ...

  8. MYSQL--服务器的安装

    MYSQL--服务器的安装 学java已经好久了,但是还是没有学会安装数据库,这次重装系统后自己学了学,昨天晚上刚刚装好,卸载了,再装一次,就想着把它笔记下来.要不又忘了.. 1.删除你的服务.在cm ...

  9. 部署项目到linux中报Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed

    @RequestMapping(value = "/security/login", method = RequestMethod.POST) public ModelAndVie ...

  10. CP-ABE的使用

    参考: http://acsc.cs.utexas.edu/cpabe/tutorial.html http://acsc.cs.utexas.edu/cpabe/ 事先先配置好cp-abe:http ...