Replace the use of the function string.replace with the method str.replace (#68793)

* Replace the use of the function string.replace() with the method str.replace()
because that's what works for both Python 2 and 3.

* Cleanup the unused string import.

Added a changelog fragment.

* The documentation for os.write() seems a bit iffy, but in Python 3 we
definitely cannot pass it a string and we need to encode it into
bytes.

The Python documentation at
https://docs.python.org/3/howto/pyporting.html#text-versus-binary-data
says that this code will work in Python 2 as well.

Co-authored-by: Lloyd Parkes <lloyd@must-have-coffee.gen.nz>
pull/73119/head
Lloyd Parkes 4 years ago committed by GitHub
parent a469a4455a
commit e0c75a6756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- service - Fix for the BSD rcconf code using a Python 2 specific string replace function

@ -135,7 +135,6 @@ import platform
import re
import select
import shlex
import string
import subprocess
import tempfile
import time
@ -419,7 +418,7 @@ class Service(object):
# Write out the contents of the list into our temporary file.
for rcline in new_rc_conf:
os.write(TMP_RCCONF, rcline)
os.write(TMP_RCCONF, rcline.encode())
# Close temporary file.
os.close(TMP_RCCONF)
@ -1116,7 +1115,7 @@ class DragonFlyBsdService(FreeBsdService):
if os.path.isfile(rcfile):
self.rcconf_file = rcfile
self.rcconf_key = "%s" % string.replace(self.name, "-", "_")
self.rcconf_key = "%s" % self.name.replace("-", "_")
return self.service_enable_rcconf()
@ -1274,7 +1273,7 @@ class NetBsdService(Service):
"""
This is the NetBSD Service manipulation class - it uses the /etc/rc.conf
file for controlling services started at boot, check status and perform
direct service manipulation. Init scripts in /etc/rcd are used for
direct service manipulation. Init scripts in /etc/rc.d are used for
controlling services (start/stop) as well as for controlling the current
state.
"""
@ -1304,7 +1303,7 @@ class NetBsdService(Service):
if os.path.isfile(rcfile):
self.rcconf_file = rcfile
self.rcconf_key = "%s" % string.replace(self.name, "-", "_")
self.rcconf_key = "%s" % self.name.replace("-", "_")
return self.service_enable_rcconf()

Loading…
Cancel
Save