From ce677103251180952bd27b6559e3fc87e6b518b7 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 17 Aug 2008 19:43:22 +0200 Subject: [PATCH] More work on the ironpython support --HG-- branch : trunk --- jinja2/_ipysupport.py | 40 ++++++++++++++++++++++++++++++++++++++++ jinja2/loaders.py | 6 +++++- jinja2/runtime.py | 11 ++++------- 3 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 jinja2/_ipysupport.py diff --git a/jinja2/_ipysupport.py b/jinja2/_ipysupport.py new file mode 100644 index 0000000..22ae823 --- /dev/null +++ b/jinja2/_ipysupport.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +""" + jinja2._ipysupport + ~~~~~~~~~~~~~~~~~~ + + IronPython support library. This library exports functionality from + the CLR to Python that is normally available in the standard library. + + :copyright: Copyright 2008 by Armin Ronacher. + :license: BSD. +""" +from System import DateTime +from System.IO import Path, File, FileInfo + + +epoch = DateTime(1970, 1, 1) + + +class _PathModule(object): + """A minimal path module.""" + + sep = str(Path.DirectorySeparatorChar) + altsep = str(Path.AltDirectorySeparatorChar) + pardir = '..' + + def join(self, path, *args): + args = list(args[::-1]) + while args: + path = Path.Combine(path, args.pop()) + return path + + def isfile(self, filename): + return File.Exists(filename) + + def getmtime(self, filename): + info = FileInfo(filename) + return int((info.LastAccessTimeUtc - epoch).TotalSeconds) + + +path = _PathModule() diff --git a/jinja2/loaders.py b/jinja2/loaders.py index e964fdc..c97b5bf 100644 --- a/jinja2/loaders.py +++ b/jinja2/loaders.py @@ -8,7 +8,11 @@ :copyright: 2008 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ -from os import path +try: + from os import path +except ImportError: + # support for iron python without standard library + from _ipysupport import path try: from hashlib import sha1 except ImportError: diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 2c3aeb0..9b2c3a5 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -10,7 +10,8 @@ """ import sys from itertools import chain, imap -from jinja2.utils import Markup, partial, soft_unicode, escape, missing, concat +from jinja2.utils import Markup, partial, soft_unicode, escape, missing, \ + concat, MethodType, FunctionType from jinja2.exceptions import UndefinedError, TemplateRuntimeError @@ -20,12 +21,8 @@ __all__ = ['LoopContext', 'Context', 'TemplateReference', 'Macro', 'Markup', 'markup_join', 'unicode_join'] -#: get the types we support for context functions. We do not use types because -#: IronPython doesn't provide that module out of the box. -class _C(object): - meth = lambda: None -_context_function_types = (type(lambda: None), type(_C.meth)) -del _C +#: the types we support for context functions +_context_function_types = (FunctionType, MethodType) def markup_join(seq): -- 2.26.2