Django

Code

Changeset 6971

Show
Ignore:
Timestamp:
12/22/07 13:16:39 (1 year ago)
Author:
adrian
Message:

Negligible formatting changes to django/template/init.py -- fixed some spacing issues, renamed NotImplemented? to NotImplementedError? and changed some 'raise' statements to use callable exceptions instead of the old-style comma technique

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/__init__.py

    r6970 r6971  
    300300 
    301301    def empty_variable(self, token): 
    302         raise self.error( token, "Empty variable tag") 
     302        raise self.error(token, "Empty variable tag") 
    303303 
    304304    def empty_block_tag(self, token): 
    305         raise self.error( token, "Empty block tag") 
     305        raise self.error(token, "Empty block tag") 
    306306 
    307307    def invalid_block_tag(self, token, command): 
    308         raise self.error( token, "Invalid block tag: '%s'" % command) 
     308        raise self.error(token, "Invalid block tag: '%s'" % command) 
    309309 
    310310    def unclosed_block_tag(self, parse_until): 
     
    335335            return self.filters[filter_name] 
    336336        else: 
    337             raise TemplateSyntaxError, "Invalid filter: '%s'" % filter_name 
     337            raise TemplateSyntaxError("Invalid filter: '%s'" % filter_name) 
    338338 
    339339def lexer_factory(*args, **kwargs): 
     
    367367    def top(self): 
    368368        "Overload this method to do the actual parsing and return the result." 
    369         raise NotImplemented 
     369        raise NotImplementedError() 
    370370 
    371371    def more(self): 
     
    376376        "Undoes the last microparser. Use this for lookahead and backtracking." 
    377377        if not len(self.backout): 
    378             raise TemplateSyntaxError, "back called without some previous parsing" 
     378            raise TemplateSyntaxError("back called without some previous parsing") 
    379379        self.pointer = self.backout.pop() 
    380380 
     
    384384        i = self.pointer 
    385385        if i >= len(subject): 
    386             raise TemplateSyntaxError, "expected another tag, found end of string: %s" % subject 
     386            raise TemplateSyntaxError("expected another tag, found end of string: %s" % subject) 
    387387        p = i 
    388388        while i < len(subject) and subject[i] not in (' ', '\t'): 
     
    400400        i = self.pointer 
    401401        if i >= len(subject): 
    402             raise TemplateSyntaxError, "Searching for value. Expected another value but found end of string: %s" % subject 
     402            raise TemplateSyntaxError("Searching for value. Expected another value but found end of string: %s" % subject) 
    403403        if subject[i] in ('"', "'"): 
    404404            p = i 
     
    407407                i += 1 
    408408            if i >= len(subject): 
    409                 raise TemplateSyntaxError, "Searching for value. Unexpected end of string in column %d: %s" % (i, subject
     409                raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject)
    410410            i += 1 
    411411            res = subject[p:i] 
     
    424424                        i += 1 
    425425                    if i >= len(subject): 
    426                         raise TemplateSyntaxError, "Searching for value. Unexpected end of string in column %d: %s" % (i, subject
     426                        raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject)
    427427                i += 1 
    428428            s = subject[p:i] 
     
    483483            start = match.start() 
    484484            if upto != start: 
    485                 raise TemplateSyntaxError, "Could not parse some characters: %s|%s|%s"  % \ 
    486                                            (token[:upto], token[upto:start], token[start:]) 
     485                raise TemplateSyntaxError("Could not parse some characters: %s|%s|%s"  % \ 
     486                                           (token[:upto], token[upto:start], token[start:])) 
    487487            if var == None: 
    488488                var, constant, i18n_constant = match.group("var", "constant", "i18n_constant") 
     
    493493                upto = match.end() 
    494494                if var == None: 
    495                     raise TemplateSyntaxError, "Could not find variable at start of %s" % token 
     495                    raise TemplateSyntaxError("Could not find variable at start of %s" % token) 
    496496                elif var.find(VARIABLE_ATTRIBUTE_SEPARATOR + '_') > -1 or var[0] == '_': 
    497                     raise TemplateSyntaxError, "Variables and attributes may not begin with underscores: '%s'" % var 
     497                    raise TemplateSyntaxError("Variables and attributes may not begin with underscores: '%s'" % var) 
    498498            else: 
    499499                filter_name = match.group("filter_name") 
     
    511511                upto = match.end() 
    512512        if upto != len(token): 
    513             raise TemplateSyntaxError, "Could not parse the remainder: '%s' from '%s'" % (token[upto:], token
     513            raise TemplateSyntaxError("Could not parse the remainder: '%s' from '%s'" % (token[upto:], token)
    514514        self.filters = filters 
    515515        self.var = Variable(var) 
     
    568568        except IndexError: 
    569569            # Not enough 
    570             raise TemplateSyntaxError, "%s requires %d arguments, %d provided" % (name, len(nondefs), plen
     570            raise TemplateSyntaxError("%s requires %d arguments, %d provided" % (name, len(nondefs), plen)
    571571 
    572572        # Defaults can be overridden. 
     
    577577        except IndexError: 
    578578            # Too many. 
    579             raise TemplateSyntaxError, "%s requires %d arguments, %d provided" % (name, len(nondefs), plen
     579            raise TemplateSyntaxError("%s requires %d arguments, %d provided" % (name, len(nondefs), plen)
    580580 
    581581        return True 
     
    797797        else: 
    798798            message = "%s takes between %s and %s arguments" % (name, bmin, bmax) 
    799         raise TemplateSyntaxError, message 
     799        raise TemplateSyntaxError(message) 
    800800    return node_class(bits) 
    801801 
     
    823823            return compile_function 
    824824        else: 
    825             raise InvalidTemplateLibrary, "Unsupported arguments to Library.tag: (%r, %r)", (name, compile_function
     825            raise InvalidTemplateLibrary("Unsupported arguments to Library.tag: (%r, %r)", (name, compile_function)
    826826 
    827827    def tag_function(self,func): 
     
    847847            return filter_func 
    848848        else: 
    849             raise InvalidTemplateLibrary, "Unsupported arguments to Library.filter: (%r, %r)", (name, filter_func
     849            raise InvalidTemplateLibrary("Unsupported arguments to Library.filter: (%r, %r)", (name, filter_func)
    850850 
    851851    def filter_function(self, func): 
     
    876876                    params = params[1:] 
    877877                else: 
    878                     raise TemplateSyntaxError, "Any tag function decorated with takes_context=True must have a first argument of 'context'" 
     878                    raise TemplateSyntaxError("Any tag function decorated with takes_context=True must have a first argument of 'context'") 
    879879 
    880880            class InclusionNode(Node): 
     
    913913            mod = __import__(module_name, {}, {}, ['']) 
    914914        except ImportError, e: 
    915             raise InvalidTemplateLibrary, "Could not load template library from %s, %s" % (module_name, e
     915            raise InvalidTemplateLibrary("Could not load template library from %s, %s" % (module_name, e)
    916916        try: 
    917917            lib = mod.register 
    918918            libraries[module_name] = lib 
    919919        except AttributeError: 
    920             raise InvalidTemplateLibrary, "Template library %s does not have a variable named 'register'" % module_name 
     920            raise InvalidTemplateLibrary("Template library %s does not have a variable named 'register'" % module_name) 
    921921    return lib 
    922922