MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / main

Function main

python/opencc/cli.py:51–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50
51def main():
52 parser = _build_parser()
53 args = parser.parse_args()
54
55 if args.input and args.output:
56 try:
57 if os.path.samefile(args.input, args.output):
58 print('opencc: error: input and output refer to the same file', file=sys.stderr)
59 sys.exit(1)
60 except FileNotFoundError:
61 pass
62
63 converter = opencc.OpenCC(
64 args.config,
65 include_tofu_risk_dictionaries=args.include_tofu_risk_dictionaries,
66 resource_zip=args.resource_zip,
67 )
68
69 if args.input:
70 with open(args.input, 'rb') as f:
71 text = f.read().decode('utf-8')
72 else:
73 text = sys.stdin.buffer.read().decode('utf-8')
74
75 result = converter.convert(text)
76
77 if args.output:
78 with open(args.output, 'wb') as f:
79 f.write(result.encode('utf-8'))
80 else:
81 sys.stdout.buffer.write(result.encode('utf-8'))
82
83
84if __name__ == '__main__':

Callers 1

cli.pyFile · 0.70

Calls 6

convertMethod · 0.95
_build_parserFunction · 0.85
printFunction · 0.85
exitMethod · 0.80
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected