符合rfc 3986,支持unicode,与方案无关的urlparse替换
uritools的Python项目详细描述
此模块定义了符合RFC 3986的替换 python 2.7标准库的常用函数 urlparse和python 3urllib.parse模块。
>>> fromuritoolsimporturicompose,urijoin,urisplit,uriunsplit>>> uricompose(scheme='foo',host='example.com',port=8042,... path='/over/there',query={'name':'ferret'},... fragment='nose')'foo://example.com:8042/over/there?name=ferret#nose' >>> parts=urisplit(_)>>> parts.scheme'foo' >>> parts.authority'example.com:8042' >>> parts.getport(default=80)8042 >>> parts.getquerydict().get('name')['ferret'] >>> urijoin(uriunsplit(parts),'/right/here?name=swallow#beak')'foo://example.com:8042/right/here?name=swallow#beak'
出于各种原因,python 2urlparse模块不兼容 使用当前的Internet标准,不包括Unicode支持,以及 对于专有的uri方案通常是不可用的。Python3 urllib.parse改进了对Unicode的支持,但其他问题仍然存在 留下来。如Lib/urllib/parse.py:
RFC 3986 is considered the current standard and any future changes to urlparse module should conform with it. The urlparse module is currently not entirely compliant with this RFC due to defacto scenarios for parsing, and for backward compatibility purposes, some parsing quirks from older RFCs are retained.
本模块旨在为 在urlparse和 urllib.parse,加上额外的函数,可以方便地编写 来自各个组件的uri。
安装
使用pip安装uritools:
pip install uritools