def biDiText(text):
 text = s3_unicode(text)
 if (biDiImported and current.deployment_settings.get_pdf_bidi()):
  isArabic = False
  isBidi = False
  for c in text:
   cat = unicodedata.bidirectional(c)
   if (cat in ('AL', 'AN')):
    isArabic = True
    isBidi = True
    break
   elif (cat in ('R', 'RLE', 'RLO')):
    isBidi = True
  if isArabic:
   text = arabic_reshaper.reshape(text)
  if isBidi:
   text = get_display(text)
 return text

def biDiText ( text ) : text = s3_unicode ( text ) if ( biDiImported and current . deployment_settings . get_pdf_bidi ( ) ) : isArabic = False isBidi = False for c in text : cat = unicodedata . bidirectional ( c ) if ( cat in ( 'AL' , 'AN' ) ) : isArabic = True isBidi = True break elif ( cat in ( 'R' , 'RLE' , 'RLO' ) ) : isBidi = True if isArabic : text = arabic_reshaper . reshape ( text ) if isBidi : text = get_display ( text ) return text
ensure that rtl text is rendered rtl & also that arabic text is rewritten to use the joined format .