You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

urlmatch

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urlmatch - pypi Package Compare versions

Comparing version
0.0.2
to
1.0.0
+1
urlmatch/__init__.py
from urlmatch import *
"""
urlmatch lets you easily check whether urls are on a domain or subdomain
"""
import re
class BadMatchPattern(Exception):
"""The Exception that's raised when a match pattern fails"""
pass
def parse_match_pattern(pattern, path_required=True, fuzzy_scheme=False,
http_auth_allowed=True):
"""
Returns the regular expression for a given match pattern.
Args:
pattern: a `urlmatch` formatted match pattern
path_required: a `bool` which dicates whether the match pattern
must have path
fuzzy_scheme: if this is true, then if the scheme is `*`, `http`,
or `https`, it will match both `http` and `https`
http_auth_allowed: if this is true, then URLs with http auth on the
correct domain and path will be matched
Returns:
a regular expresion for the match pattern
"""
if not isinstance(pattern, basestring):
return
pattern_regex = "(?:^"
result = re.search(r'^(\*|https?):\/\/', pattern)
if not result:
raise BadMatchPattern("Invalid scheme: {}".format(pattern))
elif result.group(1) == "*" or fuzzy_scheme:
pattern_regex += "https?"
else:
pattern_regex += result.group(1)
pattern_regex += "://"
if http_auth_allowed:
# add optional HTTP auth
safe_characters = "[^\/:.]"
pattern_regex += "(?:{safe}+(?:\:{safe}+)?@)?".format(
safe=safe_characters)
pattern = pattern[len(result.group(0)):]
domain_and_path_regex = r'^(?:\*|(\*\.)?([^\/*]+))'
if path_required:
domain_and_path_regex += r'(?=\/)'
result = re.search(domain_and_path_regex, pattern)
if not result:
raise BadMatchPattern("Invalid domain or path: {}".format(pattern))
pattern = pattern[len(result.group(0)):]
if result.group(0) == "*":
pattern_regex += "[^/]+"
else:
if result.group(1):
pattern_regex += "(?:[^/]+\\.)?"
pattern_regex += re.escape(result.group(2))
pattern_regex += ".*".join(map(re.escape, pattern.split("*")))
pattern_regex += r'(\/.*)?$)'
return pattern_regex
def urlmatch(match_pattern, url, **kwargs):
"""
Returns whether a given match pattern matches a url
Args:
match_pattern: a `urlmatch` formatted match pattern_regex
url: a url
"""
if isinstance(match_pattern, basestring):
match_pattern = map(str.strip, match_pattern.split(','))
regex = "({})".format("|".join(map(
lambda x: parse_match_pattern(x, **kwargs), match_pattern)))
return bool(regex and re.search(regex, url))
+3
-3
Metadata-Version: 1.1
Name: urlmatch
Version: 0.0.2
Version: 1.0.0
Summary: Python library for matching URLs.

@@ -37,3 +37,3 @@ Home-page: https://github.com/jessepollak/urlmatch

- ``path_re1uired`` (default is True) - a ``bool`` which dictates
- ``path_required`` (default is True) - a ``bool`` which dictates
whether the match pattern must have path

@@ -44,3 +44,3 @@ - ``fuzzy_scheme`` (default is False) - a ``bool`` which dictates

``http`` and ``https``
- 'http\_auth\_allowed' (default is True) - ``bool`` which dictates
- ``http_auth_allowed`` (default is True) - ``bool`` which dictates
whether URLs with HTTP Authentication in the URL should be allowed or

@@ -47,0 +47,0 @@ not

@@ -29,3 +29,3 @@ urlmatch - fnmatch for the web

- ``path_re1uired`` (default is True) - a ``bool`` which dictates
- ``path_required`` (default is True) - a ``bool`` which dictates
whether the match pattern must have path

@@ -36,3 +36,3 @@ - ``fuzzy_scheme`` (default is False) - a ``bool`` which dictates

``http`` and ``https``
- 'http\_auth\_allowed' (default is True) - ``bool`` which dictates
- ``http_auth_allowed`` (default is True) - ``bool`` which dictates
whether URLs with HTTP Authentication in the URL should be allowed or

@@ -39,0 +39,0 @@ not

@@ -15,6 +15,8 @@ try:

name='urlmatch',
version='0.0.2',
version='1.0.0',
author='Jesse Pollak',
author_email='jpollak92@gmail.com',
packages=[],
packages=[
'urlmatch'
],
url='https://github.com/jessepollak/urlmatch',

@@ -30,2 +32,2 @@ description=short_description,

install_requires=[]
)
)
Metadata-Version: 1.1
Name: urlmatch
Version: 0.0.2
Version: 1.0.0
Summary: Python library for matching URLs.

@@ -37,3 +37,3 @@ Home-page: https://github.com/jessepollak/urlmatch

- ``path_re1uired`` (default is True) - a ``bool`` which dictates
- ``path_required`` (default is True) - a ``bool`` which dictates
whether the match pattern must have path

@@ -44,3 +44,3 @@ - ``fuzzy_scheme`` (default is False) - a ``bool`` which dictates

``http`` and ``https``
- 'http\_auth\_allowed' (default is True) - ``bool`` which dictates
- ``http_auth_allowed`` (default is True) - ``bool`` which dictates
whether URLs with HTTP Authentication in the URL should be allowed or

@@ -47,0 +47,0 @@ not

README.txt
setup.py
urlmatch/__init__.py
urlmatch/urlmatch.py
urlmatch.egg-info/PKG-INFO

@@ -4,0 +6,0 @@ urlmatch.egg-info/SOURCES.txt

@@ -1,1 +0,1 @@

urlmatch