windows系统用户都能用浏览器吧,所有主流浏览器都支持GB18030,而且Windows 10对GB18030的字库,编码,显示,都没发现任何问题。windows 10 NoneUnicode只有本地简体中文选项,内部强制GB18030了,并没有GBK这个上个世纪的选项,Windows10中文家庭版默认就是GB18030,专业版可以选其他国家。
我的终端用UTF-8,ssh上水木显示GBK没发现有问题,即使将来升级到GB18030,改改Python脚本就行了。
alias | grep sm
sm='python2 /usr/local/bin/seu_bbs.py -u poocp'
cat /usr/local/bin/seu_bbs.py
#!/usr/bin/env python
try:
import os,sys,re,locale
except ImportError, e:
raise ImportError (str(e) + """
A critical module was not found. Probably your python was not successfully installed""")
has_argparse = True
try:
# process command line options
import argparse
except:
from optparse import OptionParser
has_argparse = False
sys.path.append(os.path.realpath('.'))
try:
# hack from pexpect
import pexpect_ng
except ImportError, e:
raise ImportError('''
pexpect_ng was not found in current path
''')
# parse command line options
if has_argparse:
parser = argparse.ArgumentParser(description="convert charset of BBS to locale",\
prog="seu_bbs.py")
parser.add_argument('-a', action="store_true",\
dest="AUTOSCALE",\
default=False,\
help="whether or not %(prog)s take whole window.[default disable]")
parser.add_argument('-e', '--encoding', action="store",\
dest="CHARSET",\
default='GB18030',\
help="Set up %(prog)s to use CHARSET encoding.[default GB18030]")
parser.add_argument('-u', '--username', action="store",\
dest="USERNAME",\
default='guest',\
help="Set up %(prog)s to use USERNAME login bbs.[default guest]")
parser.add_argument('-t', '--timeout', type=int,\
dest="TIMEOUT",\
default=-1,\
help="Do someting when idle(unit is seconds, negtive value will be ignored).[default -1]")
parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.3')
options = parser.parse_args()
else:
parser = OptionParser(version="%prog 0.3",\
usage="python %prog [options]")
parser.add_option("-a", action="store_true",\
dest="AUTOSCALE",\
default=False,\
help="whether or not %(prog)s take whole window.[default disable]")
parser.add_option("-e", "--encoding", action="store",\
type="string", dest="CHARSET",\
default="GB18030",\
help="Set up %(prog)s to use CHARSET encoding.[default GB18030]")
parser.add_option("-u", "--username", action="store",\
type="string", dest="USERNAME",\
default="guest",\
help="Set up %(prog)s to use USERNAME login bbs.[default guest]")
parser.add_option("-t", "--timeout", action="store",\
type="int", dest="TIMEOUT",\
default=-1,\
help="Do someting when idle(unit is seconds, negtive value will be ignored).[default -1]")
(options, args) = parser.parse_args()
# locale
loc = locale.getdefaultlocale()
# utilities for charset convert
debug = 0
NEW_LINE = chr(10)
GBK_SYMBOL_RANGE = [[0x2010, 0x2606],
[0x02b0, 0x02ff],
0xb7,
[0xa1, 0xbf]]
def build_re(l):
L = []
for i in l:
if isinstance(i, list):
f, t = i
try:
f = unichr(f)
t = unichr(t)
L.append('%s-%s'%(f, t))
except:
pass
else:
try:
L.append(unichr(i))
except:
pass
RE = '([%s])'%''.join(L)
return re.compile(RE, re.UNICODE)
RE = build_re(GBK_SYMBOL_RANGE)
# log
if debug == 1:
f_log = open('log.txt', 'a')
def output_filter(data):
'''
convert string encoding from specific charset to locale
'''
global loc, options
if type(data) != type('str'):
raise TypeError("convert_filter can only process string type data")
if debug == 1:
data_list = data.split(NEW_LINE)
tmp_list= []
for s in data_list:
try:
tmp = re.sub(RE, r'\1 ', unicode(s, options.CHARSET))
tmp_list.append(tmp.encode(loc[1]))
except UnicodeDecodeError:
tmp_list.append(s)
f_log.write(s)
return NEW_LINE.join(tmp_list)
else:
data = re.sub(RE, r'\1 ', unicode(data, options.CHARSET, 'ignore'))
data = data.encode(loc[1])
return data
def input_filter(data):
'''
convert string encoding from locale to specific charset
'''
global loc, options
if type(data) != type('str'):
raise TypeError("convert_filter can only process string type data")
data_list = data.split(NEW_LINE)
tmp_list= []
for s in data_list:
try:
tmp_list.append(s.decode(loc[1]).encode(options.CHARSET))
except UnicodeDecodeError:
tmp_list.append(ss)
return NEW_LINE.join(tmp_list)
def send_zero_byte(p):
'''
For bbs.seu.edu.cn, it is enough.
'''
p.send(chr(0))
def main():
'''
'''
if options.AUTOSCALE == True:
Rows, Columns = map(int, os.popen('stty size', 'r').read().split())
else:
Rows = 24
Columns = 80
p = pexpect_ng.spawn('ssh %s@newsmth.net'%options.USERNAME, rows=Rows, columns=Columns)
p.interact(input_filter=input_filter, output_filter=output_filter, timeout = options.TIMEOUT, timeout_handle = {send_zero_byte:p})
if debug == 1:
f_log.close()
if __name__ == "__main__":
main()
【 在 lvsoft 的大作中提到: 】
: 现状是大量用户的windows系统用的是gbk编码啊,就算升级了也意义不大。
: 我还想让水母换成utf-8呢,省的我ssh都是乱码还要折腾转换。
: 世界文字和emoji,并不是征服世界啥的,不用扯太远,如果反对的话说清楚意见就行
: ...................
--
修改:poocp FROM 222.212.168.*
FROM 222.212.168.*