()
| 244 | |
| 245 | |
| 246 | def run(): |
| 247 | import sys |
| 248 | from optparse import OptionParser |
| 249 | parser = OptionParser() |
| 250 | parser.add_option('-e', type='string', dest='encoding', |
| 251 | help='encoding') |
| 252 | parser.add_option('-f', type='string', dest='file_in', |
| 253 | help='input file (- for stdin)') |
| 254 | parser.add_option('-t', type='string', dest='file_out', |
| 255 | help='output file') |
| 256 | (options, args) = parser.parse_args() |
| 257 | if not options.encoding: |
| 258 | parser.error('encoding must be set') |
| 259 | if options.file_in: |
| 260 | if options.file_in == '-': |
| 261 | file_in = sys.stdin |
| 262 | else: |
| 263 | file_in = open(options.file_in) |
| 264 | else: |
| 265 | file_in = sys.stdin |
| 266 | if options.file_out: |
| 267 | if options.file_out == '-': |
| 268 | file_out = sys.stdout |
| 269 | else: |
| 270 | file_out = open(options.file_out, 'wb') |
| 271 | else: |
| 272 | file_out = sys.stdout |
| 273 | |
| 274 | c = Converter(options.encoding) |
| 275 | for line in file_in: |
| 276 | # print >> file_out, c.convert(line.rstrip('\n').decode( |
| 277 | file_out.write(c.convert(line.rstrip('\n').decode( |
| 278 | 'utf8')).encode('utf8')) |
| 279 | |
| 280 | |
| 281 | def simple2tradition(line): |
no test coverage detected