[ramdisk] add cvitek pre-built ramdisk
Change-Id: Ic7d2046a23358129eaf621b5558984a64fa7361d
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
|
||||
from ._url import (URL,
|
||||
parse,
|
||||
EncodedURL,
|
||||
DecodedURL,
|
||||
URLParseError,
|
||||
register_scheme)
|
||||
|
||||
__all__ = [
|
||||
"URL",
|
||||
"parse",
|
||||
"EncodedURL",
|
||||
"DecodedURL",
|
||||
"URLParseError",
|
||||
"register_scheme",
|
||||
]
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -0,0 +1,58 @@
|
||||
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
class HyperlinkTestCase(TestCase):
|
||||
"""This type mostly exists to provide a backwards-compatible
|
||||
assertRaises method for Python 2.6 testing.
|
||||
"""
|
||||
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
|
||||
"""Fail unless an exception of class excClass is raised
|
||||
by callableObj when invoked with arguments args and keyword
|
||||
arguments kwargs. If a different type of exception is
|
||||
raised, it will not be caught, and the test case will be
|
||||
deemed to have suffered an error, exactly as for an
|
||||
unexpected exception.
|
||||
|
||||
If called with callableObj omitted or None, will return a
|
||||
context object used like this::
|
||||
|
||||
with self.assertRaises(SomeException):
|
||||
do_something()
|
||||
|
||||
The context manager keeps a reference to the exception as
|
||||
the 'exception' attribute. This allows you to inspect the
|
||||
exception after the assertion::
|
||||
|
||||
with self.assertRaises(SomeException) as cm:
|
||||
do_something()
|
||||
the_exception = cm.exception
|
||||
self.assertEqual(the_exception.error_code, 3)
|
||||
"""
|
||||
context = _AssertRaisesContext(excClass, self)
|
||||
if callableObj is None:
|
||||
return context
|
||||
with context:
|
||||
callableObj(*args, **kwargs)
|
||||
|
||||
|
||||
class _AssertRaisesContext(object):
|
||||
"A context manager used to implement HyperlinkTestCase.assertRaises."
|
||||
|
||||
def __init__(self, expected, test_case):
|
||||
self.expected = expected
|
||||
self.failureException = test_case.failureException
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, tb):
|
||||
if exc_type is None:
|
||||
exc_name = self.expected.__name__
|
||||
raise self.failureException("%s not raised" % (exc_name,))
|
||||
if not issubclass(exc_type, self.expected):
|
||||
# let unexpected exceptions pass through
|
||||
return False
|
||||
self.exception = exc_value # store for later retrieval
|
||||
return True
|
||||
Binary file not shown.
@ -0,0 +1,106 @@
|
||||
"""
|
||||
Tests for hyperlink.test.common
|
||||
"""
|
||||
from unittest import TestCase
|
||||
from .common import HyperlinkTestCase
|
||||
|
||||
|
||||
class _ExpectedException(Exception):
|
||||
"""An exception used to test HyperlinkTestCase.assertRaises.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class _UnexpectedException(Exception):
|
||||
"""An exception used to test HyperlinkTestCase.assertRaises.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class TestHyperlink(TestCase):
|
||||
"""Tests for HyperlinkTestCase"""
|
||||
|
||||
def setUp(self):
|
||||
self.hyperlink_test = HyperlinkTestCase("run")
|
||||
|
||||
def test_assertRaisesWithCallable(self):
|
||||
"""HyperlinkTestCase.assertRaises does not raise an AssertionError
|
||||
when given a callable that, when called with the provided
|
||||
arguments, raises the expected exception.
|
||||
|
||||
"""
|
||||
called_with = []
|
||||
|
||||
def raisesExpected(*args, **kwargs):
|
||||
called_with.append((args, kwargs))
|
||||
raise _ExpectedException
|
||||
|
||||
self.hyperlink_test.assertRaises(_ExpectedException,
|
||||
raisesExpected, 1, keyword=True)
|
||||
self.assertEqual(called_with, [((1,), {"keyword": True})])
|
||||
|
||||
def test_assertRaisesWithCallableUnexpectedException(self):
|
||||
"""When given a callable that raises an unexpected exception,
|
||||
HyperlinkTestCase.assertRaises raises that exception.
|
||||
|
||||
"""
|
||||
|
||||
def doesNotRaiseExpected(*args, **kwargs):
|
||||
raise _UnexpectedException
|
||||
|
||||
try:
|
||||
self.hyperlink_test.assertRaises(_ExpectedException,
|
||||
doesNotRaiseExpected)
|
||||
except _UnexpectedException:
|
||||
pass
|
||||
|
||||
def test_assertRaisesWithCallableDoesNotRaise(self):
|
||||
"""HyperlinkTestCase.assertRaises raises an AssertionError when given
|
||||
a callable that, when called, does not raise any exception.
|
||||
|
||||
"""
|
||||
|
||||
def doesNotRaise(*args, **kwargs):
|
||||
return True
|
||||
|
||||
try:
|
||||
self.hyperlink_test.assertRaises(_ExpectedException,
|
||||
doesNotRaise)
|
||||
except AssertionError:
|
||||
pass
|
||||
|
||||
def test_assertRaisesContextManager(self):
|
||||
"""HyperlinkTestCase.assertRaises does not raise an AssertionError
|
||||
when used as a context manager with a suite that raises the
|
||||
expected exception. The context manager stores the exception
|
||||
instance under its `exception` instance variable.
|
||||
|
||||
"""
|
||||
with self.hyperlink_test.assertRaises(_ExpectedException) as cm:
|
||||
raise _ExpectedException
|
||||
|
||||
self.assertTrue(isinstance(cm.exception, _ExpectedException))
|
||||
|
||||
def test_assertRaisesContextManagerUnexpectedException(self):
|
||||
"""When used as a context manager with a block that raises an
|
||||
unexpected exception, HyperlinkTestCase.assertRaises raises
|
||||
that unexpected exception.
|
||||
|
||||
"""
|
||||
try:
|
||||
with self.hyperlink_test.assertRaises(_ExpectedException):
|
||||
raise _UnexpectedException
|
||||
except _UnexpectedException:
|
||||
pass
|
||||
|
||||
def test_assertRaisesContextManagerDoesNotRaise(self):
|
||||
"""HyperlinkTestcase.assertRaises raises an AssertionError when used
|
||||
as a context manager with a block that does not raise any
|
||||
exception.
|
||||
|
||||
"""
|
||||
try:
|
||||
with self.hyperlink_test.assertRaises(_ExpectedException):
|
||||
pass
|
||||
except AssertionError:
|
||||
pass
|
||||
Binary file not shown.
@ -0,0 +1,165 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .. import DecodedURL
|
||||
from .._url import _percent_decode
|
||||
from .common import HyperlinkTestCase
|
||||
|
||||
BASIC_URL = 'http://example.com/#'
|
||||
TOTAL_URL = "https://%75%73%65%72:%00%00%00%00@xn--bcher-kva.ch:8080/a/nice%20nice/./path/?zot=23%25&zut#frég"
|
||||
|
||||
|
||||
class TestURL(HyperlinkTestCase):
|
||||
|
||||
def test_durl_basic(self):
|
||||
bdurl = DecodedURL.from_text(BASIC_URL)
|
||||
assert bdurl.scheme == 'http'
|
||||
assert bdurl.host == 'example.com'
|
||||
assert bdurl.port == 80
|
||||
assert bdurl.path == ('',)
|
||||
assert bdurl.fragment == ''
|
||||
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
|
||||
assert durl.scheme == 'https'
|
||||
assert durl.host == 'bücher.ch'
|
||||
assert durl.port == 8080
|
||||
assert durl.path == ('a', 'nice nice', '.', 'path', '')
|
||||
assert durl.fragment == 'frég'
|
||||
assert durl.get('zot') == ['23%']
|
||||
|
||||
assert durl.user == 'user'
|
||||
assert durl.userinfo == ('user', '\0\0\0\0')
|
||||
|
||||
def test_passthroughs(self):
|
||||
# just basic tests for the methods that more or less pass straight
|
||||
# through to the underlying URL
|
||||
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
assert durl.sibling('te%t').path[-1] == 'te%t'
|
||||
assert durl.child('../test2%').path[-1] == '../test2%'
|
||||
assert durl.child() == durl
|
||||
assert durl.child() is durl
|
||||
assert durl.click('/').path[-1] == ''
|
||||
assert durl.user == 'user'
|
||||
|
||||
assert '.' in durl.path
|
||||
assert '.' not in durl.normalize().path
|
||||
|
||||
assert durl.to_uri().fragment == 'fr%C3%A9g'
|
||||
assert ' ' in durl.to_iri().path[1]
|
||||
|
||||
assert durl.to_text(with_password=True) == TOTAL_URL
|
||||
|
||||
assert durl.absolute
|
||||
assert durl.rooted
|
||||
|
||||
assert durl == durl.encoded_url.get_decoded_url()
|
||||
|
||||
durl2 = DecodedURL.from_text(TOTAL_URL, lazy=True)
|
||||
assert durl2 == durl2.encoded_url.get_decoded_url(lazy=True)
|
||||
|
||||
assert str(DecodedURL.from_text(BASIC_URL).child(' ')) == 'http://example.com/%20'
|
||||
|
||||
assert not (durl == 1)
|
||||
assert durl != 1
|
||||
|
||||
def test_repr(self):
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
assert repr(durl) == 'DecodedURL(url=' + repr(durl._url) + ')'
|
||||
|
||||
def test_query_manipulation(self):
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
|
||||
assert durl.get('zot') == ['23%']
|
||||
durl = durl.add(' ', 'space')
|
||||
assert durl.get(' ') == ['space']
|
||||
durl = durl.set(' ', 'spa%ed')
|
||||
assert durl.get(' ') == ['spa%ed']
|
||||
|
||||
durl = DecodedURL(url=durl.to_uri())
|
||||
assert durl.get(' ') == ['spa%ed']
|
||||
durl = durl.remove(' ')
|
||||
assert durl.get(' ') == []
|
||||
|
||||
durl = DecodedURL.from_text('/?%61rg=b&arg=c')
|
||||
assert durl.get('arg') == ['b', 'c']
|
||||
|
||||
assert durl.set('arg', 'd').get('arg') == ['d']
|
||||
|
||||
def test_equality_and_hashability(self):
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
durl2 = DecodedURL.from_text(TOTAL_URL)
|
||||
burl = DecodedURL.from_text(BASIC_URL)
|
||||
durl_uri = durl.to_uri()
|
||||
|
||||
assert durl == durl
|
||||
assert durl == durl2
|
||||
assert durl != burl
|
||||
assert durl != None
|
||||
assert durl != durl._url
|
||||
|
||||
durl_map = {}
|
||||
durl_map[durl] = durl
|
||||
durl_map[durl2] = durl2
|
||||
|
||||
assert len(durl_map) == 1
|
||||
|
||||
durl_map[burl] = burl
|
||||
|
||||
assert len(durl_map) == 2
|
||||
|
||||
durl_map[durl_uri] = durl_uri
|
||||
|
||||
assert len(durl_map) == 3
|
||||
|
||||
def test_replace_roundtrip(self):
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
|
||||
durl2 = durl.replace(scheme=durl.scheme,
|
||||
host=durl.host,
|
||||
path=durl.path,
|
||||
query=durl.query,
|
||||
fragment=durl.fragment,
|
||||
port=durl.port,
|
||||
rooted=durl.rooted,
|
||||
userinfo=durl.userinfo,
|
||||
uses_netloc=durl.uses_netloc)
|
||||
|
||||
assert durl == durl2
|
||||
|
||||
def test_replace_userinfo(self):
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
with self.assertRaises(ValueError):
|
||||
durl.replace(userinfo=['user', 'pw', 'thiswillcauseafailure'])
|
||||
return
|
||||
|
||||
def test_twisted_compat(self):
|
||||
durl = DecodedURL.from_text(TOTAL_URL)
|
||||
|
||||
assert durl == DecodedURL.fromText(TOTAL_URL)
|
||||
assert 'to_text' in dir(durl)
|
||||
assert 'asText' not in dir(durl)
|
||||
assert durl.to_text() == durl.asText()
|
||||
|
||||
def test_percent_decode_bytes(self):
|
||||
assert _percent_decode('%00', subencoding=False) == b'\0'
|
||||
|
||||
def test_percent_decode_mixed(self):
|
||||
# See https://github.com/python-hyper/hyperlink/pull/59 for a
|
||||
# nice discussion of the possibilities
|
||||
assert _percent_decode('abcdé%C3%A9éfg') == 'abcdéééfg'
|
||||
|
||||
# still allow percent encoding in the case of an error
|
||||
assert _percent_decode('abcdé%C3éfg') == 'abcdé%C3éfg'
|
||||
|
||||
# ...unless explicitly told otherwise
|
||||
with self.assertRaises(UnicodeDecodeError):
|
||||
_percent_decode('abcdé%C3éfg', raise_subencoding_exc=True)
|
||||
|
||||
# check that getting raw bytes works ok
|
||||
assert _percent_decode('a%00b', subencoding=False) == b'a\x00b'
|
||||
|
||||
# when not encodable as subencoding
|
||||
assert _percent_decode('é%25é', subencoding='ascii') == 'é%25é'
|
||||
Binary file not shown.
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .common import HyperlinkTestCase
|
||||
from hyperlink import parse, EncodedURL, DecodedURL
|
||||
|
||||
BASIC_URL = 'http://example.com/#'
|
||||
TOTAL_URL = "https://%75%73%65%72:%00%00%00%00@xn--bcher-kva.ch:8080/a/nice%20nice/./path/?zot=23%25&zut#frég"
|
||||
UNDECODABLE_FRAG_URL = TOTAL_URL + '%C3'
|
||||
# the %C3 above percent-decodes to an unpaired \xc3 byte which makes this
|
||||
# invalid utf8
|
||||
|
||||
|
||||
class TestURL(HyperlinkTestCase):
|
||||
def test_parse(self):
|
||||
purl = parse(TOTAL_URL)
|
||||
assert isinstance(purl, DecodedURL)
|
||||
assert purl.user == 'user'
|
||||
assert purl.get('zot') == ['23%']
|
||||
assert purl.fragment == 'frég'
|
||||
|
||||
purl2 = parse(TOTAL_URL, decoded=False)
|
||||
assert isinstance(purl2, EncodedURL)
|
||||
assert purl2.get('zot') == ['23%25']
|
||||
|
||||
with self.assertRaises(UnicodeDecodeError):
|
||||
purl3 = parse(UNDECODABLE_FRAG_URL)
|
||||
|
||||
purl3 = parse(UNDECODABLE_FRAG_URL, lazy=True)
|
||||
|
||||
with self.assertRaises(UnicodeDecodeError):
|
||||
purl3.fragment
|
||||
|
||||
return
|
||||
Binary file not shown.
@ -0,0 +1,64 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from .. import _url
|
||||
from .common import HyperlinkTestCase
|
||||
from .._url import register_scheme, URL
|
||||
|
||||
|
||||
class TestSchemeRegistration(HyperlinkTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self._orig_scheme_port_map = dict(_url.SCHEME_PORT_MAP)
|
||||
self._orig_no_netloc_schemes = set(_url.NO_NETLOC_SCHEMES)
|
||||
|
||||
def tearDown(self):
|
||||
_url.SCHEME_PORT_MAP = self._orig_scheme_port_map
|
||||
_url.NO_NETLOC_SCHEMES = self._orig_no_netloc_schemes
|
||||
|
||||
def test_register_scheme_basic(self):
|
||||
register_scheme('deltron', uses_netloc=True, default_port=3030)
|
||||
|
||||
u1 = URL.from_text('deltron://example.com')
|
||||
assert u1.scheme == 'deltron'
|
||||
assert u1.port == 3030
|
||||
assert u1.uses_netloc is True
|
||||
|
||||
# test netloc works even when the original gives no indication
|
||||
u2 = URL.from_text('deltron:')
|
||||
u2 = u2.replace(host='example.com')
|
||||
assert u2.to_text() == 'deltron://example.com'
|
||||
|
||||
# test default port means no emission
|
||||
u3 = URL.from_text('deltron://example.com:3030')
|
||||
assert u3.to_text() == 'deltron://example.com'
|
||||
|
||||
register_scheme('nonetron', default_port=3031)
|
||||
u4 = URL(scheme='nonetron')
|
||||
u4 = u4.replace(host='example.com')
|
||||
assert u4.to_text() == 'nonetron://example.com'
|
||||
|
||||
def test_register_no_netloc_scheme(self):
|
||||
register_scheme('noloctron', uses_netloc=False)
|
||||
u4 = URL(scheme='noloctron')
|
||||
u4 = u4.replace(path=("example", "path"))
|
||||
assert u4.to_text() == 'noloctron:example/path'
|
||||
|
||||
def test_register_no_netloc_with_port(self):
|
||||
with self.assertRaises(ValueError):
|
||||
register_scheme('badnetlocless', uses_netloc=False, default_port=7)
|
||||
|
||||
def test_invalid_uses_netloc(self):
|
||||
with self.assertRaises(ValueError):
|
||||
register_scheme('badnetloc', uses_netloc=None)
|
||||
with self.assertRaises(ValueError):
|
||||
register_scheme('badnetloc', uses_netloc=object())
|
||||
|
||||
def test_register_invalid_uses_netloc(self):
|
||||
with self.assertRaises(ValueError):
|
||||
register_scheme('lol', uses_netloc=lambda: 'nope')
|
||||
|
||||
def test_register_invalid_port(self):
|
||||
with self.assertRaises(ValueError):
|
||||
register_scheme('nope', default_port=lambda: 'lol')
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Reference in New Issue
Block a user