Ticket #2539: template_01.diff

File template_01.diff, 5.6 KB (added by limodou@…, 20 years ago)

Fix regular pattern [\w.]+ to [\w\.]+

  • template/__init__.py

     
    6060from django.template.context import Context, RequestContext, ContextPopException
    6161from django.utils.functional import curry
    6262from django.utils.text import smart_split
     63
    6364
    6465__all__ = ('Template', 'Context', 'RequestContext', 'compile_string')
    6566
     
    223224        self.tokens = tokens
    224225        self.tags = {}
    225226        self.filters = {}
     227
    226228        for lib in builtins:
    227229            self.add_library(lib)
    228230
     
    251253                # execute callback function for this tag and append resulting node
    252254                self.enter_command(command, token)
    253255                try:
    254                     compile_func = self.tags[command]
     256                    compile_func = self.
    255257                except KeyError:
    256258                    self.invalid_block_tag(token, command)
    257259                try:
     
    317319    def add_library(self, lib):
    318320        self.tags.update(lib.tags)
    319321        self.filters.update(lib.filters)
     322
     323
     324
     325
    320326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
    321351    def compile_filter(self, token):
    322352        "Convenient wrapper for FilterExpression"
    323353        return FilterExpression(token, self)
    324354
    325355    def find_filter(self, filter_name):
    326         if self.filters.has_key(filter_name):
    327             return self.filters[filter_name]
    328         else:
     356        try:
     357            return self.get_filters(filter_name)
     358        except:
     359            import traceback
     360            traceback.print_exc()
    329361            raise TemplateSyntaxError, "Invalid filter: '%s'" % filter_name
     362
     363
     364
     365
    330366
    331367class DebugParser(Parser):
    332368    def __init__(self, lexer):
     
    468504^"(?P<constant>%(str)s)"|
    469505^(?P<var>[%(var_chars)s]+)|
    470506 (?:%(filter_sep)s
    471      (?P<filter_name>\w+)
     507     (?P<filter_name>+)
    472508         (?:%(arg_sep)s
    473509             (?:
    474510              %(i18n_open)s"(?P<i18n_arg>%(str)s)"%(i18n_close)s|
     
    873909            return func
    874910        return dec
    875911
     912
    876913def get_library(module_name):
    877914    lib = libraries.get(module_name, None)
    878915    if not lib:
    879916        try:
    880917            mod = __import__(module_name, '', '', [''])
     918
     919
     920
     921
     922
     923
     924
    881925        except ImportError, e:
     926
     927
    882928            raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e)
    883929        try:
    884930            lib = mod.register
     931
     932
     933
     934
    885935            libraries[module_name] = lib
    886936        except AttributeError:
    887937            raise InvalidTemplateLibrary, "Template library %s does not have a variable named 'register'" % module_name
  • template/defaulttags.py

     
    686686    for taglib in bits[1:]:
    687687        # add the library to the parser
    688688        try:
    689             lib = get_library("django.templatetags.%s" % taglib.split('.')[-1])
     689            if taglib.find('.') > -1:
     690                appname, module = taglib.split('.')
     691                taglib = '.'.join([appname, 'templatetags', module])
     692            lib = get_library("django.templatetags.%s" % taglib)
    690693            parser.add_library(lib)
    691694        except InvalidTemplateLibrary, e:
     695
     696
    692697            raise TemplateSyntaxError, "'%s' is not a valid tag library: %s" % (taglib, e)
    693698    return LoadNode()
    694699load = register.tag(load)
  • templatetags/__init__.py

     
    22
    33for a in settings.INSTALLED_APPS:
    44    try:
     5
    56        __path__.extend(__import__(a + '.templatetags', '', '', ['']).__path__)
    67    except ImportError:
    78        pass
Back to Top