-
Notifications
You must be signed in to change notification settings - Fork 24
/
check_encode.py
31 lines (28 loc) · 693 Bytes
/
check_encode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from urlparse import urlparse
import random
import string
def random_token(size = 6):
"""
Generates a random string of 6 chars , use size argument
to change the size of token.
Returns a valid token of desired size ,
*default is 6 chars
"""
BASE_LIST = string.digits + string.letters
token = ''.join((random.choice(BASE_LIST)) for char in range(size))
return token
def url_check(url):
"""
Expects a string as argument.
Retruns True , if URL is valid else False.
For detailed docs look into urlparse.
"""
min_attr = ('scheme' , 'netloc')
try:
result = urlparse(url)
if all([result.scheme, result.netloc]):
return True
else:
return False
except:
return False