Add intlist_to_bytes to utils.py
[youtube-dl] / youtube_dl / utils.py
index 59eeaf4a89084783e1ca2607840b3b7dfc4670f5..ee8df6a5b844054287d1e6a78668e23746058abd 100644 (file)
@@ -708,3 +708,20 @@ class DateRange(object):
         return self.start <= date <= self.end
     def __str__(self):
         return '%s - %s' % ( self.start.isoformat(), self.end.isoformat())
+
+
+def bytes_to_intlist(bs):
+    if not bs:
+        return []
+    if isinstance(bs[0], int):  # Python 3
+        return list(bs)
+    else:
+        return [ord(c) for c in bs]
+
+def intlist_to_bytes(xs):
+    if not xs:
+        return b''
+    if isinstance(chr(0), bytes):  # Python 2
+        return ''.join([chr(x) for x in xs])
+    else:
+        return bytes(xs)