Skip to content

Commit

Permalink
Remove cgi dependency from Client
Browse files Browse the repository at this point in the history
  • Loading branch information
mdujava committed Dec 24, 2023
1 parent 7aefecd commit 340dc5b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Client/src/bkr/client/commands/cmd_update_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@

from __future__ import print_function

import cgi
import sys
from xml.dom.minidom import parseString

from requests.exceptions import HTTPError

from bkr.client import BeakerCommand
from bkr.client.task_watcher import watch_tasks
from bkr.common.helpers import parse_content_type


class Update_Inventory(BeakerCommand):
Expand Down Expand Up @@ -152,7 +152,7 @@ def run(self, *args, **kwargs):
res.raise_for_status()
except HTTPError as e:
sys.stderr.write('HTTP error: %s, %s\n' % (fqdn, e))
content_type, _ = cgi.parse_header(e.response.headers.get(
content_type = parse_content_type(e.response.headers.get(
'Content-Type', ''))
if content_type == 'text/plain':
sys.stderr.write('\t' +
Expand Down
4 changes: 2 additions & 2 deletions Client/src/bkr/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

import cgi
import errno
import logging
import signal
Expand All @@ -22,6 +21,7 @@
from bkr.client.command import ClientCommandContainer
from bkr.client.command import CommandOptionParser
from bkr.common import __version__
from bkr.common.helpers import parse_content_type
from bkr.log import log_to_stream

__all__ = (
Expand Down Expand Up @@ -129,7 +129,7 @@ def main():
except maybe_http_error as e:
warn_on_version_mismatch(e.response)
sys.stderr.write('HTTP error: %s\n' % e)
content_type, _ = cgi.parse_header(e.response.headers.get('Content-Type', ''))
content_type = parse_content_type(e.response.headers.get('Content-Type', ''))
if content_type == 'text/plain':
sys.stderr.write(e.response.content.decode('utf-8').rstrip('\n') + '\n')
return 1
Expand Down
6 changes: 6 additions & 0 deletions Common/bkr/common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,9 @@ def total_seconds(td):
"""
return (float(td.microseconds) + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6

def parse_content_type(value):
"""
Return just content type, without options
"""
groups = value.split(';', 1)
return groups[0]

0 comments on commit 340dc5b

Please sign in to comment.