mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-23 00:52:01 +00:00
[utils,compat] Move struct_pack and struct_unpack to compat.py
This commit is contained in:
parent
4350b74545
commit
dab0daeeb0
@ -20,6 +20,7 @@
|
|||||||
compat_urllib_parse_unquote,
|
compat_urllib_parse_unquote,
|
||||||
compat_urllib_parse_unquote_plus,
|
compat_urllib_parse_unquote_plus,
|
||||||
compat_urllib_parse_urlencode,
|
compat_urllib_parse_urlencode,
|
||||||
|
struct_unpack,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -102,5 +103,9 @@ def test_compat_etree_fromstring(self):
|
|||||||
self.assertTrue(isinstance(doc.find('chinese').text, compat_str))
|
self.assertTrue(isinstance(doc.find('chinese').text, compat_str))
|
||||||
self.assertTrue(isinstance(doc.find('foo/bar').text, compat_str))
|
self.assertTrue(isinstance(doc.find('foo/bar').text, compat_str))
|
||||||
|
|
||||||
|
def test_struct_unpack(self):
|
||||||
|
self.assertEqual(struct_unpack('!B', b'\x00'), (0,))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -55,7 +55,6 @@
|
|||||||
smuggle_url,
|
smuggle_url,
|
||||||
str_to_int,
|
str_to_int,
|
||||||
strip_jsonp,
|
strip_jsonp,
|
||||||
struct_unpack,
|
|
||||||
timeconvert,
|
timeconvert,
|
||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
unified_strdate,
|
unified_strdate,
|
||||||
@ -457,9 +456,6 @@ def get_page(pagenum):
|
|||||||
testPL(5, 2, (2, 99), [2, 3, 4])
|
testPL(5, 2, (2, 99), [2, 3, 4])
|
||||||
testPL(5, 2, (20, 99), [])
|
testPL(5, 2, (20, 99), [])
|
||||||
|
|
||||||
def test_struct_unpack(self):
|
|
||||||
self.assertEqual(struct_unpack('!B', b'\x00'), (0,))
|
|
||||||
|
|
||||||
def test_read_batch_urls(self):
|
def test_read_batch_urls(self):
|
||||||
f = io.StringIO('''\xef\xbb\xbf foo
|
f = io.StringIO('''\xef\xbb\xbf foo
|
||||||
bar\r
|
bar\r
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
import socket
|
import socket
|
||||||
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import itertools
|
import itertools
|
||||||
@ -592,6 +593,26 @@ def compat_itertools_count(start=0, step=1):
|
|||||||
else:
|
else:
|
||||||
from tokenize import generate_tokens as compat_tokenize_tokenize
|
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__ = [
|
__all__ = [
|
||||||
'compat_HTMLParser',
|
'compat_HTMLParser',
|
||||||
'compat_HTTPError',
|
'compat_HTTPError',
|
||||||
@ -634,6 +655,8 @@ def compat_itertools_count(start=0, step=1):
|
|||||||
'compat_xml_parse_error',
|
'compat_xml_parse_error',
|
||||||
'compat_xpath',
|
'compat_xpath',
|
||||||
'shlex_quote',
|
'shlex_quote',
|
||||||
|
'struct_pack',
|
||||||
|
'struct_unpack',
|
||||||
'subprocess_check_output',
|
'subprocess_check_output',
|
||||||
'workaround_optparse_bug9161',
|
'workaround_optparse_bug9161',
|
||||||
]
|
]
|
||||||
|
@ -12,13 +12,13 @@
|
|||||||
compat_urlparse,
|
compat_urlparse,
|
||||||
compat_urllib_error,
|
compat_urllib_error,
|
||||||
compat_urllib_parse_urlparse,
|
compat_urllib_parse_urlparse,
|
||||||
|
struct_pack,
|
||||||
|
struct_unpack,
|
||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
encodeFilename,
|
encodeFilename,
|
||||||
fix_xml_ampersands,
|
fix_xml_ampersands,
|
||||||
sanitize_open,
|
sanitize_open,
|
||||||
struct_pack,
|
|
||||||
struct_unpack,
|
|
||||||
xpath_text,
|
xpath_text,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..compat import (
|
||||||
|
struct_unpack,
|
||||||
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
float_or_none,
|
float_or_none,
|
||||||
@ -13,7 +16,6 @@
|
|||||||
remove_start,
|
remove_start,
|
||||||
sanitized_Request,
|
sanitized_Request,
|
||||||
std_headers,
|
std_headers,
|
||||||
struct_unpack,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
import io
|
import io
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
from .compat import compat_str
|
from .compat import (
|
||||||
|
compat_str,
|
||||||
|
struct_unpack,
|
||||||
|
)
|
||||||
from .utils import (
|
from .utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
struct_unpack,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import struct
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -53,6 +52,7 @@
|
|||||||
compat_urlparse,
|
compat_urlparse,
|
||||||
compat_xpath,
|
compat_xpath,
|
||||||
shlex_quote,
|
shlex_quote,
|
||||||
|
struct_pack,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -1761,24 +1761,6 @@ def escape_url(url):
|
|||||||
fragment=escape_rfc3986(url_parsed.fragment)
|
fragment=escape_rfc3986(url_parsed.fragment)
|
||||||
).geturl()
|
).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 read_batch_urls(batch_fd):
|
||||||
def fixup(url):
|
def fixup(url):
|
||||||
|
Loading…
Reference in New Issue
Block a user