aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-02-26 14:37:20 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-02-26 14:37:20 +0800
commit59f898b7a72284efb994a8c6baee7771046226dd (patch)
treea82844dbd548a37ad7509c8250e0909bc0f8eca9 /youtube_dl/utils.py
parent8f4a2124a914207912bf9fc37e593210e8dd423b (diff)
[utils] Merge base_n functions
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index be1f3b0d7..900e07a8e 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -2621,19 +2621,17 @@ def ohdave_rsa_encrypt(data, exponent, modulus):
return '%x' % encrypted
-def base_n(num, n, table):
+def base_n(num, n, table=None):
if num == 0:
return '0'
+
+ FULL_TABLE = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ assert n <= len(FULL_TABLE)
+ if not table:
+ table = FULL_TABLE[:n]
+
ret = ''
while num:
ret = table[num % n] + ret
num = num // n
return ret
-
-
-def base36(num):
- return base_n(num, 36, '0123456789abcdefghijklmnopqrstuvwxyz')
-
-
-def base62(num):
- return base_n(num, 62, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')