mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-19 15:12:01 +00:00
Compare commits
14 Commits
931b658de6
...
7e34c7e64d
Author | SHA1 | Date | |
---|---|---|---|
|
7e34c7e64d | ||
|
c5098961b0 | ||
|
dbc08fba83 | ||
|
71223bff39 | ||
|
099dcca6c4 | ||
|
42e611088e | ||
|
784f597601 | ||
|
e84f0673bb | ||
|
9b6e3940a7 | ||
|
c1c8791335 | ||
|
d2381bebaf | ||
|
abc3a6af48 | ||
|
05aa33b0b3 | ||
|
27e5c22293 |
@ -425,6 +425,34 @@ class TestJSInterpreter(unittest.TestCase):
|
|||||||
self._test(jsi, [''], args=['', '-'])
|
self._test(jsi, [''], args=['', '-'])
|
||||||
self._test(jsi, [], args=['', ''])
|
self._test(jsi, [], args=['', ''])
|
||||||
|
|
||||||
|
def test_slice(self):
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice()}', [0, 1, 2, 3, 4, 5, 6, 7, 8])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(0)}', [0, 1, 2, 3, 4, 5, 6, 7, 8])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(5)}', [5, 6, 7, 8])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(99)}', [])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-2)}', [7, 8])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-99)}', [0, 1, 2, 3, 4, 5, 6, 7, 8])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(0, 0)}', [])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(1, 0)}', [])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(0, 1)}', [0])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(3, 6)}', [3, 4, 5])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(1, -1)}', [1, 2, 3, 4, 5, 6, 7])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-1, 1)}', [])
|
||||||
|
self._test('function f(){return [0, 1, 2, 3, 4, 5, 6, 7, 8].slice(-3, -1)}', [6, 7])
|
||||||
|
self._test('function f(){return "012345678".slice()}', '012345678')
|
||||||
|
self._test('function f(){return "012345678".slice(0)}', '012345678')
|
||||||
|
self._test('function f(){return "012345678".slice(5)}', '5678')
|
||||||
|
self._test('function f(){return "012345678".slice(99)}', '')
|
||||||
|
self._test('function f(){return "012345678".slice(-2)}', '78')
|
||||||
|
self._test('function f(){return "012345678".slice(-99)}', '012345678')
|
||||||
|
self._test('function f(){return "012345678".slice(0, 0)}', '')
|
||||||
|
self._test('function f(){return "012345678".slice(1, 0)}', '')
|
||||||
|
self._test('function f(){return "012345678".slice(0, 1)}', '0')
|
||||||
|
self._test('function f(){return "012345678".slice(3, 6)}', '345')
|
||||||
|
self._test('function f(){return "012345678".slice(1, -1)}', '1234567')
|
||||||
|
self._test('function f(){return "012345678".slice(-1, 1)}', '')
|
||||||
|
self._test('function f(){return "012345678".slice(-3, -1)}', '67')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -174,6 +174,14 @@ _NSIG_TESTS = [
|
|||||||
'https://www.youtube.com/s/player/5604538d/player_ias.vflset/en_US/base.js',
|
'https://www.youtube.com/s/player/5604538d/player_ias.vflset/en_US/base.js',
|
||||||
'7X-he4jjvMx7BCX', 'sViSydX8IHtdWA',
|
'7X-he4jjvMx7BCX', 'sViSydX8IHtdWA',
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
'https://www.youtube.com/s/player/20dfca59/player_ias.vflset/en_US/base.js',
|
||||||
|
'-fLCxedkAk4LUTK2', 'O8kfRq1y1eyHGw',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
'https://www.youtube.com/s/player/b12cc44b/player_ias.vflset/en_US/base.js',
|
||||||
|
'keLa5R2U00sR9SQK', 'N1OGyujjEwMnLw',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -193,6 +193,22 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
_VALID_URL = TwitterBaseIE._BASE_REGEX + r'(?:(?:i/web|[^/]+)/status|statuses)/(?P<id>\d+)'
|
_VALID_URL = TwitterBaseIE._BASE_REGEX + r'(?:(?:i/web|[^/]+)/status|statuses)/(?P<id>\d+)'
|
||||||
|
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
|
'url': 'https://twitter.com/TulsiGabbard/status/1555878318469091330',
|
||||||
|
'md5': '8c45b02c4f324e0b9054ceb888091283',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '1555878318469091330',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'Tulsi Gabbard 🌺 - Puberty-blocking ...',
|
||||||
|
'description': 'Puberty-blocking procedures promoted by the Biden/Harris Admin are child abuse. The FDA has recently confirmed these hormones/drugs have extremely dangerous side effects, like brain swelling and vision loss. https://t.co/pcc70Uyt76',
|
||||||
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
|
'uploader': 'Tulsi Gabbard 🌺',
|
||||||
|
'uploader_id': 'TulsiGabbard',
|
||||||
|
'duration': 44.466,
|
||||||
|
'timestamp': 1659785272,
|
||||||
|
'upload_date': '20220806',
|
||||||
|
'age_limit': 0,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
'url': 'https://twitter.com/freethenipple/status/643211948184596480',
|
'url': 'https://twitter.com/freethenipple/status/643211948184596480',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '643211948184596480',
|
'id': '643211948184596480',
|
||||||
@ -213,7 +229,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '657991469417025536',
|
'id': '657991469417025536',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Gifs - tu vai cai tu vai cai tu nao eh capaz disso tu vai cai',
|
'title': 'Gifs - "tu vai cai tu vai cai tu nao eh capaz disso[...]',
|
||||||
'description': 'Gifs on Twitter: "tu vai cai tu vai cai tu nao eh capaz disso tu vai cai https://t.co/tM46VHFlO5"',
|
'description': 'Gifs on Twitter: "tu vai cai tu vai cai tu nao eh capaz disso tu vai cai https://t.co/tM46VHFlO5"',
|
||||||
'thumbnail': r're:^https?://.*\.png',
|
'thumbnail': r're:^https?://.*\.png',
|
||||||
'uploader': 'Gifs',
|
'uploader': 'Gifs',
|
||||||
@ -226,10 +242,10 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '665052190608723968',
|
'id': '665052190608723968',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Star Wars - A new beginning is coming December 18. Watch the official 60 second #TV spot for #StarWars: #TheForceAwakens.',
|
'title': 'Star Wars | Andor Premieres Sept 21 on Disney+ - A new beginning is coming December ...',
|
||||||
'description': 'A new beginning is coming December 18. Watch the official 60 second #TV spot for #StarWars: #TheForceAwakens. https://t.co/OkSqT2fjWJ',
|
'description': 'A new beginning is coming December 18. Watch the official 60 second #TV spot for #StarWars: #TheForceAwakens. https://t.co/OkSqT2fjWJ',
|
||||||
'uploader_id': 'starwars',
|
'uploader_id': 'starwars',
|
||||||
'uploader': 'Star Wars',
|
'uploader': 'Star Wars | Andor Premieres Sept 21 on Disney+',
|
||||||
'timestamp': 1447395772,
|
'timestamp': 1447395772,
|
||||||
'upload_date': '20151113',
|
'upload_date': '20151113',
|
||||||
},
|
},
|
||||||
@ -238,7 +254,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '705235433198714880',
|
'id': '705235433198714880',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': "Brent Yarina - Khalil Iverson's missed highlight dunk. And made highlight dunk. In one highlight.",
|
'title': 'Brent Yarina - Khalil Iverson\'s missed highlight dunk. And made highlight dunk[...]',
|
||||||
'description': "Khalil Iverson's missed highlight dunk. And made highlight dunk. In one highlight. https://t.co/OrxcJ28Bns",
|
'description': "Khalil Iverson's missed highlight dunk. And made highlight dunk. In one highlight. https://t.co/OrxcJ28Bns",
|
||||||
'uploader_id': 'BTNBrentYarina',
|
'uploader_id': 'BTNBrentYarina',
|
||||||
'uploader': 'Brent Yarina',
|
'uploader': 'Brent Yarina',
|
||||||
@ -255,11 +271,11 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '700207533655363584',
|
'id': '700207533655363584',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'simon vertugo - BEAT PROD: @suhmeduh #Damndaniel',
|
'title': 'jaydin donte geer - BEAT PROD: @suhmeduh #Damndaniel',
|
||||||
'description': 'BEAT PROD: @suhmeduh https://t.co/HBrQ4AfpvZ #Damndaniel https://t.co/byBooq2ejZ',
|
'description': 'BEAT PROD: @suhmeduh https://t.co/HBrQ4AfpvZ #Damndaniel https://t.co/byBooq2ejZ',
|
||||||
'thumbnail': r're:^https?://.*\.jpg',
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
'uploader': 'simon vertugo',
|
'uploader': 'jaydin donte geer',
|
||||||
'uploader_id': 'simonvertugo',
|
'uploader_id': 'jaydingeer',
|
||||||
'duration': 30.0,
|
'duration': 30.0,
|
||||||
'timestamp': 1455777459,
|
'timestamp': 1455777459,
|
||||||
'upload_date': '20160218',
|
'upload_date': '20160218',
|
||||||
@ -282,7 +298,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '719944021058060289',
|
'id': '719944021058060289',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Captain America - @King0fNerd Are you sure you made the right choice? Find out in theaters.',
|
'title': 'Captain America - @King0fNerd ...',
|
||||||
'description': '@King0fNerd Are you sure you made the right choice? Find out in theaters. https://t.co/GpgYi9xMJI',
|
'description': '@King0fNerd Are you sure you made the right choice? Find out in theaters. https://t.co/GpgYi9xMJI',
|
||||||
'uploader_id': 'CaptainAmerica',
|
'uploader_id': 'CaptainAmerica',
|
||||||
'uploader': 'Captain America',
|
'uploader': 'Captain America',
|
||||||
@ -322,7 +338,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '910031516746514432',
|
'id': '910031516746514432',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Préfet de Guadeloupe - [Direct] #Maria Le centre se trouve actuellement au sud de Basse-Terre. Restez confinés. Réfugiez-vous dans la pièce la + sûre.',
|
'title': 'Préfet de Guadeloupe - [Direct] #Maria Le centre se trouve...',
|
||||||
'thumbnail': r're:^https?://.*\.jpg',
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
'description': '[Direct] #Maria Le centre se trouve actuellement au sud de Basse-Terre. Restez confinés. Réfugiez-vous dans la pièce la + sûre. https://t.co/mwx01Rs4lo',
|
'description': '[Direct] #Maria Le centre se trouve actuellement au sud de Basse-Terre. Restez confinés. Réfugiez-vous dans la pièce la + sûre. https://t.co/mwx01Rs4lo',
|
||||||
'uploader': 'Préfet de Guadeloupe',
|
'uploader': 'Préfet de Guadeloupe',
|
||||||
@ -340,7 +356,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '1001551623938805763',
|
'id': '1001551623938805763',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 're:.*?Shep is on a roll today.*?',
|
'title': 'Lis Power - Holy shit, Shep is on a roll today....',
|
||||||
'thumbnail': r're:^https?://.*\.jpg',
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
'description': 'md5:37b9f2ff31720cef23b2bd42ee8a0f09',
|
'description': 'md5:37b9f2ff31720cef23b2bd42ee8a0f09',
|
||||||
'uploader': 'Lis Power',
|
'uploader': 'Lis Power',
|
||||||
@ -357,7 +373,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '1087791357756956680',
|
'id': '1087791357756956680',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Twitter - A new is coming. Some of you got an opt-in to try it now. Check out the emoji button, quick keyboard shortcuts, upgraded trends, advanced search, and more. Let us know your thoughts!',
|
'title': 'Twitter - A new is coming. Some of you got a...',
|
||||||
'thumbnail': r're:^https?://.*\.jpg',
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
'description': 'md5:6dfd341a3310fb97d80d2bf7145df976',
|
'description': 'md5:6dfd341a3310fb97d80d2bf7145df976',
|
||||||
'uploader': 'Twitter',
|
'uploader': 'Twitter',
|
||||||
@ -383,7 +399,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '1349794411333394432',
|
'id': '1349794411333394432',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'md5:d1c4941658e4caaa6cb579260d85dcba',
|
'title': 'Brooklyn Nets - WATCH: Sean Marks\' full media sessi...',
|
||||||
'thumbnail': r're:^https?://.*\.jpg',
|
'thumbnail': r're:^https?://.*\.jpg',
|
||||||
'description': 'md5:71ead15ec44cee55071547d6447c6a3e',
|
'description': 'md5:71ead15ec44cee55071547d6447c6a3e',
|
||||||
'uploader': 'Brooklyn Nets',
|
'uploader': 'Brooklyn Nets',
|
||||||
@ -440,14 +456,24 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'tweet_mode': 'extended',
|
'tweet_mode': 'extended',
|
||||||
})
|
})
|
||||||
|
|
||||||
title = description = status['full_text'].replace('\n', ' ')
|
# Get metadata
|
||||||
# strip 'https -_t.co_BJYgOjSeGA' junk from filenames
|
description = status['full_text'].replace('\n', ' ')
|
||||||
title = re.sub(r'\s+(https?://[^ ]+)', '', title)
|
|
||||||
user = status.get('user') or {}
|
user = status.get('user') or {}
|
||||||
uploader = user.get('name')
|
uploader = user.get('name')
|
||||||
|
uploader_id = user.get('screen_name')
|
||||||
|
timestamp = unified_timestamp(status.get('created_at'))
|
||||||
|
|
||||||
|
# Keep the file name short so it doesn't exceed filesystem limits
|
||||||
|
title = re.sub(r'\s+(https?://[^ ]+)', '', description)
|
||||||
|
if len(title) > 40:
|
||||||
|
trim = 35
|
||||||
|
# allow up to 10 more characters to find whitespace
|
||||||
|
m = re.search(r'\s+', title)
|
||||||
|
if m and m.start() > 10:
|
||||||
|
trim = m.start() + 1
|
||||||
|
title = title[:trim] + '...'
|
||||||
if uploader:
|
if uploader:
|
||||||
title = '%s - %s' % (uploader, title)
|
title = '%s - %s' % (uploader, title)
|
||||||
uploader_id = user.get('screen_name')
|
|
||||||
|
|
||||||
tags = []
|
tags = []
|
||||||
for hashtag in (try_get(status, lambda x: x['entities']['hashtags'], list) or []):
|
for hashtag in (try_get(status, lambda x: x['entities']['hashtags'], list) or []):
|
||||||
@ -461,7 +487,7 @@ class TwitterIE(TwitterBaseIE):
|
|||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'uploader': uploader,
|
'uploader': uploader,
|
||||||
'timestamp': unified_timestamp(status.get('created_at')),
|
'timestamp': timestamp,
|
||||||
'uploader_id': uploader_id,
|
'uploader_id': uploader_id,
|
||||||
'uploader_url': 'https://twitter.com/' + uploader_id if uploader_id else None,
|
'uploader_url': 'https://twitter.com/' + uploader_id if uploader_id else None,
|
||||||
'like_count': int_or_none(status.get('favorite_count')),
|
'like_count': int_or_none(status.get('favorite_count')),
|
||||||
|
@ -1659,17 +1659,46 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
|
|||||||
def _extract_n_function_name(self, jscode):
|
def _extract_n_function_name(self, jscode):
|
||||||
func_name, idx = self._search_regex(
|
func_name, idx = self._search_regex(
|
||||||
# new: (b=String.fromCharCode(110),c=a.get(b))&&c=nfunc[idx](c)
|
# new: (b=String.fromCharCode(110),c=a.get(b))&&c=nfunc[idx](c)
|
||||||
# or: (b="nn"[+a.D],c=a.get(b))&&(c=nfunc[idx](c)s
|
# or: (b="nn"[+a.D],c=a.get(b))&&(c=nfunc[idx](c)
|
||||||
# old: .get("n"))&&(b=nfunc[idx](b)
|
# or: (PL(a),b=a.j.n||null)&&(b=nfunc[idx](b)
|
||||||
# older: .get("n"))&&(b=nfunc(b)
|
# or: (b="nn"[+a.D],vL(a),c=a.j[b]||null)&&(c=narray[idx](c),a.set(b,c),narray.length||nfunc("")
|
||||||
|
# old: (b=a.get("n"))&&(b=nfunc[idx](b)(?P<c>[a-z])\s*=\s*[a-z]\s*
|
||||||
|
# older: (b=a.get("n"))&&(b=nfunc(b)
|
||||||
r'''(?x)
|
r'''(?x)
|
||||||
(?:\(\s*(?P<b>[a-z])\s*=\s*(?:
|
\((?:[\w$()\s]+,)*?\s* # (
|
||||||
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
(?P<b>[a-z])\s*=\s* # b=
|
||||||
"n+"\[\s*\+?s*[\w$.]+\s*]
|
(?:
|
||||||
)\s*,(?P<c>[a-z])\s*=\s*[a-z]\s*)?
|
(?: # expect ,c=a.get(b) (etc)
|
||||||
\.\s*get\s*\(\s*(?(b)(?P=b)|"n{1,2}")(?:\s*\)){2}\s*&&\s*\(\s*(?(c)(?P=c)|b)\s*=\s*
|
String\s*\.\s*fromCharCode\s*\(\s*110\s*\)|
|
||||||
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
"n+"\[\s*\+?s*[\w$.]+\s*]
|
||||||
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'))
|
)\s*(?:,[\w$()\s]+(?=,))*|
|
||||||
|
(?P<old>[\w$]+) # a (old[er])
|
||||||
|
)\s*
|
||||||
|
(?(old)
|
||||||
|
# b.get("n")
|
||||||
|
(?:\.\s*[\w$]+\s*|\[\s*[\w$]+\s*]\s*)*?
|
||||||
|
(?:\.\s*n|\[\s*"n"\s*]|\.\s*get\s*\(\s*"n"\s*\))
|
||||||
|
| # ,c=a.get(b)
|
||||||
|
,\s*(?P<c>[a-z])\s*=\s*[a-z]\s*
|
||||||
|
(?:\.\s*[\w$]+\s*|\[\s*[\w$]+\s*]\s*)*?
|
||||||
|
(?:\[\s*(?P=b)\s*]|\.\s*get\s*\(\s*(?P=b)\s*\))
|
||||||
|
)
|
||||||
|
# interstitial junk
|
||||||
|
\s*(?:\|\|\s*null\s*)?(?:\)\s*)?&&\s*(?:\(\s*)?
|
||||||
|
(?(c)(?P=c)|(?P=b))\s*=\s* # [c|b]=
|
||||||
|
# nfunc|nfunc[idx]
|
||||||
|
(?P<nfunc>[a-zA-Z_$][\w$]*)(?:\s*\[(?P<idx>\d+)\])?\s*\(\s*[\w$]+\s*\)
|
||||||
|
''', jscode, 'Initial JS player n function name', group=('nfunc', 'idx'),
|
||||||
|
default=(None, None))
|
||||||
|
# thx bashonly: yt-dlp/yt-dlp/pull/10611
|
||||||
|
if not func_name:
|
||||||
|
self.report_warning('Falling back to generic n function search')
|
||||||
|
return self._search_regex(
|
||||||
|
r'''(?xs)
|
||||||
|
(?:(?<=[^\w$])|^) # instead of \b, which ignores $
|
||||||
|
(?P<name>(?!\d)[a-zA-Z\d_$]+)\s*=\s*function\((?!\d)[a-zA-Z\d_$]+\)
|
||||||
|
\s*\{(?:(?!};).)+?["']enhanced_except_
|
||||||
|
''', jscode, 'Initial JS player n function name', group='name')
|
||||||
if not idx:
|
if not idx:
|
||||||
return func_name
|
return func_name
|
||||||
|
|
||||||
|
@ -925,9 +925,16 @@ class JSInterpreter(object):
|
|||||||
obj.reverse()
|
obj.reverse()
|
||||||
return obj
|
return obj
|
||||||
elif member == 'slice':
|
elif member == 'slice':
|
||||||
assertion(isinstance(obj, list), 'must be applied on a list')
|
assertion(isinstance(obj, (list, compat_str)), 'must be applied on a list or string')
|
||||||
assertion(len(argvals) == 1, 'takes exactly one argument')
|
# From [1]:
|
||||||
return obj[argvals[0]:]
|
# .slice() - like [:]
|
||||||
|
# .slice(n) - like [n:] (not [slice(n)]
|
||||||
|
# .slice(m, n) - like [m:n] or [slice(m, n)]
|
||||||
|
# [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
|
||||||
|
assertion(len(argvals) <= 2, 'takes between 0 and 2 arguments')
|
||||||
|
if len(argvals) < 2:
|
||||||
|
argvals += (None,)
|
||||||
|
return obj[slice(*argvals)]
|
||||||
elif member == 'splice':
|
elif member == 'splice':
|
||||||
assertion(isinstance(obj, list), 'must be applied on a list')
|
assertion(isinstance(obj, list), 'must be applied on a list')
|
||||||
assertion(argvals, 'takes one or more arguments')
|
assertion(argvals, 'takes one or more arguments')
|
||||||
|
Loading…
Reference in New Issue
Block a user