#1657 Use bytes for debug string
Merged 2 years ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue1656  into  master

file modified
+6 -2
@@ -2535,8 +2535,12 @@ 

              self.logger.debug("url: %s" % handler)

              for _key in callopts:

                  _val = callopts[_key]

-                 if _key == 'data' and len(_val) > 1024:

-                     _val = _val[:1024] + '...'

+                 if _key == 'data':

+                     if six.PY3 and isinstance(_val, bytes):

+                         # convert to hex-string

+                         _val = '0x' + _val.hex()

+                     if len(_val) > 1024:

+                         _val = _val[:1024] + '...'

                  self.logger.debug("%s: %r" % (_key, _val))

          with warnings.catch_warnings():

              warnings.simplefilter("ignore")

At this point in the code, data might be either bytes (in the upload case) or a string (in most other cases).

With this fix, things break the other way.

$ PYTHONPATH=~/Devel/koji/koji koji -p lkoji --debug --noauth --debug-xmlrpc call echo "$(seq 1000)"
2019-09-25 09:17:27,422 [DEBUG] koji: Opening new requests session
2019-09-25 09:17:27,423 [DEBUG] koji: url: https://localhost/kojihub
2019-09-25 09:17:27,423 [DEBUG] koji: headers: {'User-Agent': 'koji/1', 'Content-Type': 'text/xml', 'Content-Length': '107'}
2019-09-25 09:17:27,423 [DEBUG] koji: data: "<?xml version='1.0'?>\n<methodCall>\n<methodName>getAPIVersion</methodName>\n<params>\n</params>\n</methodCall>\n"
2019-09-25 09:17:27,423 [DEBUG] koji: stream: True
2019-09-25 09:17:27,423 [DEBUG] koji: verify: '/home/mike/.koji/localhost.crt'
2019-09-25 09:17:27,423 [DEBUG] koji: timeout: 43200
2019-09-25 09:17:27,430 [DEBUG] koji: body: b"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><int>1</int></value>\n</param>\n</params>\n</methodResponse>\n"
successfully connected to hub
2019-09-25 09:17:27,431 [DEBUG] koji: url: https://localhost/kojihub
2019-09-25 09:17:27,431 [DEBUG] koji: headers: {'User-Agent': 'koji/1', 'Content-Type': 'text/xml', 'Content-Length': '4040'}
2019-09-25 09:17:27,431 [DEBUG] koji: Opening new requests session
Traceback (most recent call last):
  File "/usr/bin/koji", line 336, in <module>
    rv = locals()[command].__call__(options, session, args)
  File "/usr/lib/python3.7/site-packages/koji_cli/commands.py", line 876, in handle_call
    response = getattr(session, name).__call__(*non_kw, **kw)
  File "/home/mike/Devel/koji/koji/koji/__init__.py", line 2094, in __call__
    return self.__func(self.__name, args, opts)
  File "/home/mike/Devel/koji/koji/koji/__init__.py", line 2582, in _callMethod
    return self._sendCall(handler, headers, request)
  File "/home/mike/Devel/koji/koji/koji/__init__.py", line 2504, in _sendCall
    return self._sendOneCall(handler, headers, request)
  File "/home/mike/Devel/koji/koji/koji/__init__.py", line 2539, in _sendOneCall
    _val = _val[:1024] + six.b('...')
TypeError: can only concatenate str (not "bytes") to str

Makes sense - I was too hasty.

Probably the thing to do is check for the bytes case and convert that to a string first (perhaps as hex)

rebased onto 80484f0

2 years ago

Commit e54f9fd fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago