用于匹配URL的Python库。
项目描述
使用urlmatch来验证URL是否符合某些模式。库和匹配模式主要基于Google Chrome扩展匹配模式。
用法
from urlmatch import urlmatch
match_pattern = 'http://*.example.com/*'
urlmatch(match_pattern, 'http://subdomain.example.com/') # True
urlmatch(match_pattern, 'http://sub.subdomain.example.com/') # True
urlmatch(match_pattern, 'https://example.com/') # False
urlmatch(match_pattern, 'http://bad.com/') # False
选项
有一些选项会影响匹配模式的工作方式。
path_required(默认为True)- 一个bool,用于指定匹配模式是否必须包含路径
fuzzy_scheme(默认为False)- 一个bool,用于指定是否应该“模糊地”匹配方案。如果为真,则任何有效的方案(*、http、https)都将匹配http和https
http_auth_allowed(默认为True)- 一个bool,用于指定是否允许在URL中包含HTTP身份验证
匹配模式语法
基本的匹配模式语法很简单
<url-pattern> := <scheme>://<host><path> <scheme> := '*' | 'http' | 'https' <host> := '*' | '*.' <any char except '/' and '*'>+ <path> := '/' <any chars>
示例
http://*/* - 匹配任何使用http方案的URL
https://*/* - 匹配任何使用https方案的URL
http://*/test* - 匹配任何使用http方案且路径以test开头的URL
*://test.com/* - 匹配任何具有域名test.com的URL
http://*.test.com - 匹配 test.com 和 test.com 的任何子域名
http://test.com/foo/bar.html - 匹配确切的URL
错误
如果您发现任何问题,请在问题部分告诉我!
贡献
从 Rubinius 贡献页面
编写代码和参与应该是乐趣,而不是毅力锻炼。严格的提交政策,无论它们的其他品质如何,也意味着更长的周转时间。
提交补丁,一旦被接受,您将获得对仓库的提交访问权限。请随意fork仓库并发送拉取请求,一旦合并,您将被添加。如果不这样做,请随意骚扰 jessepollak。
如何贡献
克隆: git@github.com:jessepollak/urlmatch.git
创建一个分支: git checkout -b awesome_feature
提交代码(并为您编写的任何代码添加单元测试)。
保持最新状态: git fetch && git rebase origin/master。
运行测试: python setup.py test
一旦准备好
在GitHub上fork项目
将您的仓库作为远程仓库添加: git remote add your_remote your_repo
推送您的分支: git push your_remote awesome_feature
为分支创建拉取请求,请求审查。
一旦被接受
如果您想访问核心仓库,请随时提出!然后可以将origin更改为指向读写URL
git remote set-url origin git@github.com:jessepollak/urlmatch.git
否则,您可以在自己的fork中继续开发。
项目详情
urlmatch-1.0.1.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3f0c3529f03f3b31efc4547ce44e6512ff5714bf61f7f6ac355b1636ad16eb2d |
|
MD5 | a7096f0de153721604ac9ba63e478ce5 |
|
BLAKE2b-256 | 844e654a4b6b335b339da7208ca1e54a34d1180e94c09b11b63dd76ee731b378 |
urlmatch-1.0.1.macosx-10.12-x86_64.tar.gz的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 21c88712cfaccf22270d2dd9957fccf9afb9fc6340fb34d169f93f6305ee8938 |
|
MD5 | 8aed6b154f835ef73012dd7ca5e48041 |
|
BLAKE2b-256 | 7a1a56d2350573d36acd826c4a73300375e49b4d2f549bce406d314c19682f75 |