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
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
wont_change = { ' ' : ' ' ,
'\n' : '\n'
}
fixed_active = False
def fixed_width_replace(char):
if char in wont_change: return unicode(char)
else:
try:
if not 32 < ord(char) < 126: raise Exception("not in range")
return unichr(0xFF00 + ord(char)-32)
except:
return char
cyr_active = False
cyrillic_dict = {
'A' : u'А', 'a' : 'а','Ä' : u'Ӓ', 'ä' : u'ӓ',
'B' : u'В',
'c' : u'с',
'E' : u'Е',
'e' : u'е',
'H' : u'Н',
'I' : u'І', 'i' : u'і',
'j' : u'ј','J' : u'Ј',
'K' : u'К',
'M' : u'М',
'O' : u'О', 'o' : u'о', 'Ö' : u'Ӧ', 'ö' : u'ӧ',
'P' : u'Р', 'p' : u'р',
'S' : u'Ѕ',
'T' : u'г'
}
def cyrillic_replace(char):
return cyrillic_dict.get(char,unicode(char))
def helpme():
print "usage %s [modes]" % sys.argv[0]
print "modes:"
print " c -- cyrillic replace"
print " f -- fixed width"
print " h -- this message"
sys.exit(0)
#parsing happens inside the nested loop
modes = ''.join(sys.argv[1:])
# sane defaults if no mode given
if not modes : modes = "f"
if 'h' in modes: helpme()
for line in sys.stdin:
for char in line:
for mode in modes:
if mode is 'c':
char = cyrillic_replace(char)
elif mode is 'f':
char = fixed_width_replace(char)
else:
print "unknown mode %c" % mode
helpme()
print char,
|