
from django import template

# For Django >= 1.5, use the default verbatim tag implementation
if not hasattr(template.defaulttags, 'verbatim'):
    register = template.Library()

    class VerbatimNode(template.Node):

        def __init__(self, text):
            self.text = text
        
        def render(self, context):
            return self.text


    @register.tag
    def verbatim(parser, token):
        text = []
        while 1:
            token = parser.tokens.pop(0)
            if token.contents == 'endverbatim':
                break
            if token.token_type == template.TOKEN_VAR:
                text.append('{{')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('{%')
            text.append(token.contents)
            if token.token_type == template.TOKEN_VAR:
                text.append('}}')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('%}')
        return VerbatimNode(''.join(text))


from django import template

register = template.Library()

# For Django >= 1.5, use the default verbatim tag implementation
if not hasattr(template.defaulttags, 'verbatim'):
    class VerbatimNode(template.Node):

        def __init__(self, text):
            self.text = text
        
        def render(self, context):
            return self.text


    @register.tag
    def verbatim(parser, token):
        text = []
        while 1:
            token = parser.tokens.pop(0)
            if token.contents == 'endverbatim':
                break
            if token.token_type == template.TOKEN_VAR:
                text.append('{{')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('{%')
            text.append(token.contents)
            if token.token_type == template.TOKEN_VAR:
                text.append('}}')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('%}')
        return VerbatimNode(''.join(text))

Move register outside of guard
Move register outside of guard

Even if we don't load the ``verbatim`` tag backbport, the module
still needs to have a ``register`` variable.

Addresses #660

  
  from django import template
  
+ register = template.Library()
+ 
  # For Django >= 1.5, use the default verbatim tag implementation
  if not hasattr(template.defaulttags, 'verbatim'):
-     register = template.Library()
- 
      class VerbatimNode(template.Node):
  
          def __init__(self, text):
              self.text = text
          
          def render(self, context):
              return self.text
  
  
      @register.tag
      def verbatim(parser, token):
          text = []
          while 1:
              token = parser.tokens.pop(0)
              if token.contents == 'endverbatim':
                  break
              if token.token_type == template.TOKEN_VAR:
                  text.append('{{')
              elif token.token_type == template.TOKEN_BLOCK:
                  text.append('{%')
              text.append(token.contents)
              if token.token_type == template.TOKEN_VAR:
                  text.append('}}')
              elif token.token_type == template.TOKEN_BLOCK:
                  text.append('%}')
          return VerbatimNode(''.join(text))
  
Move register outside of guard
## Code Before:

from django import template

# For Django >= 1.5, use the default verbatim tag implementation
if not hasattr(template.defaulttags, 'verbatim'):
    register = template.Library()

    class VerbatimNode(template.Node):

        def __init__(self, text):
            self.text = text
        
        def render(self, context):
            return self.text


    @register.tag
    def verbatim(parser, token):
        text = []
        while 1:
            token = parser.tokens.pop(0)
            if token.contents == 'endverbatim':
                break
            if token.token_type == template.TOKEN_VAR:
                text.append('{{')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('{%')
            text.append(token.contents)
            if token.token_type == template.TOKEN_VAR:
                text.append('}}')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('%}')
        return VerbatimNode(''.join(text))

## Instruction:
Move register outside of guard
## Code After:

from django import template

register = template.Library()

# For Django >= 1.5, use the default verbatim tag implementation
if not hasattr(template.defaulttags, 'verbatim'):
    class VerbatimNode(template.Node):

        def __init__(self, text):
            self.text = text
        
        def render(self, context):
            return self.text


    @register.tag
    def verbatim(parser, token):
        text = []
        while 1:
            token = parser.tokens.pop(0)
            if token.contents == 'endverbatim':
                break
            if token.token_type == template.TOKEN_VAR:
                text.append('{{')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('{%')
            text.append(token.contents)
            if token.token_type == template.TOKEN_VAR:
                text.append('}}')
            elif token.token_type == template.TOKEN_BLOCK:
                text.append('%}')
        return VerbatimNode(''.join(text))
