aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo/util.py
diff options
context:
space:
mode:
authorDan Fandrich <danf@mageia.org>2025-02-03 19:30:47 -0800
committerDan Fandrich <danf@mageia.org>2025-02-03 22:25:12 -0800
commitc488d9cdfb0aea78d4a0bde4778fe78eda1c46ea (patch)
tree034840bfc891f6873f4e2a0bcc86650291433f62 /MgaRepo/util.py
parent6d2c594260832373595effa4f63552a8068ae92c (diff)
downloadmgarepo-c488d9cdfb0aea78d4a0bde4778fe78eda1c46ea.tar
mgarepo-c488d9cdfb0aea78d4a0bde4778fe78eda1c46ea.tar.gz
mgarepo-c488d9cdfb0aea78d4a0bde4778fe78eda1c46ea.tar.bz2
mgarepo-c488d9cdfb0aea78d4a0bde4778fe78eda1c46ea.tar.xz
mgarepo-c488d9cdfb0aea78d4a0bde4778fe78eda1c46ea.zip
Fix many errors found by pytypeHEADmaster
Some of these would always cause run-time exceptions, which makes me believe that because these haven't been reported before there's a lot of dead code in here. There are a few more pytype errors that don't have obvious fixes.
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