提交 ef3a1931 编写于 作者: S Steffy-zxf 提交者: wuzewu

fix-encoding-format (#44)

上级 ead7f993
...@@ -58,7 +58,13 @@ command = HubCommand.instance() ...@@ -58,7 +58,13 @@ command = HubCommand.instance()
def main(): def main():
command.execute(sys.argv[1:]) argv = []
for item in sys.argv:
if six.PY2:
argv.append(item.decode(sys.stdin.encoding).decode("utf8"))
else:
argv.append(item)
command.execute(argv[1:])
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -17,6 +17,8 @@ from __future__ import absolute_import ...@@ -17,6 +17,8 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
import codecs
import sys
import yaml import yaml
...@@ -28,7 +30,7 @@ class CSVFileParser(object): ...@@ -28,7 +30,7 @@ class CSVFileParser(object):
pass pass
def parse(self, csv_file): def parse(self, csv_file):
with open(csv_file, "r") as file: with codecs.open(txt_file, "r", sys.stdin.encoding) as file:
content = file.read() content = file.read()
content = content.split('\n') content = content.split('\n')
self.title = content[0].split(',') self.title = content[0].split(',')
...@@ -55,7 +57,7 @@ class YAMLFileParser(object): ...@@ -55,7 +57,7 @@ class YAMLFileParser(object):
pass pass
def parse(self, yaml_file): def parse(self, yaml_file):
with open(yaml_file, "r") as file: with codecs.open(txt_file, "r", sys.stdin.encoding) as file:
content = file.read() content = file.read()
return yaml.load(content, Loader=yaml.BaseLoader) return yaml.load(content, Loader=yaml.BaseLoader)
...@@ -67,10 +69,14 @@ class TextFileParser(object): ...@@ -67,10 +69,14 @@ class TextFileParser(object):
def _check(self): def _check(self):
pass pass
def parse(self, yaml_file): def parse(self, txt_file):
with open(yaml_file, "r") as file: with codecs.open(txt_file, "r", sys.stdin.encoding) as file:
contents = file.read().split("\n") contents = []
return [content for content in contents if content] for line in file:
line = line.strip()
if line:
contents.append(line)
return contents
csv_parser = CSVFileParser() csv_parser = CSVFileParser()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册