003 File Manager
Current Path:
/usr/local/lib/python3.8/test
usr
/
local
/
lib
/
python3.8
/
test
/
📁
..
📄
Sine-1000Hz-300ms.aif
(60.25 KB)
📄
__init__.py
(47 B)
📄
__main__.py
(41 B)
📁
__pycache__
📄
_test_multiprocessing.py
(183.09 KB)
📄
allsans.pem
(9.87 KB)
📄
ann_module.py
(1.08 KB)
📄
ann_module2.py
(519 B)
📄
ann_module3.py
(448 B)
📁
audiodata
📄
audiotest.au
(27.48 KB)
📄
audiotests.py
(12.46 KB)
📄
audit-tests.py
(8.9 KB)
📄
autotest.py
(209 B)
📄
bad_coding.py
(24 B)
📄
bad_coding2.py
(30 B)
📄
bad_getattr.py
(61 B)
📄
bad_getattr2.py
(77 B)
📄
bad_getattr3.py
(139 B)
📄
badcert.pem
(1.88 KB)
📄
badkey.pem
(2.11 KB)
📄
badsyntax_3131.py
(32 B)
📄
badsyntax_future10.py
(95 B)
📄
badsyntax_future3.py
(172 B)
📄
badsyntax_future4.py
(153 B)
📄
badsyntax_future5.py
(184 B)
📄
badsyntax_future6.py
(161 B)
📄
badsyntax_future7.py
(196 B)
📄
badsyntax_future8.py
(122 B)
📄
badsyntax_future9.py
(142 B)
📄
badsyntax_pep3120.py
(14 B)
📄
bisect_cmd.py
(4.85 KB)
📄
bytecode_helper.py
(1.56 KB)
📁
capath
📄
cfgparser.1
(67 B)
📄
cfgparser.2
(19.02 KB)
📄
cfgparser.3
(1.55 KB)
📁
cjkencodings
📄
clinic.test
(94.65 KB)
📄
cmath_testcases.txt
(141.05 KB)
📄
coding20731.py
(22 B)
📄
curses_tests.py
(1.22 KB)
📁
data
📄
dataclass_module_1.py
(837 B)
📄
dataclass_module_1_str.py
(835 B)
📄
dataclass_module_2.py
(756 B)
📄
dataclass_module_2_str.py
(754 B)
📄
dataclass_textanno.py
(126 B)
📄
datetimetester.py
(239.84 KB)
📁
decimaltestdata
📄
dis_module.py
(76 B)
📄
doctest_aliases.py
(240 B)
📄
double_const.py
(1.18 KB)
📁
dtracedata
📁
eintrdata
📄
empty.vbs
(70 B)
📁
encoded_modules
📄
exception_hierarchy.txt
(1.78 KB)
📄
ffdh3072.pem
(2.16 KB)
📄
final_a.py
(411 B)
📄
final_b.py
(411 B)
📄
floating_points.txt
(15.92 KB)
📄
fork_wait.py
(2.53 KB)
📄
formatfloat_testcases.txt
(7.45 KB)
📄
future_test1.py
(229 B)
📄
future_test2.py
(149 B)
📄
gdb_sample.py
(153 B)
📄
good_getattr.py
(198 B)
📄
idnsans.pem
(9.71 KB)
📄
ieee754.txt
(3.21 KB)
📁
imghdrdata
📄
imp_dummy.py
(63 B)
📄
inspect_fodder.py
(1.88 KB)
📄
inspect_fodder2.py
(2.06 KB)
📄
keycert.passwd.pem
(4.13 KB)
📄
keycert.pem
(3.96 KB)
📄
keycert2.pem
(3.98 KB)
📄
keycert3.pem
(9.23 KB)
📄
keycert4.pem
(9.24 KB)
📄
keycertecc.pem
(5.5 KB)
📁
libregrtest
📄
list_tests.py
(16.54 KB)
📄
lock_tests.py
(28.26 KB)
📄
mailcap.txt
(1.24 KB)
📄
make_ssl_certs.py
(9.25 KB)
📄
mapping_tests.py
(21.75 KB)
📄
math_testcases.txt
(23.19 KB)
📄
memory_watchdog.py
(859 B)
📄
mime.types
(47.37 KB)
📄
mock_socket.py
(3.53 KB)
📄
mod_generics_cache.py
(1.13 KB)
📄
mp_fork_bomb.py
(448 B)
📄
mp_preload.py
(351 B)
📄
multibytecodec_support.py
(14.17 KB)
📄
nokia.pem
(1.88 KB)
📄
nosan.pem
(7.54 KB)
📄
nullbytecert.pem
(5.31 KB)
📄
nullcert.pem
(0 B)
📄
outstanding_bugs.py
(370 B)
📄
pickletester.py
(135.99 KB)
📄
profilee.py
(2.97 KB)
📄
pstats.pck
(65.05 KB)
📄
pycacert.pem
(5.53 KB)
📄
pycakey.pem
(2.43 KB)
📄
pyclbr_input.py
(648 B)
📄
pydoc_mod.py
(713 B)
📄
pydocfodder.py
(6.18 KB)
📄
pythoninfo.py
(20.34 KB)
📄
randv2_32.pck
(7.34 KB)
📄
randv2_64.pck
(7.19 KB)
📄
randv3.pck
(7.82 KB)
📄
re_tests.py
(25.93 KB)
📄
recursion.tar
(516 B)
📄
regrtest.py
(1.34 KB)
📄
relimport.py
(27 B)
📄
reperf.py
(538 B)
📄
revocation.crl
(800 B)
📄
sample_doctest.py
(1.02 KB)
📄
sample_doctest_no_docstrings.py
(227 B)
📄
sample_doctest_no_doctests.py
(269 B)
📄
secp384r1.pem
(256 B)
📄
selfsigned_pythontestdotnet.pem
(2.08 KB)
📄
seq_tests.py
(14.18 KB)
📄
sgml_input.html
(8.1 KB)
📄
signalinterproctester.py
(2.7 KB)
📁
sndhdrdata
📄
sortperf.py
(4.69 KB)
📄
ssl_cert.pem
(1.53 KB)
📄
ssl_key.passwd.pem
(2.59 KB)
📄
ssl_key.pem
(2.43 KB)
📄
ssl_servers.py
(7.04 KB)
📄
ssltests.py
(1.03 KB)
📄
string_tests.py
(64.65 KB)
📁
subprocessdata
📁
support
📄
talos-2019-0758.pem
(1.3 KB)
📄
test___all__.py
(4.12 KB)
📄
test___future__.py
(2.36 KB)
📄
test__locale.py
(7.83 KB)
📄
test__opcode.py
(3.03 KB)
📄
test__osx_support.py
(13.66 KB)
📄
test__xxsubinterpreters.py
(68.7 KB)
📄
test_abc.py
(18 KB)
📄
test_abstract_numbers.py
(1.49 KB)
📄
test_aifc.py
(17.68 KB)
📄
test_argparse.py
(172.67 KB)
📄
test_array.py
(52.57 KB)
📄
test_asdl_parser.py
(4.15 KB)
📄
test_ast.py
(88.53 KB)
📄
test_asyncgen.py
(31.44 KB)
📄
test_asynchat.py
(9.28 KB)
📁
test_asyncio
📄
test_asyncore.py
(25.81 KB)
📄
test_atexit.py
(5.81 KB)
📄
test_audioop.py
(28.24 KB)
📄
test_audit.py
(4.05 KB)
📄
test_augassign.py
(7.68 KB)
📄
test_base64.py
(30.17 KB)
📄
test_baseexception.py
(6.86 KB)
📄
test_bdb.py
(41.55 KB)
📄
test_bigaddrspace.py
(2.92 KB)
📄
test_bigmem.py
(44.88 KB)
📄
test_binascii.py
(18 KB)
📄
test_binhex.py
(1.79 KB)
📄
test_binop.py
(14.14 KB)
📄
test_bisect.py
(13.63 KB)
📄
test_bool.py
(12.48 KB)
📄
test_buffer.py
(160.04 KB)
📄
test_bufio.py
(2.54 KB)
📄
test_builtin.py
(78.38 KB)
📄
test_bytes.py
(72.23 KB)
📄
test_bz2.py
(36.76 KB)
📄
test_c_locale_coercion.py
(18.82 KB)
📄
test_calendar.py
(48.71 KB)
📄
test_call.py
(20.88 KB)
📄
test_capi.py
(30.46 KB)
📄
test_cgi.py
(22.15 KB)
📄
test_cgitb.py
(2.5 KB)
📄
test_charmapcodec.py
(1.68 KB)
📄
test_class.py
(17.42 KB)
📄
test_clinic.py
(21.71 KB)
📄
test_cmath.py
(24.07 KB)
📄
test_cmd.py
(6.1 KB)
📄
test_cmd_line.py
(33.72 KB)
📄
test_cmd_line_script.py
(31.46 KB)
📄
test_code.py
(13.66 KB)
📄
test_code_module.py
(5.51 KB)
📄
test_codeccallbacks.py
(40.97 KB)
📄
test_codecencodings_cn.py
(3.86 KB)
📄
test_codecencodings_hk.py
(701 B)
📄
test_codecencodings_iso2022.py
(1.36 KB)
📄
test_codecencodings_jp.py
(4.79 KB)
📄
test_codecencodings_kr.py
(2.96 KB)
📄
test_codecencodings_tw.py
(681 B)
📄
test_codecmaps_cn.py
(746 B)
📄
test_codecmaps_hk.py
(386 B)
📄
test_codecmaps_jp.py
(1.7 KB)
📄
test_codecmaps_kr.py
(1.16 KB)
📄
test_codecmaps_tw.py
(705 B)
📄
test_codecs.py
(129.38 KB)
📄
test_codeop.py
(7.97 KB)
📄
test_collections.py
(83.93 KB)
📄
test_colorsys.py
(3.83 KB)
📄
test_compare.py
(3.82 KB)
📄
test_compile.py
(36.48 KB)
📄
test_compileall.py
(26.7 KB)
📄
test_complex.py
(30.24 KB)
📄
test_concurrent_futures.py
(44.93 KB)
📄
test_configparser.py
(84.93 KB)
📄
test_contains.py
(3.49 KB)
📄
test_context.py
(29.33 KB)
📄
test_contextlib.py
(32.54 KB)
📄
test_contextlib_async.py
(14.82 KB)
📄
test_copy.py
(25.81 KB)
📄
test_copyreg.py
(4.39 KB)
📄
test_coroutines.py
(62.52 KB)
📄
test_cprofile.py
(6.33 KB)
📄
test_crashers.py
(1.17 KB)
📄
test_crypt.py
(3.97 KB)
📄
test_csv.py
(47.77 KB)
📄
test_ctypes.py
(184 B)
📄
test_curses.py
(45.47 KB)
📄
test_dataclasses.py
(108.8 KB)
📄
test_datetime.py
(2.15 KB)
📄
test_dbm.py
(6.45 KB)
📄
test_dbm_dumb.py
(10.61 KB)
📄
test_dbm_gnu.py
(6.22 KB)
📄
test_dbm_ndbm.py
(5.05 KB)
📄
test_decimal.py
(206.63 KB)
📄
test_decorators.py
(9.48 KB)
📄
test_defaultdict.py
(5.88 KB)
📄
test_deque.py
(34.46 KB)
📄
test_descr.py
(190.58 KB)
📄
test_descrtut.py
(11.53 KB)
📄
test_devpoll.py
(4.5 KB)
📄
test_dict.py
(45 KB)
📄
test_dict_version.py
(5.88 KB)
📄
test_dictcomps.py
(4.42 KB)
📄
test_dictviews.py
(11.68 KB)
📄
test_difflib.py
(19.64 KB)
📄
test_difflib_expect.html
(100.85 KB)
📄
test_dis.py
(48.4 KB)
📄
test_distutils.py
(375 B)
📄
test_doctest.py
(98.67 KB)
📄
test_doctest.txt
(300 B)
📄
test_doctest2.py
(2.3 KB)
📄
test_doctest2.txt
(392 B)
📄
test_doctest3.txt
(82 B)
📄
test_doctest4.txt
(244 B)
📄
test_docxmlrpc.py
(8.67 KB)
📄
test_dtrace.py
(5.23 KB)
📄
test_dummy_thread.py
(9.69 KB)
📄
test_dummy_threading.py
(1.7 KB)
📄
test_dynamic.py
(4.29 KB)
📄
test_dynamicclassattribute.py
(9.57 KB)
📄
test_eintr.py
(1.32 KB)
📁
test_email
📄
test_embed.py
(49.23 KB)
📄
test_ensurepip.py
(9.83 KB)
📄
test_enum.py
(113.68 KB)
📄
test_enumerate.py
(8.46 KB)
📄
test_eof.py
(1.94 KB)
📄
test_epoll.py
(9.03 KB)
📄
test_errno.py
(1.04 KB)
📄
test_exception_hierarchy.py
(7.43 KB)
📄
test_exception_variations.py
(3.86 KB)
📄
test_exceptions.py
(49.81 KB)
📄
test_extcall.py
(13.49 KB)
📄
test_faulthandler.py
(28.13 KB)
📄
test_fcntl.py
(6.21 KB)
📄
test_file.py
(11.02 KB)
📄
test_file_eintr.py
(10.6 KB)
📄
test_filecmp.py
(8.69 KB)
📄
test_fileinput.py
(37.33 KB)
📄
test_fileio.py
(19.96 KB)
📄
test_finalization.py
(14.66 KB)
📄
test_float.py
(63.41 KB)
📄
test_flufl.py
(1.32 KB)
📄
test_fnmatch.py
(5.07 KB)
📄
test_fork1.py
(3.67 KB)
📄
test_format.py
(22.58 KB)
📄
test_fractions.py
(29.83 KB)
📄
test_frame.py
(5.67 KB)
📄
test_frozen.py
(943 B)
📄
test_fstring.py
(46.16 KB)
📄
test_ftplib.py
(39.71 KB)
📄
test_funcattrs.py
(13.54 KB)
📄
test_functools.py
(90.59 KB)
📄
test_future.py
(11.9 KB)
📄
test_future3.py
(490 B)
📄
test_future4.py
(222 B)
📄
test_future5.py
(510 B)
📄
test_gc.py
(40.49 KB)
📄
test_gdb.py
(40.88 KB)
📄
test_generator_stop.py
(943 B)
📄
test_generators.py
(58.51 KB)
📄
test_genericclass.py
(9.28 KB)
📄
test_genericpath.py
(21.7 KB)
📄
test_genexps.py
(7.12 KB)
📄
test_getargs2.py
(50 KB)
📄
test_getopt.py
(6.75 KB)
📄
test_getpass.py
(6.29 KB)
📄
test_gettext.py
(41.38 KB)
📄
test_glob.py
(13.03 KB)
📄
test_global.py
(1.31 KB)
📄
test_grammar.py
(57.5 KB)
📄
test_grp.py
(3.54 KB)
📄
test_gzip.py
(29.9 KB)
📄
test_hash.py
(11.45 KB)
📄
test_hashlib.py
(39.43 KB)
📄
test_heapq.py
(16.4 KB)
📄
test_hmac.py
(22.24 KB)
📄
test_html.py
(4.23 KB)
📄
test_htmlparser.py
(33.19 KB)
📄
test_http_cookiejar.py
(78.36 KB)
📄
test_http_cookies.py
(18.71 KB)
📄
test_httplib.py
(76.98 KB)
📄
test_httpservers.py
(45.24 KB)
📄
test_idle.py
(825 B)
📄
test_imaplib.py
(38.95 KB)
📄
test_imghdr.py
(4.66 KB)
📄
test_imp.py
(17.73 KB)
📁
test_import
📁
test_importlib
📄
test_index.py
(8.37 KB)
📄
test_inspect.py
(151.79 KB)
📄
test_int.py
(20.8 KB)
📄
test_int_literal.py
(6.89 KB)
📄
test_io.py
(163.94 KB)
📄
test_ioctl.py
(3.2 KB)
📄
test_ipaddress.py
(90.98 KB)
📄
test_isinstance.py
(10.25 KB)
📄
test_iter.py
(31.81 KB)
📄
test_iterlen.py
(7.1 KB)
📄
test_itertools.py
(101.41 KB)
📁
test_json
📄
test_keyword.py
(1.23 KB)
📄
test_keywordonlyarg.py
(6.85 KB)
📄
test_kqueue.py
(8.76 KB)
📄
test_largefile.py
(6.83 KB)
📄
test_lib2to3.py
(101 B)
📄
test_linecache.py
(7.79 KB)
📄
test_list.py
(7.4 KB)
📄
test_listcomps.py
(3.76 KB)
📄
test_lltrace.py
(1012 B)
📄
test_locale.py
(23.87 KB)
📄
test_logging.py
(182.43 KB)
📄
test_long.py
(53.21 KB)
📄
test_longexp.py
(233 B)
📄
test_lzma.py
(87.92 KB)
📄
test_mailbox.py
(91.92 KB)
📄
test_mailcap.py
(9.88 KB)
📄
test_marshal.py
(20.57 KB)
📄
test_math.py
(82.18 KB)
📄
test_memoryio.py
(31.48 KB)
📄
test_memoryview.py
(17.78 KB)
📄
test_metaclass.py
(6.2 KB)
📄
test_mimetypes.py
(12.14 KB)
📄
test_minidom.py
(66.95 KB)
📄
test_mmap.py
(29.04 KB)
📄
test_module.py
(10.3 KB)
📄
test_modulefinder.py
(12.2 KB)
📄
test_msilib.py
(5.06 KB)
📄
test_multibytecodec.py
(15.04 KB)
📄
test_multiprocessing_fork.py
(477 B)
📄
test_multiprocessing_forkserver.py
(392 B)
📄
test_multiprocessing_main_handling.py
(11.45 KB)
📄
test_multiprocessing_spawn.py
(277 B)
📄
test_named_expressions.py
(16.51 KB)
📄
test_netrc.py
(5.96 KB)
📄
test_nis.py
(1.13 KB)
📄
test_nntplib.py
(61.7 KB)
📄
test_normalization.py
(3.66 KB)
📄
test_ntpath.py
(35.08 KB)
📄
test_numeric_tower.py
(7.18 KB)
📄
test_opcodes.py
(3.61 KB)
📄
test_openpty.py
(600 B)
📄
test_operator.py
(23.54 KB)
📄
test_optparse.py
(60.99 KB)
📄
test_ordered_dict.py
(30.22 KB)
📄
test_os.py
(150.53 KB)
📄
test_ossaudiodev.py
(7.06 KB)
📄
test_osx_env.py
(1.3 KB)
📄
test_parser.py
(35.72 KB)
📄
test_pathlib.py
(97.12 KB)
📄
test_pdb.py
(55.36 KB)
📄
test_peepholer.py
(19.41 KB)
📄
test_pickle.py
(19.16 KB)
📄
test_picklebuffer.py
(4.96 KB)
📄
test_pickletools.py
(4.33 KB)
📄
test_pipes.py
(6.59 KB)
📄
test_pkg.py
(9.59 KB)
📄
test_pkgimport.py
(2.67 KB)
📄
test_pkgutil.py
(19.25 KB)
📄
test_platform.py
(14.31 KB)
📄
test_plistlib.py
(41.43 KB)
📄
test_poll.py
(7.23 KB)
📄
test_popen.py
(1.98 KB)
📄
test_poplib.py
(16.97 KB)
📄
test_positional_only_arg.py
(17.5 KB)
📄
test_posix.py
(75.76 KB)
📄
test_posixpath.py
(29.19 KB)
📄
test_pow.py
(5.44 KB)
📄
test_pprint.py
(43.85 KB)
📄
test_print.py
(7.37 KB)
📄
test_profile.py
(8.72 KB)
📄
test_property.py
(8.77 KB)
📄
test_pstats.py
(3.04 KB)
📄
test_pty.py
(11.97 KB)
📄
test_pulldom.py
(12.66 KB)
📄
test_pwd.py
(4.17 KB)
📄
test_py_compile.py
(10.78 KB)
📄
test_pyclbr.py
(10 KB)
📄
test_pydoc.py
(56.98 KB)
📄
test_pyexpat.py
(26.54 KB)
📄
test_queue.py
(20.36 KB)
📄
test_quopri.py
(7.78 KB)
📄
test_raise.py
(12.86 KB)
📄
test_random.py
(45.59 KB)
📄
test_range.py
(23.35 KB)
📄
test_re.py
(106.41 KB)
📄
test_readline.py
(12.95 KB)
📄
test_regrtest.py
(46.36 KB)
📄
test_repl.py
(3.96 KB)
📄
test_reprlib.py
(15.12 KB)
📄
test_resource.py
(7.02 KB)
📄
test_richcmp.py
(11.91 KB)
📄
test_rlcompleter.py
(6.3 KB)
📄
test_robotparser.py
(10.69 KB)
📄
test_runpy.py
(33.86 KB)
📄
test_sax.py
(46.9 KB)
📄
test_sched.py
(6.41 KB)
📄
test_scope.py
(19.7 KB)
📄
test_script_helper.py
(5.78 KB)
📄
test_secrets.py
(4.28 KB)
📄
test_select.py
(2.69 KB)
📄
test_selectors.py
(17.79 KB)
📄
test_set.py
(64.41 KB)
📄
test_setcomps.py
(3.7 KB)
📄
test_shelve.py
(6.24 KB)
📄
test_shlex.py
(13.29 KB)
📄
test_shutil.py
(101.55 KB)
📄
test_signal.py
(46.62 KB)
📄
test_site.py
(24.71 KB)
📄
test_slice.py
(8.25 KB)
📄
test_smtpd.py
(40.14 KB)
📄
test_smtplib.py
(56.51 KB)
📄
test_smtpnet.py
(2.87 KB)
📄
test_sndhdr.py
(1.43 KB)
📄
test_socket.py
(232.71 KB)
📄
test_socketserver.py
(17.7 KB)
📄
test_sort.py
(13.42 KB)
📄
test_source_encoding.py
(7.89 KB)
📄
test_spwd.py
(2.71 KB)
📄
test_sqlite.py
(948 B)
📄
test_ssl.py
(203.3 KB)
📄
test_startfile.py
(1.29 KB)
📄
test_stat.py
(8.3 KB)
📄
test_statistics.py
(106.5 KB)
📄
test_strftime.py
(7.54 KB)
📄
test_string.py
(19.8 KB)
📄
test_string_literals.py
(9.88 KB)
📄
test_stringprep.py
(3.04 KB)
📄
test_strptime.py
(34.42 KB)
📄
test_strtod.py
(20.06 KB)
📄
test_struct.py
(34.41 KB)
📄
test_structmembers.py
(4.7 KB)
📄
test_structseq.py
(3.87 KB)
📄
test_subclassinit.py
(8.12 KB)
📄
test_subprocess.py
(142.64 KB)
📄
test_sunau.py
(6.07 KB)
📄
test_sundry.py
(2.07 KB)
📄
test_super.py
(9.6 KB)
📄
test_support.py
(24.12 KB)
📄
test_symbol.py
(2.06 KB)
📄
test_symtable.py
(9.13 KB)
📄
test_syntax.py
(25.75 KB)
📄
test_sys.py
(55.24 KB)
📄
test_sys_setprofile.py
(12.31 KB)
📄
test_sys_settrace.py
(43.08 KB)
📄
test_sysconfig.py
(17.01 KB)
📄
test_syslog.py
(1.15 KB)
📄
test_tabnanny.py
(13.44 KB)
📄
test_tarfile.py
(98.31 KB)
📄
test_tcl.py
(30.74 KB)
📄
test_telnetlib.py
(12.7 KB)
📄
test_tempfile.py
(52.57 KB)
📄
test_textwrap.py
(38.84 KB)
📄
test_thread.py
(8.41 KB)
📄
test_threaded_import.py
(8.9 KB)
📄
test_threadedtempfile.py
(1.85 KB)
📄
test_threading.py
(47.52 KB)
📄
test_threading_local.py
(6.09 KB)
📄
test_threadsignals.py
(10.09 KB)
📄
test_time.py
(38.43 KB)
📄
test_timeit.py
(14.8 KB)
📄
test_timeout.py
(11.19 KB)
📄
test_tix.py
(756 B)
📄
test_tk.py
(362 B)
📄
test_tokenize.py
(63.18 KB)
📁
test_tools
📄
test_trace.py
(19.89 KB)
📄
test_traceback.py
(46.97 KB)
📄
test_tracemalloc.py
(37.41 KB)
📄
test_ttk_guionly.py
(746 B)
📄
test_ttk_textonly.py
(299 B)
📄
test_tuple.py
(18.85 KB)
📄
test_turtle.py
(12.79 KB)
📄
test_type_comments.py
(10.13 KB)
📄
test_typechecks.py
(2.55 KB)
📄
test_types.py
(58 KB)
📄
test_typing.py
(122.05 KB)
📄
test_ucn.py
(9.35 KB)
📄
test_unary.py
(1.63 KB)
📄
test_unicode.py
(129.94 KB)
📄
test_unicode_file.py
(5.74 KB)
📄
test_unicode_file_functions.py
(6.84 KB)
📄
test_unicode_identifiers.py
(891 B)
📄
test_unicodedata.py
(12.7 KB)
📄
test_unittest.py
(286 B)
📄
test_univnewlines.py
(3.83 KB)
📄
test_unpack.py
(3.01 KB)
📄
test_unpack_ex.py
(8.73 KB)
📄
test_urllib.py
(71.24 KB)
📄
test_urllib2.py
(76.95 KB)
📄
test_urllib2_localnet.py
(24.24 KB)
📄
test_urllib2net.py
(12.39 KB)
📄
test_urllib_response.py
(1.69 KB)
📄
test_urllibnet.py
(8.9 KB)
📄
test_urlparse.py
(64.87 KB)
📄
test_userdict.py
(7.64 KB)
📄
test_userlist.py
(1.97 KB)
📄
test_userstring.py
(2.4 KB)
📄
test_utf8_mode.py
(9.22 KB)
📄
test_utf8source.py
(1.15 KB)
📄
test_uu.py
(8.02 KB)
📄
test_uuid.py
(35.74 KB)
📄
test_venv.py
(20.46 KB)
📄
test_wait3.py
(1.16 KB)
📄
test_wait4.py
(1.15 KB)
📁
test_warnings
📄
test_wave.py
(6.57 KB)
📄
test_weakref.py
(69.47 KB)
📄
test_weakset.py
(15.03 KB)
📄
test_webbrowser.py
(10.47 KB)
📄
test_winconsoleio.py
(6.14 KB)
📄
test_winreg.py
(21.38 KB)
📄
test_winsound.py
(4.57 KB)
📄
test_with.py
(25.78 KB)
📄
test_wsgiref.py
(30.1 KB)
📄
test_xdrlib.py
(2.17 KB)
📄
test_xml_dom_minicompat.py
(4.18 KB)
📄
test_xml_etree.py
(147.87 KB)
📄
test_xml_etree_c.py
(8.06 KB)
📄
test_xmlrpc.py
(55.96 KB)
📄
test_xmlrpc_net.py
(1015 B)
📄
test_xxtestfuzz.py
(670 B)
📄
test_yield_from.py
(30.01 KB)
📄
test_zipapp.py
(15.92 KB)
📄
test_zipfile.py
(115.45 KB)
📄
test_zipfile64.py
(5.8 KB)
📄
test_zipimport.py
(29.28 KB)
📄
test_zipimport_support.py
(10.44 KB)
📄
test_zlib.py
(34.48 KB)
📄
testcodec.py
(1.02 KB)
📄
testtar.tar
(425 KB)
📄
tf_inherit_check.py
(714 B)
📄
threaded_import_hangers.py
(1.45 KB)
📄
time_hashlib.py
(2.87 KB)
📄
tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt
(443 B)
📄
tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt
(302 B)
📄
tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt
(421 B)
📄
tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt
(326 B)
📄
tokenize_tests.txt
(2.65 KB)
📁
tracedmodules
📄
win_console_handler.py
(1.38 KB)
📁
xmltestdata
📄
xmltests.py
(499 B)
📄
zip_cp437_header.zip
(270 B)
📄
zipdir.zip
(374 B)
📁
ziptestdata
Editing: test_urlparse.py
import sys import unicodedata import unittest import urllib.parse RFC1808_BASE = "http://a/b/c/d;p?q#f" RFC2396_BASE = "http://a/b/c/d;p?q" RFC3986_BASE = 'http://a/b/c/d;p?q' SIMPLE_BASE = 'http://a/b/c/d' # Each parse_qsl testcase is a two-tuple that contains # a string with the query and a list with the expected result. parse_qsl_test_cases = [ ("", []), ("&", []), ("&&", []), ("=", [('', '')]), ("=a", [('', 'a')]), ("a", [('a', '')]), ("a=", [('a', '')]), ("&a=b", [('a', 'b')]), ("a=a+b&b=b+c", [('a', 'a b'), ('b', 'b c')]), ("a=1&a=2", [('a', '1'), ('a', '2')]), (b"", []), (b"&", []), (b"&&", []), (b"=", [(b'', b'')]), (b"=a", [(b'', b'a')]), (b"a", [(b'a', b'')]), (b"a=", [(b'a', b'')]), (b"&a=b", [(b'a', b'b')]), (b"a=a+b&b=b+c", [(b'a', b'a b'), (b'b', b'b c')]), (b"a=1&a=2", [(b'a', b'1'), (b'a', b'2')]), (";a=b", [(';a', 'b')]), ("a=a+b;b=b+c", [('a', 'a b;b=b c')]), (b";a=b", [(b';a', b'b')]), (b"a=a+b;b=b+c", [(b'a', b'a b;b=b c')]), ] # Each parse_qs testcase is a two-tuple that contains # a string with the query and a dictionary with the expected result. parse_qs_test_cases = [ ("", {}), ("&", {}), ("&&", {}), ("=", {'': ['']}), ("=a", {'': ['a']}), ("a", {'a': ['']}), ("a=", {'a': ['']}), ("&a=b", {'a': ['b']}), ("a=a+b&b=b+c", {'a': ['a b'], 'b': ['b c']}), ("a=1&a=2", {'a': ['1', '2']}), (b"", {}), (b"&", {}), (b"&&", {}), (b"=", {b'': [b'']}), (b"=a", {b'': [b'a']}), (b"a", {b'a': [b'']}), (b"a=", {b'a': [b'']}), (b"&a=b", {b'a': [b'b']}), (b"a=a+b&b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), (b"a=1&a=2", {b'a': [b'1', b'2']}), (";a=b", {';a': ['b']}), ("a=a+b;b=b+c", {'a': ['a b;b=b c']}), (b";a=b", {b';a': [b'b']}), (b"a=a+b;b=b+c", {b'a':[ b'a b;b=b c']}), ] class UrlParseTestCase(unittest.TestCase): def checkRoundtrips(self, url, parsed, split): result = urllib.parse.urlparse(url) self.assertEqual(result, parsed) t = (result.scheme, result.netloc, result.path, result.params, result.query, result.fragment) self.assertEqual(t, parsed) # put it back together and it should be the same result2 = urllib.parse.urlunparse(result) self.assertEqual(result2, url) self.assertEqual(result2, result.geturl()) # the result of geturl() is a fixpoint; we can always parse it # again to get the same result: result3 = urllib.parse.urlparse(result.geturl()) self.assertEqual(result3.geturl(), result.geturl()) self.assertEqual(result3, result) self.assertEqual(result3.scheme, result.scheme) self.assertEqual(result3.netloc, result.netloc) self.assertEqual(result3.path, result.path) self.assertEqual(result3.params, result.params) self.assertEqual(result3.query, result.query) self.assertEqual(result3.fragment, result.fragment) self.assertEqual(result3.username, result.username) self.assertEqual(result3.password, result.password) self.assertEqual(result3.hostname, result.hostname) self.assertEqual(result3.port, result.port) # check the roundtrip using urlsplit() as well result = urllib.parse.urlsplit(url) self.assertEqual(result, split) t = (result.scheme, result.netloc, result.path, result.query, result.fragment) self.assertEqual(t, split) result2 = urllib.parse.urlunsplit(result) self.assertEqual(result2, url) self.assertEqual(result2, result.geturl()) # check the fixpoint property of re-parsing the result of geturl() result3 = urllib.parse.urlsplit(result.geturl()) self.assertEqual(result3.geturl(), result.geturl()) self.assertEqual(result3, result) self.assertEqual(result3.scheme, result.scheme) self.assertEqual(result3.netloc, result.netloc) self.assertEqual(result3.path, result.path) self.assertEqual(result3.query, result.query) self.assertEqual(result3.fragment, result.fragment) self.assertEqual(result3.username, result.username) self.assertEqual(result3.password, result.password) self.assertEqual(result3.hostname, result.hostname) self.assertEqual(result3.port, result.port) def test_qsl(self): for orig, expect in parse_qsl_test_cases: result = urllib.parse.parse_qsl(orig, keep_blank_values=True) self.assertEqual(result, expect, "Error parsing %r" % orig) expect_without_blanks = [v for v in expect if len(v[1])] result = urllib.parse.parse_qsl(orig, keep_blank_values=False) self.assertEqual(result, expect_without_blanks, "Error parsing %r" % orig) def test_qs(self): for orig, expect in parse_qs_test_cases: result = urllib.parse.parse_qs(orig, keep_blank_values=True) self.assertEqual(result, expect, "Error parsing %r" % orig) expect_without_blanks = {v: expect[v] for v in expect if len(expect[v][0])} result = urllib.parse.parse_qs(orig, keep_blank_values=False) self.assertEqual(result, expect_without_blanks, "Error parsing %r" % orig) def test_roundtrips(self): str_cases = [ ('file:///tmp/junk.txt', ('file', '', '/tmp/junk.txt', '', '', ''), ('file', '', '/tmp/junk.txt', '', '')), ('imap://mail.python.org/mbox1', ('imap', 'mail.python.org', '/mbox1', '', '', ''), ('imap', 'mail.python.org', '/mbox1', '', '')), ('mms://wms.sys.hinet.net/cts/Drama/09006251100.asf', ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', '', '', ''), ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf', '', '')), ('nfs://server/path/to/file.txt', ('nfs', 'server', '/path/to/file.txt', '', '', ''), ('nfs', 'server', '/path/to/file.txt', '', '')), ('svn+ssh://svn.zope.org/repos/main/ZConfig/trunk/', ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/', '', '', ''), ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/', '', '')), ('git+ssh://git@github.com/user/project.git', ('git+ssh', 'git@github.com','/user/project.git', '','',''), ('git+ssh', 'git@github.com','/user/project.git', '', '')), ] def _encode(t): return (t[0].encode('ascii'), tuple(x.encode('ascii') for x in t[1]), tuple(x.encode('ascii') for x in t[2])) bytes_cases = [_encode(x) for x in str_cases] for url, parsed, split in str_cases + bytes_cases: self.checkRoundtrips(url, parsed, split) def test_http_roundtrips(self): # urllib.parse.urlsplit treats 'http:' as an optimized special case, # so we test both 'http:' and 'https:' in all the following. # Three cheers for white box knowledge! str_cases = [ ('://www.python.org', ('www.python.org', '', '', '', ''), ('www.python.org', '', '', '')), ('://www.python.org#abc', ('www.python.org', '', '', '', 'abc'), ('www.python.org', '', '', 'abc')), ('://www.python.org?q=abc', ('www.python.org', '', '', 'q=abc', ''), ('www.python.org', '', 'q=abc', '')), ('://www.python.org/#abc', ('www.python.org', '/', '', '', 'abc'), ('www.python.org', '/', '', 'abc')), ('://a/b/c/d;p?q#f', ('a', '/b/c/d', 'p', 'q', 'f'), ('a', '/b/c/d;p', 'q', 'f')), ] def _encode(t): return (t[0].encode('ascii'), tuple(x.encode('ascii') for x in t[1]), tuple(x.encode('ascii') for x in t[2])) bytes_cases = [_encode(x) for x in str_cases] str_schemes = ('http', 'https') bytes_schemes = (b'http', b'https') str_tests = str_schemes, str_cases bytes_tests = bytes_schemes, bytes_cases for schemes, test_cases in (str_tests, bytes_tests): for scheme in schemes: for url, parsed, split in test_cases: url = scheme + url parsed = (scheme,) + parsed split = (scheme,) + split self.checkRoundtrips(url, parsed, split) def checkJoin(self, base, relurl, expected): str_components = (base, relurl, expected) self.assertEqual(urllib.parse.urljoin(base, relurl), expected) bytes_components = baseb, relurlb, expectedb = [ x.encode('ascii') for x in str_components] self.assertEqual(urllib.parse.urljoin(baseb, relurlb), expectedb) def test_unparse_parse(self): str_cases = ['Python', './Python','x-newscheme://foo.com/stuff','x://y','x:/y','x:/','/',] bytes_cases = [x.encode('ascii') for x in str_cases] for u in str_cases + bytes_cases: self.assertEqual(urllib.parse.urlunsplit(urllib.parse.urlsplit(u)), u) self.assertEqual(urllib.parse.urlunparse(urllib.parse.urlparse(u)), u) def test_RFC1808(self): # "normal" cases from RFC 1808: self.checkJoin(RFC1808_BASE, 'g:h', 'g:h') self.checkJoin(RFC1808_BASE, 'g', 'http://a/b/c/g') self.checkJoin(RFC1808_BASE, './g', 'http://a/b/c/g') self.checkJoin(RFC1808_BASE, 'g/', 'http://a/b/c/g/') self.checkJoin(RFC1808_BASE, '/g', 'http://a/g') self.checkJoin(RFC1808_BASE, '//g', 'http://g') self.checkJoin(RFC1808_BASE, 'g?y', 'http://a/b/c/g?y') self.checkJoin(RFC1808_BASE, 'g?y/./x', 'http://a/b/c/g?y/./x') self.checkJoin(RFC1808_BASE, '#s', 'http://a/b/c/d;p?q#s') self.checkJoin(RFC1808_BASE, 'g#s', 'http://a/b/c/g#s') self.checkJoin(RFC1808_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x') self.checkJoin(RFC1808_BASE, 'g?y#s', 'http://a/b/c/g?y#s') self.checkJoin(RFC1808_BASE, 'g;x', 'http://a/b/c/g;x') self.checkJoin(RFC1808_BASE, 'g;x?y#s', 'http://a/b/c/g;x?y#s') self.checkJoin(RFC1808_BASE, '.', 'http://a/b/c/') self.checkJoin(RFC1808_BASE, './', 'http://a/b/c/') self.checkJoin(RFC1808_BASE, '..', 'http://a/b/') self.checkJoin(RFC1808_BASE, '../', 'http://a/b/') self.checkJoin(RFC1808_BASE, '../g', 'http://a/b/g') self.checkJoin(RFC1808_BASE, '../..', 'http://a/') self.checkJoin(RFC1808_BASE, '../../', 'http://a/') self.checkJoin(RFC1808_BASE, '../../g', 'http://a/g') # "abnormal" cases from RFC 1808: self.checkJoin(RFC1808_BASE, '', 'http://a/b/c/d;p?q#f') self.checkJoin(RFC1808_BASE, 'g.', 'http://a/b/c/g.') self.checkJoin(RFC1808_BASE, '.g', 'http://a/b/c/.g') self.checkJoin(RFC1808_BASE, 'g..', 'http://a/b/c/g..') self.checkJoin(RFC1808_BASE, '..g', 'http://a/b/c/..g') self.checkJoin(RFC1808_BASE, './../g', 'http://a/b/g') self.checkJoin(RFC1808_BASE, './g/.', 'http://a/b/c/g/') self.checkJoin(RFC1808_BASE, 'g/./h', 'http://a/b/c/g/h') self.checkJoin(RFC1808_BASE, 'g/../h', 'http://a/b/c/h') # RFC 1808 and RFC 1630 disagree on these (according to RFC 1808), # so we'll not actually run these tests (which expect 1808 behavior). #self.checkJoin(RFC1808_BASE, 'http:g', 'http:g') #self.checkJoin(RFC1808_BASE, 'http:', 'http:') # XXX: The following tests are no longer compatible with RFC3986 # self.checkJoin(RFC1808_BASE, '../../../g', 'http://a/../g') # self.checkJoin(RFC1808_BASE, '../../../../g', 'http://a/../../g') # self.checkJoin(RFC1808_BASE, '/./g', 'http://a/./g') # self.checkJoin(RFC1808_BASE, '/../g', 'http://a/../g') def test_RFC2368(self): # Issue 11467: path that starts with a number is not parsed correctly self.assertEqual(urllib.parse.urlparse('mailto:1337@example.org'), ('mailto', '', '1337@example.org', '', '', '')) def test_RFC2396(self): # cases from RFC 2396 self.checkJoin(RFC2396_BASE, 'g:h', 'g:h') self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g') self.checkJoin(RFC2396_BASE, './g', 'http://a/b/c/g') self.checkJoin(RFC2396_BASE, 'g/', 'http://a/b/c/g/') self.checkJoin(RFC2396_BASE, '/g', 'http://a/g') self.checkJoin(RFC2396_BASE, '//g', 'http://g') self.checkJoin(RFC2396_BASE, 'g?y', 'http://a/b/c/g?y') self.checkJoin(RFC2396_BASE, '#s', 'http://a/b/c/d;p?q#s') self.checkJoin(RFC2396_BASE, 'g#s', 'http://a/b/c/g#s') self.checkJoin(RFC2396_BASE, 'g?y#s', 'http://a/b/c/g?y#s') self.checkJoin(RFC2396_BASE, 'g;x', 'http://a/b/c/g;x') self.checkJoin(RFC2396_BASE, 'g;x?y#s', 'http://a/b/c/g;x?y#s') self.checkJoin(RFC2396_BASE, '.', 'http://a/b/c/') self.checkJoin(RFC2396_BASE, './', 'http://a/b/c/') self.checkJoin(RFC2396_BASE, '..', 'http://a/b/') self.checkJoin(RFC2396_BASE, '../', 'http://a/b/') self.checkJoin(RFC2396_BASE, '../g', 'http://a/b/g') self.checkJoin(RFC2396_BASE, '../..', 'http://a/') self.checkJoin(RFC2396_BASE, '../../', 'http://a/') self.checkJoin(RFC2396_BASE, '../../g', 'http://a/g') self.checkJoin(RFC2396_BASE, '', RFC2396_BASE) self.checkJoin(RFC2396_BASE, 'g.', 'http://a/b/c/g.') self.checkJoin(RFC2396_BASE, '.g', 'http://a/b/c/.g') self.checkJoin(RFC2396_BASE, 'g..', 'http://a/b/c/g..') self.checkJoin(RFC2396_BASE, '..g', 'http://a/b/c/..g') self.checkJoin(RFC2396_BASE, './../g', 'http://a/b/g') self.checkJoin(RFC2396_BASE, './g/.', 'http://a/b/c/g/') self.checkJoin(RFC2396_BASE, 'g/./h', 'http://a/b/c/g/h') self.checkJoin(RFC2396_BASE, 'g/../h', 'http://a/b/c/h') self.checkJoin(RFC2396_BASE, 'g;x=1/./y', 'http://a/b/c/g;x=1/y') self.checkJoin(RFC2396_BASE, 'g;x=1/../y', 'http://a/b/c/y') self.checkJoin(RFC2396_BASE, 'g?y/./x', 'http://a/b/c/g?y/./x') self.checkJoin(RFC2396_BASE, 'g?y/../x', 'http://a/b/c/g?y/../x') self.checkJoin(RFC2396_BASE, 'g#s/./x', 'http://a/b/c/g#s/./x') self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x') # XXX: The following tests are no longer compatible with RFC3986 # self.checkJoin(RFC2396_BASE, '../../../g', 'http://a/../g') # self.checkJoin(RFC2396_BASE, '../../../../g', 'http://a/../../g') # self.checkJoin(RFC2396_BASE, '/./g', 'http://a/./g') # self.checkJoin(RFC2396_BASE, '/../g', 'http://a/../g') def test_RFC3986(self): self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y') self.checkJoin(RFC3986_BASE, ';x', 'http://a/b/c/;x') self.checkJoin(RFC3986_BASE, 'g:h','g:h') self.checkJoin(RFC3986_BASE, 'g','http://a/b/c/g') self.checkJoin(RFC3986_BASE, './g','http://a/b/c/g') self.checkJoin(RFC3986_BASE, 'g/','http://a/b/c/g/') self.checkJoin(RFC3986_BASE, '/g','http://a/g') self.checkJoin(RFC3986_BASE, '//g','http://g') self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y') self.checkJoin(RFC3986_BASE, 'g?y','http://a/b/c/g?y') self.checkJoin(RFC3986_BASE, '#s','http://a/b/c/d;p?q#s') self.checkJoin(RFC3986_BASE, 'g#s','http://a/b/c/g#s') self.checkJoin(RFC3986_BASE, 'g?y#s','http://a/b/c/g?y#s') self.checkJoin(RFC3986_BASE, ';x','http://a/b/c/;x') self.checkJoin(RFC3986_BASE, 'g;x','http://a/b/c/g;x') self.checkJoin(RFC3986_BASE, 'g;x?y#s','http://a/b/c/g;x?y#s') self.checkJoin(RFC3986_BASE, '','http://a/b/c/d;p?q') self.checkJoin(RFC3986_BASE, '.','http://a/b/c/') self.checkJoin(RFC3986_BASE, './','http://a/b/c/') self.checkJoin(RFC3986_BASE, '..','http://a/b/') self.checkJoin(RFC3986_BASE, '../','http://a/b/') self.checkJoin(RFC3986_BASE, '../g','http://a/b/g') self.checkJoin(RFC3986_BASE, '../..','http://a/') self.checkJoin(RFC3986_BASE, '../../','http://a/') self.checkJoin(RFC3986_BASE, '../../g','http://a/g') self.checkJoin(RFC3986_BASE, '../../../g', 'http://a/g') # Abnormal Examples # The 'abnormal scenarios' are incompatible with RFC2986 parsing # Tests are here for reference. self.checkJoin(RFC3986_BASE, '../../../g','http://a/g') self.checkJoin(RFC3986_BASE, '../../../../g','http://a/g') self.checkJoin(RFC3986_BASE, '/./g','http://a/g') self.checkJoin(RFC3986_BASE, '/../g','http://a/g') self.checkJoin(RFC3986_BASE, 'g.','http://a/b/c/g.') self.checkJoin(RFC3986_BASE, '.g','http://a/b/c/.g') self.checkJoin(RFC3986_BASE, 'g..','http://a/b/c/g..') self.checkJoin(RFC3986_BASE, '..g','http://a/b/c/..g') self.checkJoin(RFC3986_BASE, './../g','http://a/b/g') self.checkJoin(RFC3986_BASE, './g/.','http://a/b/c/g/') self.checkJoin(RFC3986_BASE, 'g/./h','http://a/b/c/g/h') self.checkJoin(RFC3986_BASE, 'g/../h','http://a/b/c/h') self.checkJoin(RFC3986_BASE, 'g;x=1/./y','http://a/b/c/g;x=1/y') self.checkJoin(RFC3986_BASE, 'g;x=1/../y','http://a/b/c/y') self.checkJoin(RFC3986_BASE, 'g?y/./x','http://a/b/c/g?y/./x') self.checkJoin(RFC3986_BASE, 'g?y/../x','http://a/b/c/g?y/../x') self.checkJoin(RFC3986_BASE, 'g#s/./x','http://a/b/c/g#s/./x') self.checkJoin(RFC3986_BASE, 'g#s/../x','http://a/b/c/g#s/../x') #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') #relaxed parser # Test for issue9721 self.checkJoin('http://a/b/c/de', ';x','http://a/b/c/;x') def test_urljoins(self): self.checkJoin(SIMPLE_BASE, 'g:h','g:h') self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g') self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d') self.checkJoin(SIMPLE_BASE, 'g','http://a/b/c/g') self.checkJoin(SIMPLE_BASE, './g','http://a/b/c/g') self.checkJoin(SIMPLE_BASE, 'g/','http://a/b/c/g/') self.checkJoin(SIMPLE_BASE, '/g','http://a/g') self.checkJoin(SIMPLE_BASE, '//g','http://g') self.checkJoin(SIMPLE_BASE, '?y','http://a/b/c/d?y') self.checkJoin(SIMPLE_BASE, 'g?y','http://a/b/c/g?y') self.checkJoin(SIMPLE_BASE, 'g?y/./x','http://a/b/c/g?y/./x') self.checkJoin(SIMPLE_BASE, '.','http://a/b/c/') self.checkJoin(SIMPLE_BASE, './','http://a/b/c/') self.checkJoin(SIMPLE_BASE, '..','http://a/b/') self.checkJoin(SIMPLE_BASE, '../','http://a/b/') self.checkJoin(SIMPLE_BASE, '../g','http://a/b/g') self.checkJoin(SIMPLE_BASE, '../..','http://a/') self.checkJoin(SIMPLE_BASE, '../../g','http://a/g') self.checkJoin(SIMPLE_BASE, './../g','http://a/b/g') self.checkJoin(SIMPLE_BASE, './g/.','http://a/b/c/g/') self.checkJoin(SIMPLE_BASE, 'g/./h','http://a/b/c/g/h') self.checkJoin(SIMPLE_BASE, 'g/../h','http://a/b/c/h') self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g') self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d') self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y') self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y') self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x') self.checkJoin('http:///', '..','http:///') self.checkJoin('', 'http://a/b/c/g?y/./x','http://a/b/c/g?y/./x') self.checkJoin('', 'http://a/./g', 'http://a/./g') self.checkJoin('svn://pathtorepo/dir1', 'dir2', 'svn://pathtorepo/dir2') self.checkJoin('svn+ssh://pathtorepo/dir1', 'dir2', 'svn+ssh://pathtorepo/dir2') self.checkJoin('ws://a/b','g','ws://a/g') self.checkJoin('wss://a/b','g','wss://a/g') # XXX: The following tests are no longer compatible with RFC3986 # self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g') # self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g') # test for issue22118 duplicate slashes self.checkJoin(SIMPLE_BASE + '/', 'foo', SIMPLE_BASE + '/foo') # Non-RFC-defined tests, covering variations of base and trailing # slashes self.checkJoin('http://a/b/c/d/e/', '../../f/g/', 'http://a/b/c/f/g/') self.checkJoin('http://a/b/c/d/e', '../../f/g/', 'http://a/b/f/g/') self.checkJoin('http://a/b/c/d/e/', '/../../f/g/', 'http://a/f/g/') self.checkJoin('http://a/b/c/d/e', '/../../f/g/', 'http://a/f/g/') self.checkJoin('http://a/b/c/d/e/', '../../f/g', 'http://a/b/c/f/g') self.checkJoin('http://a/b/', '../../f/g/', 'http://a/f/g/') # issue 23703: don't duplicate filename self.checkJoin('a', 'b', 'b') def test_RFC2732(self): str_cases = [ ('http://Test.python.org:5432/foo/', 'test.python.org', 5432), ('http://12.34.56.78:5432/foo/', '12.34.56.78', 5432), ('http://[::1]:5432/foo/', '::1', 5432), ('http://[dead:beef::1]:5432/foo/', 'dead:beef::1', 5432), ('http://[dead:beef::]:5432/foo/', 'dead:beef::', 5432), ('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]:5432/foo/', 'dead:beef:cafe:5417:affe:8fa3:deaf:feed', 5432), ('http://[::12.34.56.78]:5432/foo/', '::12.34.56.78', 5432), ('http://[::ffff:12.34.56.78]:5432/foo/', '::ffff:12.34.56.78', 5432), ('http://Test.python.org/foo/', 'test.python.org', None), ('http://12.34.56.78/foo/', '12.34.56.78', None), ('http://[::1]/foo/', '::1', None), ('http://[dead:beef::1]/foo/', 'dead:beef::1', None), ('http://[dead:beef::]/foo/', 'dead:beef::', None), ('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/', 'dead:beef:cafe:5417:affe:8fa3:deaf:feed', None), ('http://[::12.34.56.78]/foo/', '::12.34.56.78', None), ('http://[::ffff:12.34.56.78]/foo/', '::ffff:12.34.56.78', None), ('http://Test.python.org:/foo/', 'test.python.org', None), ('http://12.34.56.78:/foo/', '12.34.56.78', None), ('http://[::1]:/foo/', '::1', None), ('http://[dead:beef::1]:/foo/', 'dead:beef::1', None), ('http://[dead:beef::]:/foo/', 'dead:beef::', None), ('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]:/foo/', 'dead:beef:cafe:5417:affe:8fa3:deaf:feed', None), ('http://[::12.34.56.78]:/foo/', '::12.34.56.78', None), ('http://[::ffff:12.34.56.78]:/foo/', '::ffff:12.34.56.78', None), ] def _encode(t): return t[0].encode('ascii'), t[1].encode('ascii'), t[2] bytes_cases = [_encode(x) for x in str_cases] for url, hostname, port in str_cases + bytes_cases: urlparsed = urllib.parse.urlparse(url) self.assertEqual((urlparsed.hostname, urlparsed.port) , (hostname, port)) str_cases = [ 'http://::12.34.56.78]/', 'http://[::1/foo/', 'ftp://[::1/foo/bad]/bad', 'http://[::1/foo/bad]/bad', 'http://[::ffff:12.34.56.78'] bytes_cases = [x.encode('ascii') for x in str_cases] for invalid_url in str_cases + bytes_cases: self.assertRaises(ValueError, urllib.parse.urlparse, invalid_url) def test_urldefrag(self): str_cases = [ ('http://python.org#frag', 'http://python.org', 'frag'), ('http://python.org', 'http://python.org', ''), ('http://python.org/#frag', 'http://python.org/', 'frag'), ('http://python.org/', 'http://python.org/', ''), ('http://python.org/?q#frag', 'http://python.org/?q', 'frag'), ('http://python.org/?q', 'http://python.org/?q', ''), ('http://python.org/p#frag', 'http://python.org/p', 'frag'), ('http://python.org/p?q', 'http://python.org/p?q', ''), (RFC1808_BASE, 'http://a/b/c/d;p?q', 'f'), (RFC2396_BASE, 'http://a/b/c/d;p?q', ''), ] def _encode(t): return type(t)(x.encode('ascii') for x in t) bytes_cases = [_encode(x) for x in str_cases] for url, defrag, frag in str_cases + bytes_cases: result = urllib.parse.urldefrag(url) self.assertEqual(result.geturl(), url) self.assertEqual(result, (defrag, frag)) self.assertEqual(result.url, defrag) self.assertEqual(result.fragment, frag) def test_urlsplit_scoped_IPv6(self): p = urllib.parse.urlsplit('http://[FE80::822a:a8ff:fe49:470c%tESt]:1234') self.assertEqual(p.hostname, "fe80::822a:a8ff:fe49:470c%tESt") self.assertEqual(p.netloc, '[FE80::822a:a8ff:fe49:470c%tESt]:1234') p = urllib.parse.urlsplit(b'http://[FE80::822a:a8ff:fe49:470c%tESt]:1234') self.assertEqual(p.hostname, b"fe80::822a:a8ff:fe49:470c%tESt") self.assertEqual(p.netloc, b'[FE80::822a:a8ff:fe49:470c%tESt]:1234') def test_urlsplit_attributes(self): url = "HTTP://WWW.PYTHON.ORG/doc/#frag" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, "http") self.assertEqual(p.netloc, "WWW.PYTHON.ORG") self.assertEqual(p.path, "/doc/") self.assertEqual(p.query, "") self.assertEqual(p.fragment, "frag") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, "www.python.org") self.assertEqual(p.port, None) # geturl() won't return exactly the original URL in this case # since the scheme is always case-normalized # We handle this by ignoring the first 4 characters of the URL self.assertEqual(p.geturl()[4:], url[4:]) url = "http://User:Pass@www.python.org:080/doc/?query=yes#frag" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, "http") self.assertEqual(p.netloc, "User:Pass@www.python.org:080") self.assertEqual(p.path, "/doc/") self.assertEqual(p.query, "query=yes") self.assertEqual(p.fragment, "frag") self.assertEqual(p.username, "User") self.assertEqual(p.password, "Pass") self.assertEqual(p.hostname, "www.python.org") self.assertEqual(p.port, 80) self.assertEqual(p.geturl(), url) # Addressing issue1698, which suggests Username can contain # "@" characters. Though not RFC compliant, many ftp sites allow # and request email addresses as usernames. url = "http://User@example.com:Pass@www.python.org:080/doc/?query=yes#frag" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, "http") self.assertEqual(p.netloc, "User@example.com:Pass@www.python.org:080") self.assertEqual(p.path, "/doc/") self.assertEqual(p.query, "query=yes") self.assertEqual(p.fragment, "frag") self.assertEqual(p.username, "User@example.com") self.assertEqual(p.password, "Pass") self.assertEqual(p.hostname, "www.python.org") self.assertEqual(p.port, 80) self.assertEqual(p.geturl(), url) # And check them all again, only with bytes this time url = b"HTTP://WWW.PYTHON.ORG/doc/#frag" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, b"http") self.assertEqual(p.netloc, b"WWW.PYTHON.ORG") self.assertEqual(p.path, b"/doc/") self.assertEqual(p.query, b"") self.assertEqual(p.fragment, b"frag") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, b"www.python.org") self.assertEqual(p.port, None) self.assertEqual(p.geturl()[4:], url[4:]) url = b"http://User:Pass@www.python.org:080/doc/?query=yes#frag" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, b"http") self.assertEqual(p.netloc, b"User:Pass@www.python.org:080") self.assertEqual(p.path, b"/doc/") self.assertEqual(p.query, b"query=yes") self.assertEqual(p.fragment, b"frag") self.assertEqual(p.username, b"User") self.assertEqual(p.password, b"Pass") self.assertEqual(p.hostname, b"www.python.org") self.assertEqual(p.port, 80) self.assertEqual(p.geturl(), url) url = b"http://User@example.com:Pass@www.python.org:080/doc/?query=yes#frag" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, b"http") self.assertEqual(p.netloc, b"User@example.com:Pass@www.python.org:080") self.assertEqual(p.path, b"/doc/") self.assertEqual(p.query, b"query=yes") self.assertEqual(p.fragment, b"frag") self.assertEqual(p.username, b"User@example.com") self.assertEqual(p.password, b"Pass") self.assertEqual(p.hostname, b"www.python.org") self.assertEqual(p.port, 80) self.assertEqual(p.geturl(), url) # Verify an illegal port raises ValueError url = b"HTTP://WWW.PYTHON.ORG:65536/doc/#frag" p = urllib.parse.urlsplit(url) with self.assertRaisesRegex(ValueError, "out of range"): p.port def test_urlsplit_remove_unsafe_bytes(self): # Remove ASCII tabs and newlines from input, for http common case scenario. url = "h\nttp://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, "http") self.assertEqual(p.netloc, "www.python.org") self.assertEqual(p.path, "/javascript:alert('msg')/") self.assertEqual(p.query, "query=something") self.assertEqual(p.fragment, "fragment") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, "www.python.org") self.assertEqual(p.port, None) self.assertEqual(p.geturl(), "http://www.python.org/javascript:alert('msg')/?query=something#fragment") # Remove ASCII tabs and newlines from input as bytes, for http common case scenario. url = b"h\nttp://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" p = urllib.parse.urlsplit(url) self.assertEqual(p.scheme, b"http") self.assertEqual(p.netloc, b"www.python.org") self.assertEqual(p.path, b"/javascript:alert('msg')/") self.assertEqual(p.query, b"query=something") self.assertEqual(p.fragment, b"fragment") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, b"www.python.org") self.assertEqual(p.port, None) self.assertEqual(p.geturl(), b"http://www.python.org/javascript:alert('msg')/?query=something#fragment") # any scheme url = "x-new-scheme\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" p = urllib.parse.urlsplit(url) self.assertEqual(p.geturl(), "x-new-scheme://www.python.org/javascript:alert('msg')/?query=something#fragment") # Remove ASCII tabs and newlines from input as bytes, any scheme. url = b"x-new-scheme\t://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" p = urllib.parse.urlsplit(url) self.assertEqual(p.geturl(), b"x-new-scheme://www.python.org/javascript:alert('msg')/?query=something#fragment") # Unsafe bytes is not returned from urlparse cache. # scheme is stored after parsing, sending an scheme with unsafe bytes *will not* return an unsafe scheme url = "https://www.python\n.org\t/java\nscript:\talert('msg\r\n')/?query\n=\tsomething#frag\nment" scheme = "htt\nps" for _ in range(2): p = urllib.parse.urlsplit(url, scheme=scheme) self.assertEqual(p.scheme, "https") self.assertEqual(p.geturl(), "https://www.python.org/javascript:alert('msg')/?query=something#fragment") def test_attributes_bad_port(self): """Check handling of invalid ports.""" for bytes in (False, True): for parse in (urllib.parse.urlsplit, urllib.parse.urlparse): for port in ("foo", "1.5", "-1", "0x10"): with self.subTest(bytes=bytes, parse=parse, port=port): netloc = "www.example.net:" + port url = "http://" + netloc if bytes: netloc = netloc.encode("ascii") url = url.encode("ascii") p = parse(url) self.assertEqual(p.netloc, netloc) with self.assertRaises(ValueError): p.port def test_attributes_without_netloc(self): # This example is straight from RFC 3261. It looks like it # should allow the username, hostname, and port to be filled # in, but doesn't. Since it's a URI and doesn't use the # scheme://netloc syntax, the netloc and related attributes # should be left empty. uri = "sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15" p = urllib.parse.urlsplit(uri) self.assertEqual(p.netloc, "") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, None) self.assertEqual(p.port, None) self.assertEqual(p.geturl(), uri) p = urllib.parse.urlparse(uri) self.assertEqual(p.netloc, "") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, None) self.assertEqual(p.port, None) self.assertEqual(p.geturl(), uri) # You guessed it, repeating the test with bytes input uri = b"sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15" p = urllib.parse.urlsplit(uri) self.assertEqual(p.netloc, b"") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, None) self.assertEqual(p.port, None) self.assertEqual(p.geturl(), uri) p = urllib.parse.urlparse(uri) self.assertEqual(p.netloc, b"") self.assertEqual(p.username, None) self.assertEqual(p.password, None) self.assertEqual(p.hostname, None) self.assertEqual(p.port, None) self.assertEqual(p.geturl(), uri) def test_noslash(self): # Issue 1637: http://foo.com?query is legal self.assertEqual(urllib.parse.urlparse("http://example.com?blahblah=/foo"), ('http', 'example.com', '', '', 'blahblah=/foo', '')) self.assertEqual(urllib.parse.urlparse(b"http://example.com?blahblah=/foo"), (b'http', b'example.com', b'', b'', b'blahblah=/foo', b'')) def test_withoutscheme(self): # Test urlparse without scheme # Issue 754016: urlparse goes wrong with IP:port without scheme # RFC 1808 specifies that netloc should start with //, urlparse expects # the same, otherwise it classifies the portion of url as path. self.assertEqual(urllib.parse.urlparse("path"), ('','','path','','','')) self.assertEqual(urllib.parse.urlparse("//www.python.org:80"), ('','www.python.org:80','','','','')) self.assertEqual(urllib.parse.urlparse("http://www.python.org:80"), ('http','www.python.org:80','','','','')) # Repeat for bytes input self.assertEqual(urllib.parse.urlparse(b"path"), (b'',b'',b'path',b'',b'',b'')) self.assertEqual(urllib.parse.urlparse(b"//www.python.org:80"), (b'',b'www.python.org:80',b'',b'',b'',b'')) self.assertEqual(urllib.parse.urlparse(b"http://www.python.org:80"), (b'http',b'www.python.org:80',b'',b'',b'',b'')) def test_portseparator(self): # Issue 754016 makes changes for port separator ':' from scheme separator self.assertEqual(urllib.parse.urlparse("path:80"), ('','','path:80','','','')) self.assertEqual(urllib.parse.urlparse("http:"),('http','','','','','')) self.assertEqual(urllib.parse.urlparse("https:"),('https','','','','','')) self.assertEqual(urllib.parse.urlparse("http://www.python.org:80"), ('http','www.python.org:80','','','','')) # As usual, need to check bytes input as well self.assertEqual(urllib.parse.urlparse(b"path:80"), (b'',b'',b'path:80',b'',b'',b'')) self.assertEqual(urllib.parse.urlparse(b"http:"),(b'http',b'',b'',b'',b'',b'')) self.assertEqual(urllib.parse.urlparse(b"https:"),(b'https',b'',b'',b'',b'',b'')) self.assertEqual(urllib.parse.urlparse(b"http://www.python.org:80"), (b'http',b'www.python.org:80',b'',b'',b'',b'')) def test_usingsys(self): # Issue 3314: sys module is used in the error self.assertRaises(TypeError, urllib.parse.urlencode, "foo") def test_anyscheme(self): # Issue 7904: s3://foo.com/stuff has netloc "foo.com". self.assertEqual(urllib.parse.urlparse("s3://foo.com/stuff"), ('s3', 'foo.com', '/stuff', '', '', '')) self.assertEqual(urllib.parse.urlparse("x-newscheme://foo.com/stuff"), ('x-newscheme', 'foo.com', '/stuff', '', '', '')) self.assertEqual(urllib.parse.urlparse("x-newscheme://foo.com/stuff?query#fragment"), ('x-newscheme', 'foo.com', '/stuff', '', 'query', 'fragment')) self.assertEqual(urllib.parse.urlparse("x-newscheme://foo.com/stuff?query"), ('x-newscheme', 'foo.com', '/stuff', '', 'query', '')) # And for bytes... self.assertEqual(urllib.parse.urlparse(b"s3://foo.com/stuff"), (b's3', b'foo.com', b'/stuff', b'', b'', b'')) self.assertEqual(urllib.parse.urlparse(b"x-newscheme://foo.com/stuff"), (b'x-newscheme', b'foo.com', b'/stuff', b'', b'', b'')) self.assertEqual(urllib.parse.urlparse(b"x-newscheme://foo.com/stuff?query#fragment"), (b'x-newscheme', b'foo.com', b'/stuff', b'', b'query', b'fragment')) self.assertEqual(urllib.parse.urlparse(b"x-newscheme://foo.com/stuff?query"), (b'x-newscheme', b'foo.com', b'/stuff', b'', b'query', b'')) def test_default_scheme(self): # Exercise the scheme parameter of urlparse() and urlsplit() for func in (urllib.parse.urlparse, urllib.parse.urlsplit): with self.subTest(function=func): result = func("http://example.net/", "ftp") self.assertEqual(result.scheme, "http") result = func(b"http://example.net/", b"ftp") self.assertEqual(result.scheme, b"http") self.assertEqual(func("path", "ftp").scheme, "ftp") self.assertEqual(func("path", scheme="ftp").scheme, "ftp") self.assertEqual(func(b"path", scheme=b"ftp").scheme, b"ftp") self.assertEqual(func("path").scheme, "") self.assertEqual(func(b"path").scheme, b"") self.assertEqual(func(b"path", "").scheme, b"") def test_parse_fragments(self): # Exercise the allow_fragments parameter of urlparse() and urlsplit() tests = ( ("http:#frag", "path", "frag"), ("//example.net#frag", "path", "frag"), ("index.html#frag", "path", "frag"), (";a=b#frag", "params", "frag"), ("?a=b#frag", "query", "frag"), ("#frag", "path", "frag"), ("abc#@frag", "path", "@frag"), ("//abc#@frag", "path", "@frag"), ("//abc:80#@frag", "path", "@frag"), ("//abc#@frag:80", "path", "@frag:80"), ) for url, attr, expected_frag in tests: for func in (urllib.parse.urlparse, urllib.parse.urlsplit): if attr == "params" and func is urllib.parse.urlsplit: attr = "path" with self.subTest(url=url, function=func): result = func(url, allow_fragments=False) self.assertEqual(result.fragment, "") self.assertTrue( getattr(result, attr).endswith("#" + expected_frag)) self.assertEqual(func(url, "", False).fragment, "") result = func(url, allow_fragments=True) self.assertEqual(result.fragment, expected_frag) self.assertFalse( getattr(result, attr).endswith(expected_frag)) self.assertEqual(func(url, "", True).fragment, expected_frag) self.assertEqual(func(url).fragment, expected_frag) def test_mixed_types_rejected(self): # Several functions that process either strings or ASCII encoded bytes # accept multiple arguments. Check they reject mixed type input with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlparse("www.python.org", b"http") with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlparse(b"www.python.org", "http") with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlsplit("www.python.org", b"http") with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlsplit(b"www.python.org", "http") with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlunparse(( b"http", "www.python.org","","","","")) with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlunparse(("http", b"www.python.org","","","","")) with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlunsplit((b"http", "www.python.org","","","")) with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urlunsplit(("http", b"www.python.org","","","")) with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urljoin("http://python.org", b"http://python.org") with self.assertRaisesRegex(TypeError, "Cannot mix str"): urllib.parse.urljoin(b"http://python.org", "http://python.org") def _check_result_type(self, str_type): num_args = len(str_type._fields) bytes_type = str_type._encoded_counterpart self.assertIs(bytes_type._decoded_counterpart, str_type) str_args = ('',) * num_args bytes_args = (b'',) * num_args str_result = str_type(*str_args) bytes_result = bytes_type(*bytes_args) encoding = 'ascii' errors = 'strict' self.assertEqual(str_result, str_args) self.assertEqual(bytes_result.decode(), str_args) self.assertEqual(bytes_result.decode(), str_result) self.assertEqual(bytes_result.decode(encoding), str_args) self.assertEqual(bytes_result.decode(encoding), str_result) self.assertEqual(bytes_result.decode(encoding, errors), str_args) self.assertEqual(bytes_result.decode(encoding, errors), str_result) self.assertEqual(bytes_result, bytes_args) self.assertEqual(str_result.encode(), bytes_args) self.assertEqual(str_result.encode(), bytes_result) self.assertEqual(str_result.encode(encoding), bytes_args) self.assertEqual(str_result.encode(encoding), bytes_result) self.assertEqual(str_result.encode(encoding, errors), bytes_args) self.assertEqual(str_result.encode(encoding, errors), bytes_result) def test_result_pairs(self): # Check encoding and decoding between result pairs result_types = [ urllib.parse.DefragResult, urllib.parse.SplitResult, urllib.parse.ParseResult, ] for result_type in result_types: self._check_result_type(result_type) def test_parse_qs_encoding(self): result = urllib.parse.parse_qs("key=\u0141%E9", encoding="latin-1") self.assertEqual(result, {'key': ['\u0141\xE9']}) result = urllib.parse.parse_qs("key=\u0141%C3%A9", encoding="utf-8") self.assertEqual(result, {'key': ['\u0141\xE9']}) result = urllib.parse.parse_qs("key=\u0141%C3%A9", encoding="ascii") self.assertEqual(result, {'key': ['\u0141\ufffd\ufffd']}) result = urllib.parse.parse_qs("key=\u0141%E9-", encoding="ascii") self.assertEqual(result, {'key': ['\u0141\ufffd-']}) result = urllib.parse.parse_qs("key=\u0141%E9-", encoding="ascii", errors="ignore") self.assertEqual(result, {'key': ['\u0141-']}) def test_parse_qsl_encoding(self): result = urllib.parse.parse_qsl("key=\u0141%E9", encoding="latin-1") self.assertEqual(result, [('key', '\u0141\xE9')]) result = urllib.parse.parse_qsl("key=\u0141%C3%A9", encoding="utf-8") self.assertEqual(result, [('key', '\u0141\xE9')]) result = urllib.parse.parse_qsl("key=\u0141%C3%A9", encoding="ascii") self.assertEqual(result, [('key', '\u0141\ufffd\ufffd')]) result = urllib.parse.parse_qsl("key=\u0141%E9-", encoding="ascii") self.assertEqual(result, [('key', '\u0141\ufffd-')]) result = urllib.parse.parse_qsl("key=\u0141%E9-", encoding="ascii", errors="ignore") self.assertEqual(result, [('key', '\u0141-')]) def test_parse_qsl_max_num_fields(self): with self.assertRaises(ValueError): urllib.parse.parse_qs('&'.join(['a=a']*11), max_num_fields=10) urllib.parse.parse_qs('&'.join(['a=a']*10), max_num_fields=10) def test_parse_qs_separator(self): parse_qs_semicolon_cases = [ (";", {}), (";;", {}), (";a=b", {'a': ['b']}), ("a=a+b;b=b+c", {'a': ['a b'], 'b': ['b c']}), ("a=1;a=2", {'a': ['1', '2']}), (b";", {}), (b";;", {}), (b";a=b", {b'a': [b'b']}), (b"a=a+b;b=b+c", {b'a': [b'a b'], b'b': [b'b c']}), (b"a=1;a=2", {b'a': [b'1', b'2']}), ] for orig, expect in parse_qs_semicolon_cases: with self.subTest(f"Original: {orig!r}, Expected: {expect!r}"): result = urllib.parse.parse_qs(orig, separator=';') self.assertEqual(result, expect, "Error parsing %r" % orig) result_bytes = urllib.parse.parse_qs(orig, separator=b';') self.assertEqual(result_bytes, expect, "Error parsing %r" % orig) def test_parse_qsl_separator(self): parse_qsl_semicolon_cases = [ (";", []), (";;", []), (";a=b", [('a', 'b')]), ("a=a+b;b=b+c", [('a', 'a b'), ('b', 'b c')]), ("a=1;a=2", [('a', '1'), ('a', '2')]), (b";", []), (b";;", []), (b";a=b", [(b'a', b'b')]), (b"a=a+b;b=b+c", [(b'a', b'a b'), (b'b', b'b c')]), (b"a=1;a=2", [(b'a', b'1'), (b'a', b'2')]), ] for orig, expect in parse_qsl_semicolon_cases: with self.subTest(f"Original: {orig!r}, Expected: {expect!r}"): result = urllib.parse.parse_qsl(orig, separator=';') self.assertEqual(result, expect, "Error parsing %r" % orig) result_bytes = urllib.parse.parse_qsl(orig, separator=b';') self.assertEqual(result_bytes, expect, "Error parsing %r" % orig) def test_urlencode_sequences(self): # Other tests incidentally urlencode things; test non-covered cases: # Sequence and object values. result = urllib.parse.urlencode({'a': [1, 2], 'b': (3, 4, 5)}, True) # we cannot rely on ordering here assert set(result.split('&')) == {'a=1', 'a=2', 'b=3', 'b=4', 'b=5'} class Trivial: def __str__(self): return 'trivial' result = urllib.parse.urlencode({'a': Trivial()}, True) self.assertEqual(result, 'a=trivial') def test_urlencode_quote_via(self): result = urllib.parse.urlencode({'a': 'some value'}) self.assertEqual(result, "a=some+value") result = urllib.parse.urlencode({'a': 'some value/another'}, quote_via=urllib.parse.quote) self.assertEqual(result, "a=some%20value%2Fanother") result = urllib.parse.urlencode({'a': 'some value/another'}, safe='/', quote_via=urllib.parse.quote) self.assertEqual(result, "a=some%20value/another") def test_quote_from_bytes(self): self.assertRaises(TypeError, urllib.parse.quote_from_bytes, 'foo') result = urllib.parse.quote_from_bytes(b'archaeological arcana') self.assertEqual(result, 'archaeological%20arcana') result = urllib.parse.quote_from_bytes(b'') self.assertEqual(result, '') def test_unquote_to_bytes(self): result = urllib.parse.unquote_to_bytes('abc%20def') self.assertEqual(result, b'abc def') result = urllib.parse.unquote_to_bytes('') self.assertEqual(result, b'') def test_quote_errors(self): self.assertRaises(TypeError, urllib.parse.quote, b'foo', encoding='utf-8') self.assertRaises(TypeError, urllib.parse.quote, b'foo', errors='strict') def test_issue14072(self): p1 = urllib.parse.urlsplit('tel:+31-641044153') self.assertEqual(p1.scheme, 'tel') self.assertEqual(p1.path, '+31-641044153') p2 = urllib.parse.urlsplit('tel:+31641044153') self.assertEqual(p2.scheme, 'tel') self.assertEqual(p2.path, '+31641044153') # assert the behavior for urlparse p1 = urllib.parse.urlparse('tel:+31-641044153') self.assertEqual(p1.scheme, 'tel') self.assertEqual(p1.path, '+31-641044153') p2 = urllib.parse.urlparse('tel:+31641044153') self.assertEqual(p2.scheme, 'tel') self.assertEqual(p2.path, '+31641044153') def test_port_casting_failure_message(self): message = "Port could not be cast to integer value as 'oracle'" p1 = urllib.parse.urlparse('http://Server=sde; Service=sde:oracle') with self.assertRaisesRegex(ValueError, message): p1.port p2 = urllib.parse.urlsplit('http://Server=sde; Service=sde:oracle') with self.assertRaisesRegex(ValueError, message): p2.port def test_telurl_params(self): p1 = urllib.parse.urlparse('tel:123-4;phone-context=+1-650-516') self.assertEqual(p1.scheme, 'tel') self.assertEqual(p1.path, '123-4') self.assertEqual(p1.params, 'phone-context=+1-650-516') p1 = urllib.parse.urlparse('tel:+1-201-555-0123') self.assertEqual(p1.scheme, 'tel') self.assertEqual(p1.path, '+1-201-555-0123') self.assertEqual(p1.params, '') p1 = urllib.parse.urlparse('tel:7042;phone-context=example.com') self.assertEqual(p1.scheme, 'tel') self.assertEqual(p1.path, '7042') self.assertEqual(p1.params, 'phone-context=example.com') p1 = urllib.parse.urlparse('tel:863-1234;phone-context=+1-914-555') self.assertEqual(p1.scheme, 'tel') self.assertEqual(p1.path, '863-1234') self.assertEqual(p1.params, 'phone-context=+1-914-555') def test_Quoter_repr(self): quoter = urllib.parse.Quoter(urllib.parse._ALWAYS_SAFE) self.assertIn('Quoter', repr(quoter)) def test_all(self): expected = [] undocumented = { 'splitattr', 'splithost', 'splitnport', 'splitpasswd', 'splitport', 'splitquery', 'splittag', 'splittype', 'splituser', 'splitvalue', 'Quoter', 'ResultBase', 'clear_cache', 'to_bytes', 'unwrap', } for name in dir(urllib.parse): if name.startswith('_') or name in undocumented: continue object = getattr(urllib.parse, name) if getattr(object, '__module__', None) == 'urllib.parse': expected.append(name) self.assertCountEqual(urllib.parse.__all__, expected) def test_urlsplit_normalization(self): # Certain characters should never occur in the netloc, # including under normalization. # Ensure that ALL of them are detected and cause an error illegal_chars = '/:#?@' hex_chars = {'{:04X}'.format(ord(c)) for c in illegal_chars} denorm_chars = [ c for c in map(chr, range(128, sys.maxunicode)) if (hex_chars & set(unicodedata.decomposition(c).split())) and c not in illegal_chars ] # Sanity check that we found at least one such character self.assertIn('\u2100', denorm_chars) self.assertIn('\uFF03', denorm_chars) # bpo-36742: Verify port separators are ignored when they # existed prior to decomposition urllib.parse.urlsplit('http://\u30d5\u309a:80') with self.assertRaises(ValueError): urllib.parse.urlsplit('http://\u30d5\u309a\ufe1380') for scheme in ["http", "https", "ftp"]: for netloc in ["netloc{}false.netloc", "n{}user@netloc"]: for c in denorm_chars: url = "{}://{}/path".format(scheme, netloc.format(c)) with self.subTest(url=url, char='{:04X}'.format(ord(c))): with self.assertRaises(ValueError): urllib.parse.urlsplit(url) class Utility_Tests(unittest.TestCase): """Testcase to test the various utility functions in the urllib.""" # In Python 2 this test class was in test_urllib. def test_splittype(self): splittype = urllib.parse._splittype self.assertEqual(splittype('type:opaquestring'), ('type', 'opaquestring')) self.assertEqual(splittype('opaquestring'), (None, 'opaquestring')) self.assertEqual(splittype(':opaquestring'), (None, ':opaquestring')) self.assertEqual(splittype('type:'), ('type', '')) self.assertEqual(splittype('type:opaque:string'), ('type', 'opaque:string')) def test_splithost(self): splithost = urllib.parse._splithost self.assertEqual(splithost('//www.example.org:80/foo/bar/baz.html'), ('www.example.org:80', '/foo/bar/baz.html')) self.assertEqual(splithost('//www.example.org:80'), ('www.example.org:80', '')) self.assertEqual(splithost('/foo/bar/baz.html'), (None, '/foo/bar/baz.html')) # bpo-30500: # starts a fragment. self.assertEqual(splithost('//127.0.0.1#@host.com'), ('127.0.0.1', '/#@host.com')) self.assertEqual(splithost('//127.0.0.1#@host.com:80'), ('127.0.0.1', '/#@host.com:80')) self.assertEqual(splithost('//127.0.0.1:80#@host.com'), ('127.0.0.1:80', '/#@host.com')) # Empty host is returned as empty string. self.assertEqual(splithost("///file"), ('', '/file')) # Trailing semicolon, question mark and hash symbol are kept. self.assertEqual(splithost("//example.net/file;"), ('example.net', '/file;')) self.assertEqual(splithost("//example.net/file?"), ('example.net', '/file?')) self.assertEqual(splithost("//example.net/file#"), ('example.net', '/file#')) def test_splituser(self): splituser = urllib.parse._splituser self.assertEqual(splituser('User:Pass@www.python.org:080'), ('User:Pass', 'www.python.org:080')) self.assertEqual(splituser('@www.python.org:080'), ('', 'www.python.org:080')) self.assertEqual(splituser('www.python.org:080'), (None, 'www.python.org:080')) self.assertEqual(splituser('User:Pass@'), ('User:Pass', '')) self.assertEqual(splituser('User@example.com:Pass@www.python.org:080'), ('User@example.com:Pass', 'www.python.org:080')) def test_splitpasswd(self): # Some of the password examples are not sensible, but it is added to # confirming to RFC2617 and addressing issue4675. splitpasswd = urllib.parse._splitpasswd self.assertEqual(splitpasswd('user:ab'), ('user', 'ab')) self.assertEqual(splitpasswd('user:a\nb'), ('user', 'a\nb')) self.assertEqual(splitpasswd('user:a\tb'), ('user', 'a\tb')) self.assertEqual(splitpasswd('user:a\rb'), ('user', 'a\rb')) self.assertEqual(splitpasswd('user:a\fb'), ('user', 'a\fb')) self.assertEqual(splitpasswd('user:a\vb'), ('user', 'a\vb')) self.assertEqual(splitpasswd('user:a:b'), ('user', 'a:b')) self.assertEqual(splitpasswd('user:a b'), ('user', 'a b')) self.assertEqual(splitpasswd('user 2:ab'), ('user 2', 'ab')) self.assertEqual(splitpasswd('user+1:a+b'), ('user+1', 'a+b')) self.assertEqual(splitpasswd('user:'), ('user', '')) self.assertEqual(splitpasswd('user'), ('user', None)) self.assertEqual(splitpasswd(':ab'), ('', 'ab')) def test_splitport(self): splitport = urllib.parse._splitport self.assertEqual(splitport('parrot:88'), ('parrot', '88')) self.assertEqual(splitport('parrot'), ('parrot', None)) self.assertEqual(splitport('parrot:'), ('parrot', None)) self.assertEqual(splitport('127.0.0.1'), ('127.0.0.1', None)) self.assertEqual(splitport('parrot:cheese'), ('parrot:cheese', None)) self.assertEqual(splitport('[::1]:88'), ('[::1]', '88')) self.assertEqual(splitport('[::1]'), ('[::1]', None)) self.assertEqual(splitport(':88'), ('', '88')) def test_splitnport(self): splitnport = urllib.parse._splitnport self.assertEqual(splitnport('parrot:88'), ('parrot', 88)) self.assertEqual(splitnport('parrot'), ('parrot', -1)) self.assertEqual(splitnport('parrot', 55), ('parrot', 55)) self.assertEqual(splitnport('parrot:'), ('parrot', -1)) self.assertEqual(splitnport('parrot:', 55), ('parrot', 55)) self.assertEqual(splitnport('127.0.0.1'), ('127.0.0.1', -1)) self.assertEqual(splitnport('127.0.0.1', 55), ('127.0.0.1', 55)) self.assertEqual(splitnport('parrot:cheese'), ('parrot', None)) self.assertEqual(splitnport('parrot:cheese', 55), ('parrot', None)) def test_splitquery(self): # Normal cases are exercised by other tests; ensure that we also # catch cases with no port specified (testcase ensuring coverage) splitquery = urllib.parse._splitquery self.assertEqual(splitquery('http://python.org/fake?foo=bar'), ('http://python.org/fake', 'foo=bar')) self.assertEqual(splitquery('http://python.org/fake?foo=bar?'), ('http://python.org/fake?foo=bar', '')) self.assertEqual(splitquery('http://python.org/fake'), ('http://python.org/fake', None)) self.assertEqual(splitquery('?foo=bar'), ('', 'foo=bar')) def test_splittag(self): splittag = urllib.parse._splittag self.assertEqual(splittag('http://example.com?foo=bar#baz'), ('http://example.com?foo=bar', 'baz')) self.assertEqual(splittag('http://example.com?foo=bar#'), ('http://example.com?foo=bar', '')) self.assertEqual(splittag('#baz'), ('', 'baz')) self.assertEqual(splittag('http://example.com?foo=bar'), ('http://example.com?foo=bar', None)) self.assertEqual(splittag('http://example.com?foo=bar#baz#boo'), ('http://example.com?foo=bar#baz', 'boo')) def test_splitattr(self): splitattr = urllib.parse._splitattr self.assertEqual(splitattr('/path;attr1=value1;attr2=value2'), ('/path', ['attr1=value1', 'attr2=value2'])) self.assertEqual(splitattr('/path;'), ('/path', [''])) self.assertEqual(splitattr(';attr1=value1;attr2=value2'), ('', ['attr1=value1', 'attr2=value2'])) self.assertEqual(splitattr('/path'), ('/path', [])) def test_splitvalue(self): # Normal cases are exercised by other tests; test pathological cases # with no key/value pairs. (testcase ensuring coverage) splitvalue = urllib.parse._splitvalue self.assertEqual(splitvalue('foo=bar'), ('foo', 'bar')) self.assertEqual(splitvalue('foo='), ('foo', '')) self.assertEqual(splitvalue('=bar'), ('', 'bar')) self.assertEqual(splitvalue('foobar'), ('foobar', None)) self.assertEqual(splitvalue('foo=bar=baz'), ('foo', 'bar=baz')) def test_to_bytes(self): result = urllib.parse._to_bytes('http://www.python.org') self.assertEqual(result, 'http://www.python.org') self.assertRaises(UnicodeError, urllib.parse._to_bytes, 'http://www.python.org/medi\u00e6val') def test_unwrap(self): for wrapped_url in ('<URL:scheme://host/path>', '<scheme://host/path>', 'URL:scheme://host/path', 'scheme://host/path'): url = urllib.parse.unwrap(wrapped_url) self.assertEqual(url, 'scheme://host/path') class DeprecationTest(unittest.TestCase): def test_splittype_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splittype('') self.assertEqual(str(cm.warning), 'urllib.parse.splittype() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splithost_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splithost('') self.assertEqual(str(cm.warning), 'urllib.parse.splithost() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splituser_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splituser('') self.assertEqual(str(cm.warning), 'urllib.parse.splituser() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splitpasswd_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splitpasswd('') self.assertEqual(str(cm.warning), 'urllib.parse.splitpasswd() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splitport_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splitport('') self.assertEqual(str(cm.warning), 'urllib.parse.splitport() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splitnport_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splitnport('') self.assertEqual(str(cm.warning), 'urllib.parse.splitnport() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splitquery_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splitquery('') self.assertEqual(str(cm.warning), 'urllib.parse.splitquery() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splittag_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splittag('') self.assertEqual(str(cm.warning), 'urllib.parse.splittag() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splitattr_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splitattr('') self.assertEqual(str(cm.warning), 'urllib.parse.splitattr() is deprecated as of 3.8, ' 'use urllib.parse.urlparse() instead') def test_splitvalue_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.splitvalue('') self.assertEqual(str(cm.warning), 'urllib.parse.splitvalue() is deprecated as of 3.8, ' 'use urllib.parse.parse_qsl() instead') def test_to_bytes_deprecation(self): with self.assertWarns(DeprecationWarning) as cm: urllib.parse.to_bytes('') self.assertEqual(str(cm.warning), 'urllib.parse.to_bytes() is deprecated as of 3.8') if __name__ == "__main__": unittest.main()
Upload File
Create Folder