aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/compat.py
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-04-23 18:28:49 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-05-10 14:51:38 +0800
commitdab0daeeb0929b9b560d2b9a5f39c1e2e6dfa449 (patch)
treeed4c6036aa4e509a9d46e9c184c819702fb4f5c5 /youtube_dl/compat.py
parent4350b74545ea3d3ce072444655613bc6974d5516 (diff)
[utils,compat] Move struct_pack and struct_unpack to compat.py
Diffstat (limited to 'youtube_dl/compat.py')
-rw-r--r--youtube_dl/compat.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py
index 12b53cdc8..f697bee7e 100644
--- a/youtube_dl/compat.py
+++ b/youtube_dl/compat.py
@@ -11,6 +11,7 @@ import re
import shlex
import shutil
import socket
+import struct
import subprocess
import sys
import itertools
@@ -592,6 +593,26 @@ if sys.version_info >= (3, 0):
else:
from tokenize import generate_tokens as compat_tokenize_tokenize
+
+try:
+ struct.pack('!I', 0)
+except TypeError:
+ # In Python 2.6 and 2.7.x < 2.7.7, struct requires a bytes argument
+ # See https://bugs.python.org/issue19099
+ def struct_pack(spec, *args):
+ if isinstance(spec, compat_str):
+ spec = spec.encode('ascii')
+ return struct.pack(spec, *args)
+
+ def struct_unpack(spec, *args):
+ if isinstance(spec, compat_str):
+ spec = spec.encode('ascii')
+ return struct.unpack(spec, *args)
+else:
+ struct_pack = struct.pack
+ struct_unpack = struct.unpack
+
+
__all__ = [
'compat_HTMLParser',
'compat_HTTPError',
@@ -634,6 +655,8 @@ __all__ = [
'compat_xml_parse_error',
'compat_xpath',
'shlex_quote',
+ 'struct_pack',
+ 'struct_unpack',
'subprocess_check_output',
'workaround_optparse_bug9161',
]