关于flask框架的flask_scrip._compat
- compat是什么
- 源码
- Flask版本书写不同
compat是什么
compat 英文单词同胞的意思
compat的功能是在py的不同版本之间做兼容处理
一些py2/py3兼容性支持基于精简版的six,因此我们不必依赖于它的特定版本。
源码
# -*- coding: utf-8 -*-
"""flask_script._compat~~~~~~~~~~~~~~~~~~~~Some py2/py3 compatibility support based on a stripped downversion of six so we don't have to depend on a specific versionof it.:copyright: (c) 2013 by Armin Ronacher.:license: BSD, see LICENSE for more details.
"""
import sysPY2 = sys.version_info[0] == 2
PYPY = hasattr(sys, 'pypy_translation_info')
_identity = lambda x: xif not PY2:unichr = chrrange_type = rangetext_type = strstring_types = (str, )integer_types = (int, )iterkeys = lambda d: iter(d.keys())itervalues = lambda d: iter(d.values())iteritems = lambda d: iter(d.items())import picklefrom io import BytesIO, StringIONativeStringIO = StringIOdef reraise(tp, value, tb=None):if value.__traceback__ is not tb:raise value.with_traceback(tb)raise valueifilter = filterimap = mapizip = zipintern = sys.internimplements_iterator = _identityimplements_to_string = _identityencode_filename = _identityget_next = lambda x: x.__next__input = inputelse:unichr = unichrtext_type = unicoderange_type = xrangestring_types = (str, unicode)integer_types = (int, long)iterkeys = lambda d: d.iterkeys()itervalues = lambda d: d.itervalues()iteritems = lambda d: d.iteritems()import cPickle as picklefrom cStringIO import StringIO as BytesIO, StringIONativeStringIO = BytesIOexec('def reraise(tp, value, tb=None):\n raise tp, value, tb')from itertools import imap, izip, ifilterintern = interndef implements_iterator(cls):cls.next = cls.__next__del cls.__next__return clsdef implements_to_string(cls):cls.__unicode__ = cls.__str__cls.__str__ = lambda x: x.__unicode__().encode('utf-8')return clsget_next = lambda x: x.nextdef encode_filename(filename):if isinstance(filename, unicode):return filename.encode('utf-8')return filenameinput = raw_inputdef with_metaclass(meta, *bases):# 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. Because of internal type checks# we also need to make sure that we downgrade the custom metaclass# for one level to something closer to type (that's why __call__ and# __init__ comes back from type etc.).## This has the advantage over six.with_metaclass in that it does not# introduce dummy classes into the final MRO.class metaclass(meta):__call__ = type.__call____init__ = type.__init__def __new__(cls, name, this_bases, d):if this_bases is None:return type.__new__(cls, name, (), d)return meta(name, bases, d)return metaclass('temporary_class', None, {})try:from urllib.parse import quote_from_bytes as url_quote
except ImportError:from urllib import quote as url_quote
Flask版本书写不同
如遇到以下问题:
Traceback (most recent call last):File "D:/code/p11/sylpro/main.py", line 1, in <module>from flask_script import Manager,ServerFile "D:\code\p11\sylpro\venv\lib\site-packages\flask_script\__init__.py", line 15, in <module>from flask._compat import text_type
ModuleNotFoundError: No module named 'flask._compat'
可以降低版本至1.1.2及以下,
或者修改到如下图效果:
卸载命令如下
pip uninstall flask==1.1.2 这个是卸载指定版本的
pip uninstall flask 直接卸载python里面的flask也行
12
卸载后到报错的源码里面取改源码
修改一下
flask_script/init.py中
from ._compat import text_type
改成
from flask_script._compat import text_type 。
以上参考:Deng872347348