Next / Previous / Contents / TCC Help System / NM Tech homepage

22. letterInfo(): Information about a subpage

homelist2
# - - -   l e t t e r I n f o

def letterInfo(dirPath, letter):
    '''Find the URL, path, and title of the subpage for one letter.

      [ (dirPath is a path relative to TCC_URL) and
        (letter is a single unicode character) ->
          return (URL of letter's page, absolute path to letter's
          page, Unicode title of letter's page) ]
    '''

Because the letter may be a non-ASCII Unicode character, we can't use it directly in the name of the letter page. Instead, for code points past a lowercase “z”, we'll use a string of the form “uNNNN” where NNNN is the hexadecimal value of the code point.

homelist2
    #-- 1 --
    # [ if letter is ASCII ->
    #     suffix  :=  letter
    #   else ->
    #     suffix  :=  letter's code point formatted as "uNNNN" ]
    n = ord(letter)
    if n <= ord('z'): suffix = str(letter)
    else:                suffix = "u%04x" % n

    #-- 2 --
    # [ pageName  :=  file name of letter's page ]
    pageName = ''.join((SUBPAGE_NAME, suffix, HTML_SUFFIX))

See Section 19, “relToURL(): URL of a relative path” and Section 20, “relToAbs(): Absolute path from a relative path”. Because letter may be a non-ASCII Unicode character, the returned title must be Unicode.

homelist2
    #-- 3 --
    # [ url  :=  URL of pageName relative to dirPath
    #   path  :=  absolute path of pageName relative to dirPath
    #   title  :=  BASE_TITLE + ": " + letter ]
    url = relToURL(dirPath, pageName)
    path = relToAbs(dirPath, pageName)
    title = (u"%s: %s" %
             (BASE_TITLE, letter))

    #-- 4 --
    return (url, path, title)