Skip to content

Commit 636f23c

Browse files
committed
Fix open.write incompatibility between Py2 and Py3
1 parent 3119831 commit 636f23c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

readthedocs/projects/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import redis
1212
import six
13-
from builtins import object
13+
from builtins import object, open
1414
from django.conf import settings
1515
from django.core.cache import cache
1616
from httplib2 import Http
@@ -121,10 +121,10 @@ def safe_write(filename, contents):
121121
dirname = os.path.dirname(filename)
122122
if not os.path.exists(dirname):
123123
os.makedirs(dirname)
124-
with open(filename, 'w') as fh:
125-
fh.write(contents.encode('utf-8', 'ignore'))
126-
fh.close()
127124

125+
with open(filename, 'w', encoding='utf-8', errors='ignore') as fh:
126+
fh.write(contents)
127+
fh.close()
128128

129129
def purge_version(version, mainsite=False, subdomain=False, cname=False):
130130
varnish_servers = getattr(settings, 'VARNISH_SERVERS', None)

0 commit comments

Comments
 (0)