Interface ( Functions : Objects : Constants ) : Examples : Structure : Support : Download : Copyright & License : History : Home | Version 0.2.0 |
This package provides a new datatype for storing and manipulating URL values as well as a few helpers related to URL building, encoding and decoding.
The main intention of the package is to provide an easy to use, fast and lightwheight datatype for Universal Resource Locators (note the W3C now calls these URIs).
The mxURL package defines the following interfaces.
These functions are available.
If the url already provides a scheme, nothing is
changed. Strings are turned into URL object by the
function.
These conventions are used:
extension must be a file name extension including the
delimiting dot (e.g. ".html"). The function will
overwrite any existing entry for the given extension.
Note that mxURL uses the dictionary
To simplify and speed up handling URLs the package provides
a new type to work with them in an object oriented way.
URL objects can be added to each other as well as right
added to strings giving a joined URL object in both cases.
The join semantics depend on the URL schemes and their
attributes.
These schemes are predefined by the module. The function
The uses_* fields are integers 0 or 1 representing the
schemes possibilities. When a feature is set to 0 the
corresponding field is left out while parsing the
URL. Characters which would normally be seen as separators
are ignored then.
uses_relative is important when joining URLs. Only URLs
with uses_relative will have their paths joined
according to the common rules.
Note that the URL object constructors will raise
a ValueError exception for unknown schemes they find in the
construction string.
These constructors are available in the package:
Normalizing means that unnecessary relative
components and slashes are removed from the URL prior to
storing it. The stored URL will always be equivalent to the
one given to the constructor.
Note: The URL type uses a scheme feature dictionary
to figure out how to parse different schemes. Use the
A URL instance
In case the url already forfills this requirement, a new
reference to it is returned.
URL and baseURL must both be absolute URLs for this to
work. An exception is raised otherwise. The base URL
should provide also scheme and netloc, because otherwise
joining might result in lossage of scheme information.
If only the URL provides a scheme, then the returned
relative URL will also include that scheme.
Parameters, fragment and query of the URL object are
preserved; only the path is made relative and the netloc
removed (relative paths and netlocs don't go together).
In case both URLs provide schemes and/or netlocs that
point to different resources, the method simply returns
a new reference to the object.
Arguments not given are taken unchanged from the URL
object.
index may be negative to indicate an entry counted from
the right (with -1 being the rightmost entry). An
IndexError is raised in case the index lies out of
range. Leading and trailing slashes are not counted.
Leading and trailing slashes are not counted.
Leading and trailing slashes are ignored and the slashes
are not included.
A URL instance
Functions
escape(url)
unescape(url)
urlencode(url)
urldecode(url)
urljoin(u,v)
addscheme(url)
www. -> http://www.
ftp. -> ftp://ftp.
[/.] -> file:[/.]
none of these -> http://
register_scheme(scheme, uses_netloc, uses_params,
uses_query, uses_fragment, uses_relative)
register_mimetype(extension,major='*',minor='*')
mimetypes.types_map
as its registry, so
changes done with this function will be available
through the mimetypes module too. URL Object
Predfined URL schemes
register_scheme()
(see above) allows adding new
ones or changing the behaviour for predefined ones.
Scheme
uses_netloc
uses_params
uses_query
uses_fragment
uses_relative
http 1 1 1 1 1
https 1 1 1 1 1
shttp 1 1 1 1 1
mailto 0 0 1 0 0
ftp 1 1 0 1 1
gopher 1 0 0 1 1
news 1 0 0 1 1
nntp 1 0 0 0 1
telnet 1 0 0 1 0
file 1 0 0 0 1
about 0 0 0 0 0
javascript 0 0 0 0 0
URL Constructors
URL(url)
RawURL(url)
BuildURL(scheme='', netloc='', path='', params='',
query='', fragment='')
add_scheme()
to access this dictionary.
URL Instance Methods
url
defines these
methods:
depth()
normalized()
parsed()
basic()
relative(baseURL)
rebuild(scheme='', netloc='', path='', params='',
query='', fragment='')
pathentry(index)
pathlen()
.pathentry()
method.
pathtuple()
URL Instance Variables
url
provides access to
these (read-only) variables:
absolute
base
ext
file
fragment
netloc
host
user
passwd
port
params
path
scheme
string, url
absolute
normal
mimetype
types_map
dictionary of the Python standard
lib's mimetype module as basis for finding out
the MIME type. You can add entries to that dictionary at
runtime to adapt the mechanism to your needs. Constants
Error
Here is a very simple one:
from mx.URL import * url = URL('http://search.python.org/query.html?qt=mx') print url.scheme >>> http print url.host >>> search.python.org print url.query >>> qt=mx print url.path >>> /query.html
More examples will eventually appear in the Examples
subdirectory of the package.
Entries enclosed in brackets are packages (i.e. they are
directories that include a __init__.py file). Ones
without brackets are just simple subdirectories that are not
accessible via
The package imports all symbols from the extension module,
so you only need to '
eGenix.com is providing commercial support for this
package. If you are interested in receiving information
about this service please see the eGenix.com
Support Conditions.
© 1997-2000, Copyright by Marc-André Lemburg;
All Rights Reserved. mailto: mal@lemburg.com
© 2000-2001, Copyright by eGenix.com Software GmbH,
Langenfeld, Germany; All Rights Reserved. mailto: info@egenix.com
This software is covered by the eGenix.com Public
License Agreement. The text of the license is also
included as file "LICENSE" in the package's main directory.
By downloading, copying, installing or otherwise using
the software, you agree to be bound by the terms and
conditions of the eGenix.com
Public License Agreement.
Things that still need to be done:
Changes from 0.1.0 to 0.2.0:
Version 0.1.0 was the intial release.
© 1998-2000, Copyright by Marc-André Lemburg;
All Rights Reserved. mailto: mal@lemburg.com
© 2000-2001, Copyright by eGenix.com Software GmbH;
All Rights Reserved. mailto: info@egenix.com
Package Structure
[URL]
Doc/
[mxURL]
URL.py
import
.
from mx import URL
' to start
working.
Support
What I'd like to hear from you...
Copyright & License
History & Future