File: XMDict.py

package info (click to toggle)
scim-python 0.1.13~rc1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,436 kB
  • ctags: 2,794
  • sloc: sh: 9,774; python: 9,551; cpp: 3,420; makefile: 349; sed: 16
file content (101 lines) | stat: -rw-r--r-- 2,669 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
# vim: set noet ts=4:
#
# scim-python
#
# Copyright (c) 2008-2008 Yu Yuwei <acevery@gmail.com>
#
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA
#
# $Id: $
#
import sys
reload (sys)
sys.setdefaultencoding('utf-8')

XingMa_Dict = {
	'0':0,
	'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 
	'f':6, 'g':7, 'h':8, 'i':9, 'j':10,
	'k':11, 'l':12, 'm':13, 'n':14, 'o':15,
	'p':16, 'q':17, 'r':18, 's':19, 't':20,
	'u':21, 'v':22, 'w':23, 'x':24, 'y':25,
	'z':26, "'":27, ';':28, '`':29, '~':30, 
	'!':31, '@':32, '#':33, '$':34, '%':35,
	'^':36, '&':37, '*':38, '(':39, ')':40,
	'-':41, '_':42, '=':43, '+':44, '[':45,
	']':46, '{':47, '}':48, '|':49, '/':50,
	':':51, '"':52,  '<':53, '>':54, ',':55,
	'.':56, '?':57, '\\':58, 'A':59, 'B':60,
	'C':61, 'D':62, 'E':63, 'F':64, 'G':65,
	'H':66, 'I':67, 'J':68, 'K':69, 'L':70,
	'M':71, 'N':72, 'O':73, 'P':74, 'Q':75,
	'R':76, 'S':77, 'T':78, 'U':79, 'V':80,
    'W':81, 'X':82, 'Y':83, 'Z':84, '0':85,
    '1':86, '2':87, '3':88, '4':89, '5':90,
    '6':91, '7':92, '8':93, '9':94
	}

XingMa_List = XingMa_Dict.keys()

ID_XingMa_Dict = {}
for key,id in XingMa_Dict.items():
	ID_XingMa_Dict[id] = key

class XingMa_key:
	'''The class store'''
	def __init__(self, xm_key):
		try:
			if xm_key not in XingMa_List:
				error_m = u'%s is not in XingMa_Dict' % xm_key
				raise Exception ( error_m.encode('utf8') )
		except Exception, e:
			print e
			import traceback
			traceback.print_exc ()
		self._key = xm_key
		self._key_id = XingMa_Dict[xm_key]
	
	def get_key_id(self):
		return self._key_id

	def get_key(self):
		return self._key

	def __str__(self):
		return self._key

	def __int__(self):
		return self._key_id

def Parse ( inputstr ):
	
	ids_input = []
	try:
		ids_input = map (XingMa_key,inputstr)
	except:
		pass
	return ids_input[:]

def Deparse (id):
	'''deparse the id code of XingMa, id could be int or int in string form'''
	if id:
		id = int(id)
		if id in ID_XingMa_Dict:
			return ID_XingMa_Dict[id]
	else:
		return ''