PageRenderTime 30ms CodeModel.GetById 2ms app.highlight 23ms RepoModel.GetById 2ms app.codeStats 0ms

/python/engine/XingMa/XMDict.py

http://scim-python.googlecode.com/
Python | 101 lines | 75 code | 1 blank | 25 comment | 2 complexity | 1e708d5d2c04370b902aefb558e31e89 MD5 | raw file
  1# -*- coding: utf-8 -*-
  2# vim: set noet ts=4:
  3#
  4# scim-python
  5#
  6# Copyright (c) 2008-2008 Yu Yuwei <acevery@gmail.com>
  7#
  8#
  9# This library is free software; you can redistribute it and/or
 10# modify it under the terms of the GNU Lesser General Public
 11# License as published by the Free Software Foundation; either
 12# version 2 of the License, or (at your option) any later version.
 13#
 14# This library is distributed in the hope that it will be useful,
 15# but WITHOUT ANY WARRANTY; without even the implied warranty of
 16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17# GNU Lesser General Public License for more details.
 18#
 19# You should have received a copy of the GNU Lesser General Public
 20# License along with this program; if not, write to the
 21# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 22# Boston, MA  02111-1307  USA
 23#
 24# $Id: $
 25#
 26import sys
 27reload (sys)
 28sys.setdefaultencoding('utf-8')
 29
 30XingMa_Dict = {
 31	'0':0,
 32	'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 
 33	'f':6, 'g':7, 'h':8, 'i':9, 'j':10,
 34	'k':11, 'l':12, 'm':13, 'n':14, 'o':15,
 35	'p':16, 'q':17, 'r':18, 's':19, 't':20,
 36	'u':21, 'v':22, 'w':23, 'x':24, 'y':25,
 37	'z':26, "'":27, ';':28, '`':29, '~':30, 
 38	'!':31, '@':32, '#':33, '$':34, '%':35,
 39	'^':36, '&':37, '*':38, '(':39, ')':40,
 40	'-':41, '_':42, '=':43, '+':44, '[':45,
 41	']':46, '{':47, '}':48, '|':49, '/':50,
 42	':':51, '"':52,  '<':53, '>':54, ',':55,
 43	'.':56, '?':57, '\\':58, 'A':59, 'B':60,
 44	'C':61, 'D':62, 'E':63, 'F':64, 'G':65,
 45	'H':66, 'I':67, 'J':68, 'K':69, 'L':70,
 46	'M':71, 'N':72, 'O':73, 'P':74, 'Q':75,
 47	'R':76, 'S':77, 'T':78, 'U':79, 'V':80,
 48    'W':81, 'X':82, 'Y':83, 'Z':84, '0':85,
 49    '1':86, '2':87, '3':88, '4':89, '5':90,
 50    '6':91, '7':92, '8':93, '9':94
 51	}
 52
 53XingMa_List = XingMa_Dict.keys()
 54
 55ID_XingMa_Dict = {}
 56for key,id in XingMa_Dict.items():
 57	ID_XingMa_Dict[id] = key
 58
 59class XingMa_key:
 60	'''The class store'''
 61	def __init__(self, xm_key):
 62		try:
 63			if xm_key not in XingMa_List:
 64				error_m = u'%s is not in XingMa_Dict' % xm_key
 65				raise Exception ( error_m.encode('utf8') )
 66		except Exception, e:
 67			print e
 68			import traceback
 69			traceback.print_exc ()
 70		self._key = xm_key
 71		self._key_id = XingMa_Dict[xm_key]
 72	
 73	def get_key_id(self):
 74		return self._key_id
 75
 76	def get_key(self):
 77		return self._key
 78
 79	def __str__(self):
 80		return self._key
 81
 82	def __int__(self):
 83		return self._key_id
 84
 85def Parse ( inputstr ):
 86	
 87	ids_input = []
 88	try:
 89		ids_input = map (XingMa_key,inputstr)
 90	except:
 91		pass
 92	return ids_input[:]
 93
 94def Deparse (id):
 95	'''deparse the id code of XingMa, id could be int or int in string form'''
 96	if id:
 97		id = int(id)
 98		if id in ID_XingMa_Dict:
 99			return ID_XingMa_Dict[id]
100	else:
101		return ''