nodes: 0, module; 1, function_definition; 2, function_name:sortable_title; 3, parameters; 4, block; 5, identifier:portal; 6, identifier:title; 7, expression_statement; 8, if_statement; 9, expression_statement; 10, expression_statement; 11, comment:# Replace numbers with zero filled numbers; 12, expression_statement; 13, comment:# Truncate to prevent bloat; 14, for_statement; 15, return_statement; 16, comment:"""Convert title to sortable title
      """; 17, not_operator; 18, block; 19, assignment; 20, assignment; 21, assignment; 22, identifier:charset; 23, list; 24, block; 25, identifier:sortabletitle; 26, identifier:title; 27, return_statement; 28, identifier:def_charset; 29, call; 30, identifier:sortabletitle; 31, call; 32, identifier:sortabletitle; 33, call; 34, identifier:def_charset; 35, string; 36, string; 37, try_statement; 38, string; 39, attribute; 40, argument_list; 41, identifier:str; 42, argument_list; 43, attribute; 44, argument_list; 45, string_content:latin-1; 46, string_content:utf-8; 47, block; 48, except_clause; 49, except_clause; 50, attribute; 51, identifier:getSiteEncoding; 52, call; 53, identifier:num_sort_regex; 54, identifier:sub; 55, identifier:zero_fill; 56, identifier:sortabletitle; 57, expression_statement; 58, expression_statement; 59, break_statement; 60, identifier:UnicodeError; 61, block; 62, identifier:TypeError; 63, comment:# If we get a TypeError if we already have a unicode string; 64, block; 65, identifier:portal; 66, identifier:plone_utils; 67, attribute; 68, argument_list; 69, assignment; 70, assignment; 71, pass_statement; 72, expression_statement; 73, break_statement; 74, call; 75, identifier:strip; 76, identifier:sortabletitle; 77, subscript; 78, identifier:sortabletitle; 79, call; 80, assignment; 81, attribute; 82, argument_list; 83, call; 84, slice; 85, attribute; 86, argument_list; 87, identifier:sortabletitle; 88, subscript; 89, identifier:title; 90, identifier:lower; 91, identifier:safe_unicode; 92, argument_list; 93, integer:30; 94, identifier:sortabletitle; 95, identifier:encode; 96, boolean_operator; 97, identifier:sortabletitle; 98, slice; 99, identifier:sortabletitle; 100, identifier:charset; 101, identifier:def_charset; 102, string; 103, integer:30; 104, string_content:utf-8
code: def sortable_title(portal, title):
      """Convert title to sortable title
      """
      if not title:
          return ''
  
      def_charset = portal.plone_utils.getSiteEncoding()
      sortabletitle = str(title.lower().strip())
      # Replace numbers with zero filled numbers
      sortabletitle = num_sort_regex.sub(zero_fill, sortabletitle)
      # Truncate to prevent bloat
      for charset in [def_charset, 'latin-1', 'utf-8']:
          try:
              sortabletitle = safe_unicode(sortabletitle, charset)[:30]
              sortabletitle = sortabletitle.encode(def_charset or 'utf-8')
              break
          except UnicodeError:
              pass
          except TypeError:
              # If we get a TypeError if we already have a unicode string
              sortabletitle = sortabletitle[:30]
              break
      return sortabletitle