Coverage Report - orca.chnames

ModuleCoverage %
orca.chnames
94%
1
# Orca
2
#
3
# Copyright 2004-2006 Sun Microsystems Inc.
4
#
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU Library General Public
7
# License as published by the Free Software Foundation; either
8
# version 2 of the License, or (at your option) any later version.
9
#
10
# This library is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# Library General Public License for more details.
14
#
15
# You should have received a copy of the GNU Library General Public
16
# License along with this library; if not, write to the
17
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
# Boston, MA 02111-1307, USA.
19
20
"""Provides getCharacterName that maps punctuation marks and other
21 1
individual characters into localized words."""
22
23 1
__id__        = "$Id: chnames.py 1534 2006-10-06 17:38:23Z wwalker $"
24 1
__version__   = "$Revision: 1534 $"
25 1
__date__      = "$Date: 2006-10-06 10:38:23 -0700 (Fri, 06 Oct 2006) $"
26 1
__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc."
27 1
__license__   = "LGPL"
28
29 1
from orca_i18n import _ # for gettext support
30
31
# __chnames is a dictionary where the keys represent a UTF-8
32
# character (possibly multibyte) and the values represent the common
33
# term used for the character.
34
#
35 1
__chnames = {}
36 1
__chnames[" "] = _("space")
37 1
__chnames["\n"] = _("newline")
38 1
__chnames["\t"] = _("tab")
39
40 1
__chnames["!"] = _("exclaim")
41 1
__chnames["'"] = _("apostrophe")
42 1
__chnames[","] = _("comma")
43 1
__chnames["."] = _("dot")
44 1
__chnames["?"] = _("question")
45
46 1
__chnames["\""] = _("quote")
47 1
__chnames["("] = _("left paren")
48 1
__chnames[")"] = _("right paren")
49 1
__chnames["-"] = _("dash")
50 1
__chnames["_"] = _("underscore")
51 1
__chnames[":"] = _("colon")
52 1
__chnames[";"] = _("semicolon")
53 1
__chnames["<"] = _("less than")
54 1
__chnames[">"] = _("greater than")
55 1
__chnames["["] = _("left bracket")
56 1
__chnames["]"] = _("right bracket")
57 1
__chnames["\\"] = _("backslash")
58 1
__chnames["|"] = _("vertical line")
59 1
__chnames["`"] = _("grave accent")
60 1
__chnames["~"] = _("tilde")
61 1
__chnames["{"] = _("left brace")
62 1
__chnames["}"] = _("right brace")
63
64 1
__chnames["#"] = _("pound")
65 1
__chnames["$"] = _("dollar")
66 1
__chnames["%"] = _("percent")
67 1
__chnames["&"] = _("and")
68 1
__chnames["*"] = _("star")
69 1
__chnames["+"] = _("plus")
70 1
__chnames["/"] = _("slash")
71 1
__chnames["="] = _("equals")
72 1
__chnames["@"] = _("at")
73 1
__chnames["^"] = _("caret")
74
75 1
__chnames["\xc2\xb1"] = _("plus minus")
76 1
__chnames["\xc3\xb7"] = _("divide")
77 1
__chnames["\xc3\x97"] = _("multiply")
78
79 1
def getCharacterName(character):
80
    """Given a character, return its name as people might refer to it
81
    in ordinary conversation.
82
83
    Arguments:
84
    - character: the character to get the name for
85
86
    Returns a string representing the name for the character
87
    """
88
89 30
    if isinstance(character, unicode):
90 0
        character = character.encode("UTF-8")
91
92 30
    try:
93 30
        return __chnames[character]
94 0
    except:
95 0
        return character