More work on the ironpython support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent 833a3b5 · Browse files · 3 files·+49 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+49 added−8 removed
- other:+49 added−8 removed
Provenance
- Commit
ce67710- Tree
6444a92- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
833a3b5
3 files changed+49 added−8 removed
added:jinja2/_ipysupport.py+40 added
1+# -*- coding: utf-8 -*-2+"""3+ jinja2._ipysupport4+ ~~~~~~~~~~~~~~~~~~5+6+ IronPython support library. This library exports functionality from7+ the CLR to Python that is normally available in the standard library.8+9+ :copyright: Copyright 2008 by Armin Ronacher.10+ :license: BSD.11+"""12+from System import DateTime13+from System.IO import Path, File, FileInfo14+15+16+epoch = DateTime(1970, 1, 1)17+18+19+class _PathModule(object):20+ """A minimal path module."""21+22+ sep = str(Path.DirectorySeparatorChar)23+ altsep = str(Path.AltDirectorySeparatorChar)24+ pardir = '..'25+26+ def join(self, path, *args):27+ args = list(args[::-1])28+ while args:29+ path = Path.Combine(path, args.pop())30+ return path31+32+ def isfile(self, filename):33+ return File.Exists(filename)34+35+ def getmtime(self, filename):36+ info = FileInfo(filename)37+ return int((info.LastAccessTimeUtc - epoch).TotalSeconds)38+39+40+path = _PathModule()modified:jinja2/loaders.py+5 added-1 removed
6 unmodified lines7 8 :copyright: 2008 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11-from os import path11 try:12+ from os import path13+except ImportError:14+ # support for iron python without standard library15+ from _ipysupport import path16+try:17 from hashlib import sha118 except ImportError:19 from sha import new as sha120 from jinja2.exceptions import TemplateNotFound260 unmodified linesmodified:jinja2/runtime.py+4 added-7 removed
8 unmodified lines9 :license: BSD.10 """11 import sys12 from itertools import chain, imap13-from jinja2.utils import Markup, partial, soft_unicode, escape, missing, concat13+from jinja2.utils import Markup, partial, soft_unicode, escape, missing, \14+ concat, MethodType, FunctionType15 from jinja2.exceptions import UndefinedError, TemplateRuntimeError16 17 18 # these variables are exported to the template runtime1 unmodified line20 'TemplateRuntimeError', 'missing', 'concat', 'escape',21 'markup_join', 'unicode_join']22 23 23-#: get the types we support for context functions. We do not use types because24-#: IronPython doesn't provide that module out of the box.25-class _C(object):26- meth = lambda: None27-_context_function_types = (type(lambda: None), type(_C.meth))28-del _C24+#: the types we support for context functions25+_context_function_types = (FunctionType, MethodType)26 27 28 def markup_join(seq):29 """Concatenation that escapes if necessary and converts to unicode."""432 unmodified lines