-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
43 lines (38 loc) · 1.03 KB
/
common.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
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
__author__ = 'byron'
import hashlib
import re
class Common:
@staticmethod
def getMd5Value(src):
src = str(src)
myMd5 = hashlib.md5()
myMd5.update(src)
myMd5_Digest = myMd5.hexdigest()
return myMd5_Digest
@staticmethod
def isValidUrl2(url):
pat = re.compile(r'^https?:/{2}\w.*?[;#?]')
match = pat.search(str(url))
if match:
href = match.group(1)
return href
else:
return url
@staticmethod
def isExternalUrl(site_url, ex_url):
pat = re.compile(r'^http.*(//|\\).*?\/|\\')
match = pat.search(str(ex_url))
if match:
href = match.group()
if site_url == href:
return True
else:
return False
else:
return False
@staticmethod
def isValidUrl(site_url, ex_url):
if ex_url is None or ex_url =="":
return False
return Common.isExternalUrl(site_url, ex_url)