This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from fredthomsen/validate_ipv6_support
Validate ipv6 support
- Loading branch information
Showing
18 changed files
with
1,285 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright 2014 Ian Cordasco, Rackspace | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2014 Rackspace | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
rfc3986 | ||
======= | ||
An implementation of semantics and validations described in RFC 3986. See | ||
http://rfc3986.rtfd.org/ for documentation. | ||
:copyright: (c) 2014 Rackspace | ||
:license: Apache v2.0, see LICENSE for details | ||
""" | ||
|
||
__title__ = 'rfc3986' | ||
__author__ = 'Ian Cordasco' | ||
__author_email__ = 'ian.cordasco@rackspace.com' | ||
__license__ = 'Apache v2.0' | ||
__copyright__ = 'Copyright 2014 Rackspace' | ||
__version__ = '0.3.0' | ||
|
||
from .api import (URIReference, uri_reference, is_valid_uri, normalize_uri, | ||
urlparse) | ||
from .parseresult import ParseResult | ||
|
||
__all__ = ( | ||
'ParseResult', | ||
'URIReference', | ||
'is_valid_uri', | ||
'normalize_uri', | ||
'uri_reference', | ||
'urlparse', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2014 Rackspace | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
rfc3986.api | ||
~~~~~~~~~~~ | ||
This defines the simple API to rfc3986. This module defines 3 functions and | ||
provides access to the class ``URIReference``. | ||
""" | ||
|
||
from .uri import URIReference | ||
from .parseresult import ParseResult | ||
|
||
|
||
def uri_reference(uri, encoding='utf-8'): | ||
"""Parse a URI string into a URIReference. | ||
This is a convenience function. You could achieve the same end by using | ||
``URIReference.from_string(uri)``. | ||
:param str uri: The URI which needs to be parsed into a reference. | ||
:param str encoding: The encoding of the string provided | ||
:returns: A parsed URI | ||
:rtype: :class:`URIReference` | ||
""" | ||
return URIReference.from_string(uri, encoding) | ||
|
||
|
||
def is_valid_uri(uri, encoding='utf-8', **kwargs): | ||
"""Determine if the URI given is valid. | ||
This is a convenience function. You could use either | ||
``uri_reference(uri).is_valid()`` or | ||
``URIReference.from_string(uri).is_valid()`` to achieve the same result. | ||
:param str uri: The URI to be validated. | ||
:param str encoding: The encoding of the string provided | ||
:param bool require_scheme: Set to ``True`` if you wish to require the | ||
presence of the scheme component. | ||
:param bool require_authority: Set to ``True`` if you wish to require the | ||
presence of the authority component. | ||
:param bool require_path: Set to ``True`` if you wish to require the | ||
presence of the path component. | ||
:param bool require_query: Set to ``True`` if you wish to require the | ||
presence of the query component. | ||
:param bool require_fragment: Set to ``True`` if you wish to require the | ||
presence of the fragment component. | ||
:returns: ``True`` if the URI is valid, ``False`` otherwise. | ||
:rtype: bool | ||
""" | ||
return URIReference.from_string(uri, encoding).is_valid(**kwargs) | ||
|
||
|
||
def normalize_uri(uri, encoding='utf-8'): | ||
"""Normalize the given URI. | ||
This is a convenience function. You could use either | ||
``uri_reference(uri).normalize().unsplit()`` or | ||
``URIReference.from_string(uri).normalize().unsplit()`` instead. | ||
:param str uri: The URI to be normalized. | ||
:param str encoding: The encoding of the string provided | ||
:returns: The normalized URI. | ||
:rtype: str | ||
""" | ||
normalized_reference = URIReference.from_string(uri, encoding).normalize() | ||
return normalized_reference.unsplit() | ||
|
||
|
||
def urlparse(uri, encoding='utf-8'): | ||
"""Parse a given URI and return a ParseResult. | ||
This is a partial replacement of the standard library's urlparse function. | ||
:param str uri: The URI to be parsed. | ||
:param str encoding: The encoding of the string provided. | ||
:returns: A parsed URI | ||
:rtype: :class:`~rfc3986.parseresult.ParseResult` | ||
""" | ||
return ParseResult.from_string(uri, encoding, strict=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2014 Rackspace | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
|
||
|
||
if sys.version_info >= (3, 0): | ||
unicode = str # Python 3.x | ||
|
||
|
||
def to_str(b, encoding): | ||
if hasattr(b, 'decode') and not isinstance(b, unicode): | ||
b = b.decode('utf-8') | ||
return b | ||
|
||
|
||
def to_bytes(s, encoding): | ||
if hasattr(s, 'encode') and not isinstance(s, bytes): | ||
s = s.encode('utf-8') | ||
return s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
class RFC3986Exception(Exception): | ||
pass | ||
|
||
|
||
class InvalidAuthority(RFC3986Exception): | ||
def __init__(self, authority): | ||
super(InvalidAuthority, self).__init__( | ||
"The authority ({0}) is not valid.".format(authority)) | ||
|
||
|
||
class InvalidPort(RFC3986Exception): | ||
def __init__(self, port): | ||
super(InvalidPort, self).__init__( | ||
'The port ("{0}") is not valid.'.format(port)) | ||
|
||
|
||
class ResolutionError(RFC3986Exception): | ||
def __init__(self, uri): | ||
super(ResolutionError, self).__init__( | ||
"{0} is not an absolute URI.".format(uri.unsplit())) |
Oops, something went wrong.