Returns True if all provided urls share that same host >>> checkSameHost('http://www.target.com/page1.php?id=1', 'http://www.target.com/images/page2.php') True >>> checkSameHost('http://www.target.com/page1.php?id=1', 'http://www.target2.com/images/page2.php') False
(*urls)
| 4789 | return retVal |
| 4790 | |
| 4791 | def checkSameHost(*urls): |
| 4792 | """ |
| 4793 | Returns True if all provided urls share that same host |
| 4794 | |
| 4795 | >>> checkSameHost('http://www.target.com/page1.php?id=1', 'http://www.target.com/images/page2.php') |
| 4796 | True |
| 4797 | >>> checkSameHost('http://www.target.com/page1.php?id=1', 'http://www.target2.com/images/page2.php') |
| 4798 | False |
| 4799 | """ |
| 4800 | |
| 4801 | if not urls: |
| 4802 | return None |
| 4803 | elif len(urls) == 1: |
| 4804 | return True |
| 4805 | else: |
| 4806 | def _(value): |
| 4807 | if value and not re.search(r"\A\w+://", value): |
| 4808 | value = "http://%s" % value |
| 4809 | return value |
| 4810 | |
| 4811 | return all(re.sub(r"(?i)\Awww\.", "", _urllib.parse.urlparse(_(url) or "").netloc.split(':')[0]) == re.sub(r"(?i)\Awww\.", "", _urllib.parse.urlparse(_(urls[0]) or "").netloc.split(':')[0]) for url in urls[1:]) |
| 4812 | |
| 4813 | def getHostHeader(url): |
| 4814 | """ |
no test coverage detected
searching dependent graphs…