aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'MgaRepo/util.py')
-rw-r--r--MgaRepo/util.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/MgaRepo/util.py b/MgaRepo/util.py
index 519c199..8435ec2 100644
--- a/MgaRepo/util.py
+++ b/MgaRepo/util.py
@@ -23,11 +23,11 @@ def commands_getstatusoutput(cmd):
text = b''
pipe.stdin.close()
while True:
- text += os.read(of,8192)
+ text += os.read(of, 8192)
status = pipe.poll()
if status is not None or text == '':
break
- if text[-1:] == '\n': text = text[:-1]
+ if text[-1:] == b'\n': text = text[:-1]
return status, text.decode('utf8')
def execcmd(*cmd, **kwargs):
@@ -54,10 +54,14 @@ def execcmd(*cmd, **kwargs):
r,w,x = select.select((of,ef), (), ())
odata = None
if of in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
odata = (os.read(of, 8192)).decode('utf8')
sys.stdout.write(odata)
edata = None
if ef in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
edata = (os.read(ef, 8192)).decode('utf8')
err.write(edata)
sys.stderr.write(edata)
@@ -92,10 +96,14 @@ def get_output_exec(cmdstr):
r,w,x = select.select((of,ef), (), ())
odata = None
if of in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
odata = (os.read(of, 8192)).decode('utf8')
output.write(odata)
edata = None
if ef in r:
+ # TODO: wait until all text is received before decoding to
+ # reduce the chance of decoding a partial UTF-8 codepoint
edata = (os.read(ef, 8192)).decode('utf8')
err.write(edata)
status = p.poll()
@@ -135,12 +143,12 @@ def mapurl(url):
try:
expr_, replace = urlmap.split()[:2]
except ValueError:
- sys.stderr.buffer.write("invalid url-map: %s" % urlmap)
+ sys.stderr.buffer.write(("invalid url-map: %s" % urlmap).encode())
else:
try:
newurl = re.sub(expr_, replace, url)
except re.error as errmsg:
- sys.stderr.buffer.write("error in URL mapping regexp: %s" % errmsg)
+ sys.stderr.buffer.write(("error in URL mapping regexp: %s" % errmsg).encode())
return newurl