more relative imports
Before adoption: this commit came in with the history the project adopted, so no landing records it.
_identifier exports a compiled regex instead of a string to avoid some tricky cleanup
authored by David Lord · committed by David Lord · parent 963b5d3 · Browse files · 8 files·+32 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+32 added−33 removed
- other:+32 added−33 removed
Provenance
- Commit
126fce8- Tree
05d39bd- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
963b5d3
8 files changed+32 added−33 removed
modified:scripts/generate_identifier_pattern.py+7 added-4 removed
56 unmodified lines57 return "".join(out)58 59 60 def main():61- """Build the regex pattern and write it to the file62- :file:`jinja2/_identifier.py`."""61+ """Build the regex pattern and write it to62+ ``jinja2/_identifier.py``.63+ """64 pattern = build_pattern(collapse_ranges(get_characters()))65 filename = os.path.abspath(66 os.path.join(os.path.dirname(__file__), "..", "src", "jinja2", "_identifier.py")67 )68 69 with open(filename, "w", encoding="utf8") as f:69- f.write("")70+ f.write("import re\n\n")71 f.write("# generated by scripts/generate_identifier_pattern.py\n")72+ f.write("pattern = re.compile(\n")71- f.write('pattern = "{}" # noqa: B950\n'.format(pattern))73+ f.write(' r"[\\w{}]+" # noqa: B950\n'.format(pattern))74+ f.write(")\n")75 76 77 if __name__ == "__main__":78 main()modified:src/jinja2/_identifier.py+5 added-1 removed
1+import re2+3 # generated by scripts/generate_identifier_pattern.py2-pattern = "·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-ٰٟۖ-ۜ۟-۪ۤۧۨ-ܑۭܰ-݊ަ-ް߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣔ-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣঁ-ঃ়া-ৄেৈো-্ৗৢৣਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑੰੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣஂா-ூெ-ைொ-்ௗఀ-ఃా-ౄె-ైొ-్ౕౖౢౣಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣංඃ්ා-ුූෘ-ෟෲෳัิ-ฺ็-๎ັິ-ູົຼ່-ໍ༹༘༙༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏႚ-ႝ፝-፟ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝᠋-᠍ᢅᢆᢩᤠ-ᤫᤰ-᤻ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼᪰-᪽ᬀ-ᬄ᬴-᭄᭫-᭳ᮀ-ᮂᮡ-ᮭ᯦-᯳ᰤ-᰷᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰℘℮⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣠-꣱ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀ꧥꨩ-ꨶꩃꩌꩍꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭ﬞ︀-️︠-︯︳︴﹍-﹏_𐇽𐋠𐍶-𐍺𐨁-𐨃𐨅𐨆𐨌-𐨏𐨸-𐨿𐨺𐫦𐫥𑀀-𑀂𑀸-𑁆𑁿-𑂂𑂰-𑂺𑄀-𑄂𑄧-𑅳𑄴𑆀-𑆂𑆳-𑇊𑇀-𑇌𑈬-𑈷𑈾𑋟-𑋪𑌀-𑌃𑌼𑌾-𑍄𑍇𑍈𑍋-𑍍𑍗𑍢𑍣𑍦-𑍬𑍰-𑍴𑐵-𑑆𑒰-𑓃𑖯-𑖵𑖸-𑗀𑗜𑗝𑘰-𑙀𑚫-𑚷𑜝-𑜫𑰯-𑰶𑰸-𑰿𑲒-𑲧𑲩-𑲶𖫰-𖫴𖬰-𖬶𖽑-𖽾𖾏-𖾒𛲝𛲞𝅥-𝅩𝅭-𝅲𝅻-𝆂𝆅-𝆋𝆪-𝆭𝉂-𝉄𝨀-𝨶𝨻-𝩬𝩵𝪄𝪛-𝪟𝪡-𝪯𞀀-𞀆𞀈-𞀘𞀛-𞀡𞀣𞀤𞀦-𞣐𞀪-𞣖𞥄-𞥊󠄀-󠇯" # noqa: B9504+pattern = re.compile(5+ r"[\w·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-ٰٟۖ-ۜ۟-۪ۤۧۨ-ܑۭܰ-݊ަ-ް߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛ࣔ-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣঁ-ঃ়া-ৄেৈো-্ৗৢৣਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑੰੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣஂா-ூெ-ைொ-்ௗఀ-ఃా-ౄె-ైొ-్ౕౖౢౣಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣഁ-ഃാ-ൄെ-ൈൊ-്ൗൢൣංඃ්ා-ුූෘ-ෟෲෳัิ-ฺ็-๎ັິ-ູົຼ່-ໍ༹༘༙༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏႚ-ႝ፝-፟ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝᠋-᠍ᢅᢆᢩᤠ-ᤫᤰ-᤻ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼᪰-᪽ᬀ-ᬄ᬴-᭄᭫-᭳ᮀ-ᮂᮡ-ᮭ᯦-᯳ᰤ-᰷᳐-᳔᳒-᳨᳭ᳲ-᳴᳸᳹᷀-᷵᷻-᷿‿⁀⁔⃐-⃥⃜⃡-⃰℘℮⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-ꣅ꣠-꣱ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀ꧥꨩ-ꨶꩃꩌꩍꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭ﬞ︀-️︠-︯︳︴﹍-﹏_𐇽𐋠𐍶-𐍺𐨁-𐨃𐨅𐨆𐨌-𐨏𐨸-𐨿𐨺𐫦𐫥𑀀-𑀂𑀸-𑁆𑁿-𑂂𑂰-𑂺𑄀-𑄂𑄧-𑅳𑄴𑆀-𑆂𑆳-𑇊𑇀-𑇌𑈬-𑈷𑈾𑋟-𑋪𑌀-𑌃𑌼𑌾-𑍄𑍇𑍈𑍋-𑍍𑍗𑍢𑍣𑍦-𑍬𑍰-𑍴𑐵-𑑆𑒰-𑓃𑖯-𑖵𑖸-𑗀𑗜𑗝𑘰-𑙀𑚫-𑚷𑜝-𑜫𑰯-𑰶𑰸-𑰿𑲒-𑲧𑲩-𑲶𖫰-𖫴𖬰-𖬶𖽑-𖽾𖾏-𖾒𛲝𛲞𝅥-𝅩𝅭-𝅲𝅻-𝆂𝆅-𝆋𝆪-𝆭𝉂-𝉄𝨀-𝨶𝨻-𝩬𝩵𝪄𝪛-𝪟𝪡-𝪯𞀀-𞀆𞀈-𞀘𞀛-𞀡𞀣𞀤𞀦-𞣐𞀪-𞣖𞥄-𞥊󠄀-󠇯]+" # noqa: B9506+)modified:src/jinja2/asyncsupport.py+4 added-4 removed
140 unmodified lines141 return TemplateModule(self, context, body_stream)142 143 144 def patch_template():145- from jinja2 import Template145+ from . import Template146 147 Template.generate = wrap_generate_func(Template.generate)148 Template.generate_async = update_wrapper(generate_async, Template.generate_async)149 Template.render_async = update_wrapper(render_async, Template.render_async)5 unmodified lines155 )156 157 158 def patch_runtime():159- from jinja2.runtime import BlockReference, Macro159+ from .runtime import BlockReference, Macro160 161 BlockReference.__call__ = wrap_block_reference_call(BlockReference.__call__)162 Macro._invoke = wrap_macro_invoke(Macro._invoke)163 164 165 def patch_filters():166- from jinja2.filters import FILTERS167- from jinja2.asyncfilters import ASYNC_FILTERS166+ from .filters import FILTERS167+ from .asyncfilters import ASYNC_FILTERS168 169 FILTERS.update(ASYNC_FILTERS)170 171 99 unmodified linesmodified:src/jinja2/compiler.py+1 added-1 removed
718 unmodified lines719 def visit_Template(self, node, frame=None):720 assert frame is None, "no root frame allowed"721 eval_ctx = EvalContext(self.environment, self.name)722 723- from jinja2.runtime import __all__ as exported723+ from .runtime import __all__ as exported724 725 self.writeline("from __future__ import %s" % ", ".join(code_features))726 self.writeline("from jinja2.runtime import " + ", ".join(exported))727 1123 unmodified linesmodified:src/jinja2/environment.py+3 added-3 removed
365 unmodified lines366 self.enable_async = enable_async367 self.is_async = self.enable_async and have_async_gen368 if self.is_async:369 # runs patch_all() to enable async support370- import jinja2.asyncsupport # noqa: F401370+ from . import asyncsupport # noqa: F401371 372 _environment_sanity_check(self)373 374 def add_extension(self, extension):342 unmodified lines717 don't give much benefit.718 719 .. versionadded:: 2.4720 """721- from jinja2.loaders import ModuleLoader721+ from .loaders import ModuleLoader722 723 if log_function is None:724 725 def log_function(x):105 unmodified lines831 def handle_exception(self, source=None):832 """Exception handling helper. This is used internally to either raise833 rewritten exceptions or return a rendered traceback for the template.834 """835- from jinja2.debug import rewrite_traceback_stack835+ from .debug import rewrite_traceback_stack836 837 reraise(*rewrite_traceback_stack(source=source))838 839 def join_path(self, template, parent):528 unmodified linesmodified:src/jinja2/exceptions.py+2 added-2 removed
62 unmodified lines63 def __init__(self, name, message=None):64 IOError.__init__(self, name)65 66 if message is None:67- from jinja2.runtime import Undefined67+ from .runtime import Undefined68 69 if isinstance(name, Undefined):70 name._fail_with_undefined_error()71 20 unmodified lines92 """93 94 def __init__(self, names=(), message=None):95 if message is None:96- from jinja2.runtime import Undefined96+ from .runtime import Undefined97 98 parts = []99 100 for name in names:86 unmodified linesmodified:src/jinja2/lexer.py+4 added-13 removed
53 unmodified lines54 try:55 # check if this Python supports Unicode identifiers56 compile("föö", "<unknown>", "eval")57 except SyntaxError:58- # no Unicode support, use ASCII identifiers58+ # Python 2, no Unicode support, use ASCII identifiers59 name_re = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*")60 check_ident = False61 else:62- # Unicode support, build a pattern to match valid characters, and set flag63- # to use str.isidentifier to validate during lexing64- from jinja2 import _identifier62+ # Unicode support, import generated re pattern and set flag to use63+ # str.isidentifier to validate during lexing.64+ from ._identifier import pattern as name_re65 66- name_re = re.compile(r"[\w{0}]+".format(_identifier.pattern))66 check_ident = True68- # remove the pattern from memory after building the regex69- import sys67 71- del sys.modules["jinja2._identifier"]72- import jinja273-74- del jinja2._identifier75- del _identifier76-68 # internal the tokens and keep references to them69 TOKEN_ADD = intern("add")70 TOKEN_ASSIGN = intern("assign")71 TOKEN_COLON = intern("colon")780 unmodified linesmodified:src/jinja2/utils.py+6 added-5 removed
11 unmodified lines12 import os13 import re14 import warnings15 from collections import deque16+from random import choice17+from random import randrange18 from threading import Lock19 20 from markupsafe import escape21 from markupsafe import Markup84 unmodified lines106 if is_undefined(var):107 return default108 return var109 """108- from jinja2.runtime import Undefined110+ from .runtime import Undefined111 112 return isinstance(obj, Undefined)113 114 8 unmodified lines123 used so that Jinja doesn't have to recreate environments and lexers all124 the time. Normally you don't have to care about that but if you are125 measuring memory consumption you may want to clean the caches.126 """125- from jinja2.environment import _spontaneous_environments126- from jinja2.lexer import _lexer_cache127+ from .environment import _spontaneous_environments128+ from .lexer import _lexer_cache129 130 _spontaneous_environments.clear()131 _lexer_cache.clear()132 128 unmodified lines261 262 263 def generate_lorem_ipsum(n=5, html=True, min=20, max=100):264 """Generate some lorem ipsum for the template."""263- from jinja2.constants import LOREM_IPSUM_WORDS264- from random import choice, randrange265+ from .constants import LOREM_IPSUM_WORDS266 267 words = LOREM_IPSUM_WORDS.split()268 result = []269 467 unmodified lines