aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/compat.py23
-rw-r--r--youtube_dl/downloader/f4m.py4
-rw-r--r--youtube_dl/extractor/rtve.py4
-rw-r--r--youtube_dl/swfinterp.py6
-rw-r--r--youtube_dl/utils.py20
5 files changed, 33 insertions, 24 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',
]
diff --git a/youtube_dl/downloader/f4m.py b/youtube_dl/downloader/f4m.py
index 664d87543..b282fe3d6 100644
--- a/youtube_dl/downloader/f4m.py
+++ b/youtube_dl/downloader/f4m.py
@@ -12,13 +12,13 @@ from ..compat import (
compat_urlparse,
compat_urllib_error,
compat_urllib_parse_urlparse,
+ struct_pack,
+ struct_unpack,
)
from ..utils import (
encodeFilename,
fix_xml_ampersands,
sanitize_open,
- struct_pack,
- struct_unpack,
xpath_text,
)
diff --git a/youtube_dl/extractor/rtve.py b/youtube_dl/extractor/rtve.py
index 79af47715..f59040877 100644
--- a/youtube_dl/extractor/rtve.py
+++ b/youtube_dl/extractor/rtve.py
@@ -6,6 +6,9 @@ import re
import time
from .common import InfoExtractor
+from ..compat import (
+ struct_unpack,
+)
from ..utils import (
ExtractorError,
float_or_none,
@@ -13,7 +16,6 @@ from ..utils import (
remove_start,
sanitized_Request,
std_headers,
- struct_unpack,
)
diff --git a/youtube_dl/swfinterp.py b/youtube_dl/swfinterp.py
index 06c1d6cc1..86b28716c 100644
--- a/youtube_dl/swfinterp.py
+++ b/youtube_dl/swfinterp.py
@@ -4,10 +4,12 @@ import collections
import io
import zlib
-from .compat import compat_str
+from .compat import (
+ compat_str,
+ struct_unpack,
+)
from .utils import (
ExtractorError,
- struct_unpack,
)
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 6e4573784..fa16a42ad 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -26,7 +26,6 @@ import platform
import re
import socket
import ssl
-import struct
import subprocess
import sys
import tempfile
@@ -53,6 +52,7 @@ from .compat import (
compat_urlparse,
compat_xpath,
shlex_quote,
+ struct_pack,
)
@@ -1761,24 +1761,6 @@ def escape_url(url):
fragment=escape_rfc3986(url_parsed.fragment)
).geturl()
-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
-
def read_batch_urls(batch_fd):
def fixup(url):