from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe

register = template.Library()


def obfuscate_string(value):
    return ''.join(['&#%s;'.format(str(ord(char))) for char in value])


@register.filter
@stringfilter
def obfuscate(value):
    return mark_safe(obfuscate_string(value))


@register.filter
@stringfilter
def obfuscate_mailto(value, text=False):
    mail = obfuscate_string(value)

    if text:
        link_text = text
    else:
        link_text = mail

    return mark_safe('<a href="%s%s">%s</a>'.format(
        obfuscate_string('mailto:'), mail, link_text))

from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe

register = template.Library()


def obfuscate_string(value):
    return ''.join(['&#{0:s};'.format(str(ord(char))) for char in value])


@register.filter
@stringfilter
def obfuscate(value):
    return mark_safe(obfuscate_string(value))


@register.filter
@stringfilter
def obfuscate_mailto(value, text=False):
    mail = obfuscate_string(value)

    if text:
        link_text = text
    else:
        link_text = mail

    return mark_safe('<a href="{0:s}{1:s}">{2:s}</a>'.format(
        obfuscate_string('mailto:'), mail, link_text))

Fix mixup of old and new-style string formatting
Fix mixup of old and new-style string formatting
  from django import template
  from django.template.defaultfilters import stringfilter
  from django.utils.safestring import mark_safe
  
  register = template.Library()
  
  
  def obfuscate_string(value):
-     return ''.join(['&#%s;'.format(str(ord(char))) for char in value])
+     return ''.join(['&#{0:s};'.format(str(ord(char))) for char in value])
  
  
  @register.filter
  @stringfilter
  def obfuscate(value):
      return mark_safe(obfuscate_string(value))
  
  
  @register.filter
  @stringfilter
  def obfuscate_mailto(value, text=False):
      mail = obfuscate_string(value)
  
      if text:
          link_text = text
      else:
          link_text = mail
  
-     return mark_safe('<a href="%s%s">%s</a>'.format(
+     return mark_safe('<a href="{0:s}{1:s}">{2:s}</a>'.format(
          obfuscate_string('mailto:'), mail, link_text))
  
Fix mixup of old and new-style string formatting
## Code Before:
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe

register = template.Library()


def obfuscate_string(value):
    return ''.join(['&#%s;'.format(str(ord(char))) for char in value])


@register.filter
@stringfilter
def obfuscate(value):
    return mark_safe(obfuscate_string(value))


@register.filter
@stringfilter
def obfuscate_mailto(value, text=False):
    mail = obfuscate_string(value)

    if text:
        link_text = text
    else:
        link_text = mail

    return mark_safe('<a href="%s%s">%s</a>'.format(
        obfuscate_string('mailto:'), mail, link_text))

## Instruction:
Fix mixup of old and new-style string formatting
## Code After:
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe

register = template.Library()


def obfuscate_string(value):
    return ''.join(['&#{0:s};'.format(str(ord(char))) for char in value])


@register.filter
@stringfilter
def obfuscate(value):
    return mark_safe(obfuscate_string(value))


@register.filter
@stringfilter
def obfuscate_mailto(value, text=False):
    mail = obfuscate_string(value)

    if text:
        link_text = text
    else:
        link_text = mail

    return mark_safe('<a href="{0:s}{1:s}">{2:s}</a>'.format(
        obfuscate_string('mailto:'), mail, link_text))
