From 6b842439b04d123555c6d8de3468f45108584745 Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: May 30 2023 18:44:56 +0000 Subject: explain _ord() method This method is a historical oddity that we needed to deal with pieces of RPM headers (strings) on Python 2. Since ord() no longer exists on Python 3, it's difficult for new developers to understand what this code is. Add comments so it's easier to read. --- diff --git a/koji/__init__.py b/koji/__init__.py index 0ca0ef6..37fb428 100644 --- a/koji/__init__.py +++ b/koji/__init__.py @@ -958,10 +958,19 @@ def rip_rpm_hdr(src): def _ord(s): - # in python2 it is char/str, while in py3 it is already int/bytes + """Convert a string (single character) to an int (byte). + + Use this method to get bytes from RPM headers in Python 2 and 3. + + :returns: int + """ if isinstance(s, int): + # In Python 3, RPM headers are bytes (sequences of integers), so we + # already have an int here: return s else: + # In Python 2, RPM headers are strings, so we have a one-character + # string here, which we must convert to an int: return ord(s)