def translate(s, a, b=None, c=None):
 from sympy.core.compatibility import maketrans
 try:
  ''.translate(None, '')
  py3 = False
 except TypeError:
  py3 = True
 mr = {}
 if (a is None):
  assert (c is None)
  if (not b):
   return s
  c = b
  a = b = ''
 elif (type(a) is dict):
  short = {}
  for k in list(a.keys()):
   if ((len(k) == 1) and (len(a[k]) == 1)):
    short[k] = a.pop(k)
  mr = a
  c = b
  if short:
   (a, b) = [''.join(i) for i in list(zip(*short.items()))]
  else:
   a = b = ''
 else:
  assert (len(a) == len(b))
 if py3:
  if c:
   s = s.translate(maketrans('', '', c))
  s = replace(s, mr)
  return s.translate(maketrans(a, b))
 else:
  if c:
   c = list(c)
   rem = {}
   for i in range((-1), ((-1) - len(c)), (-1)):
    if (ord(c[i]) > 255):
     rem[c[i]] = ''
     c.pop(i)
   s = s.translate(None, ''.join(c))
   s = replace(s, rem)
   if a:
    a = list(a)
    b = list(b)
    for i in range((-1), ((-1) - len(a)), (-1)):
     if ((ord(a[i]) > 255) or (ord(b[i]) > 255)):
      mr[a.pop(i)] = b.pop(i)
    a = ''.join(a)
    b = ''.join(b)
  s = replace(s, mr)
  table = maketrans(a, b)
  if ((type(table) is str) and (type(s) is str)):
   s = s.translate(table)
  else:
   s = s.translate(dict([(i, ord(c)) for (i, c) in enumerate(table)]))
  return s

def translate ( s , a , b = None , c = None ) : from sympy . core . compatibility import maketrans try : . translate ( None , '' ) py3 = False except TypeError : py3 = True mr = { } if ( a is None ) : assert ( c is None ) if ( not b ) : return s c = b a = b = '' elif ( type ( a ) is dict ) : short = { } for k in list ( a . keys ( ) ) : if ( ( len ( k ) == 1 ) and ( len ( a [ k ] ) == 1 ) ) : short [ k ] = a . pop ( k ) mr = a c = b if short : ( a , b ) = [ '' . join ( i ) for i in list ( zip ( * short . items ( ) ) ) ] else : a = b = '' else : assert ( len ( a ) == len ( b ) ) if py3 : if c : s = s . translate ( maketrans ( '' , '' , c ) ) s = replace ( s , mr ) return s . translate ( maketrans ( a , b ) ) else : if c : c = list ( c ) rem = { } for i in range ( ( - 1 ) , ( ( - 1 ) - len ( c ) ) , ( - 1 ) ) : if ( ord ( c [ i ] ) > 255 ) : rem [ c [ i ] ] = '' c . pop ( i ) s = s . translate ( None , '' . join ( c ) ) s = replace ( s , rem ) if a : a = list ( a ) b = list ( b ) for i in range ( ( - 1 ) , ( ( - 1 ) - len ( a ) ) , ( - 1 ) ) : if ( ( ord ( a [ i ] ) > 255 ) or ( ord ( b [ i ] ) > 255 ) ) : mr [ a . pop ( i ) ] = b . pop ( i ) a = '' . join ( a ) b = '' . join ( b ) s = replace ( s , mr ) table = maketrans ( a , b ) if ( ( type ( table ) is str ) and ( type ( s ) is str ) ) : s = s . translate ( table ) else : s = s . translate ( dict ( [ ( i , ord ( c ) ) for ( i , c ) in enumerate ( table ) ] ) ) return s
ajax handler for translating .