Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: UnicodeDecodeError: 'gbk' codec can't decode byte #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ def print_file(self, path):
line = "{}\nimport({}\n{}\n)\n{}".format(
self.before_import, self.import_other_library, hertzLibrary, self.body
)
wopen = open(path, "w")
wopen = open(path, "w", encoding='utf-8')
wopen.write(line)
wopen.close()

def find_route_handler(self):
filePath = self.items_dir()
for path in filePath:
fd = open(path, "r")
fd = open(path, "r", encoding='utf-8')
line = fd.readline()
while line:
if line.strip().startswith("//"):
Expand Down Expand Up @@ -279,7 +279,7 @@ def find_func(self, fd, line, lines):

def add_import_context(self, path):
lines = ""
fd = open(path, "r")
fd = open(path, "r", encoding='utf-8')
line = fd.readline()
while line:
if re.search(r"import \(", line):
Expand All @@ -297,7 +297,7 @@ def add_import_context(self, path):
else:
lines += line
line = fd.readline()
wopen = open(path, "w")
wopen = open(path, "w", encoding='utf-8')
wopen.write(lines)
wopen.close()

Expand All @@ -307,7 +307,7 @@ def handle_context(self):
filePath = self.items_dir()
for path in filePath:
lines = ""
fd = open(path, "r")
fd = open(path, "r", encoding='utf-8')
line = fd.readline()
need_add_import = False
while line:
Expand All @@ -322,7 +322,7 @@ def handle_context(self):
if not has_found:
lines = lines + line
line = fd.readline()
wopen = open(path, "w")
wopen = open(path, "w", encoding='utf-8')
wopen.write(lines)
wopen.close()
if need_add_import:
Expand Down Expand Up @@ -350,7 +350,7 @@ def transfer(self):
self.format_code()
filePath = self.items_dir()
for path in filePath:
fd = open(path, "r")
fd = open(path, "r", encoding='utf-8')
has_other_framework = self.handle_import(fd)
if not has_other_framework:
fd.close()
Expand Down
Loading