Skip to content

Use utf-8 instead of GBK to fix runtime error #52

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

Open
wants to merge 1 commit into
base: devel
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
6 changes: 3 additions & 3 deletions python_hosts/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def write(self, path=None, mode='w'):
else:
output_file_path = self.path
try:
with open(output_file_path, mode) as hosts_file:
with open(output_file_path, mode, encoding='utf-8') as hosts_file:
for written_count, line in enumerate(self.entries):
if line.entry_type == 'comment':
hosts_file.write(line.comment + "\n")
Expand Down Expand Up @@ -362,7 +362,7 @@ def import_file(self, import_file_path=None):
invalid_count = 0
if is_readable(import_file_path):
import_entries = []
with open(import_file_path, 'r') as infile:
with open(import_file_path, 'r', encoding='utf-8') as infile:
for line in infile:
stripped_entry = line.strip()
if (not stripped_entry) or (stripped_entry.startswith('#')):
Expand Down Expand Up @@ -489,7 +489,7 @@ def populate_entries(self):
:return: None
"""
try:
with open(self.path, 'r') as hosts_file:
with open(self.path, 'r', encoding='utf-8') as hosts_file:
hosts_entries = [line for line in hosts_file]
for hosts_entry in hosts_entries:
entry_type = HostsEntry.get_entry_type(hosts_entry)
Expand Down