PATH: //opt/alt/python311/lib64/python3.11/test
FILE_BARU
CREATE
FOLDER_BARU
MKDIR
UPLOAD_FILE
GO
[ .. KEMBALI ]
๐ Sine-1000Hz-300ms.aif
โ
X
๐ __init__.py
โ
X
๐ __main__.py
โ
X
๐ __pycache__/
X
๐ _test_atexit.py
โ
X
๐ _test_eintr.py
โ
X
๐ _test_embed_set_config.py
โ
X
๐ _test_embed_structseq.py
โ
X
๐ _test_multiprocessing.py
โ
X
๐ _test_venv_multiprocessing.py
โ
X
๐ archiver_tests.py
โ
X
๐ audiodata/
X
๐ audiotest.au
โ
X
๐ audiotests.py
โ
X
๐ audit-tests.py
โ
X
๐ autotest.py
โ
X
๐ bisect_cmd.py
โ
X
๐ certdata/
X
๐ cjkencodings/
X
๐ clinic.test.c
โ
X
๐ cmath_testcases.txt
โ
X
๐ configdata/
X
๐ crashers/
X
๐ curses_tests.py
โ
X
๐ data/
X
๐ datetimetester.py
โ
X
๐ decimaltestdata/
X
๐ dis_module.py
โ
X
๐ dtracedata/
X
๐ empty.vbs
โ
X
๐ encoded_modules/
X
๐ exception_hierarchy.txt
โ
X
๐ floating_points.txt
โ
X
๐ fork_wait.py
โ
X
๐ formatfloat_testcases.txt
โ
X
๐ ieee754.txt
โ
X
๐ imghdrdata/
X
๐ imp_dummy.py
โ
X
๐ leakers/
X
๐ libregrtest/
X
๐ list_tests.py
โ
X
๐ lock_tests.py
โ
X
๐ mailcap.txt
โ
X
๐ mapping_tests.py
โ
X
๐ math_testcases.txt
โ
X
๐ memory_watchdog.py
โ
X
๐ mime.types
โ
X
๐ mock_socket.py
โ
X
๐ mp_fork_bomb.py
โ
X
๐ mp_preload.py
โ
X
๐ multibytecodec_support.py
โ
X
๐ pickletester.py
โ
X
๐ profilee.py
โ
X
๐ pstats.pck
โ
X
๐ pyclbr_input.py
โ
X
๐ pythoninfo.py
โ
X
๐ randv2_32.pck
โ
X
๐ randv2_64.pck
โ
X
๐ randv3.pck
โ
X
๐ re_tests.py
โ
X
๐ recursion.tar
โ
X
๐ regrtest.py
โ
X
๐ regrtestdata/
X
๐ relimport.py
โ
X
๐ reperf.py
โ
X
๐ seq_tests.py
โ
X
๐ signalinterproctester.py
โ
X
๐ sndhdrdata/
X
๐ ssl_servers.py
โ
X
๐ ssltests.py
โ
X
๐ string_tests.py
โ
X
๐ subprocessdata/
X
๐ support/
X
๐ test___all__.py
โ
X
๐ test__locale.py
โ
X
๐ test__opcode.py
โ
X
๐ test__osx_support.py
โ
X
๐ test__xxsubinterpreters.py
โ
X
๐ test_abc.py
โ
X
๐ test_abstract_numbers.py
โ
X
๐ test_aifc.py
โ
X
๐ test_argparse.py
โ
X
๐ test_array.py
โ
X
๐ test_asdl_parser.py
โ
X
๐ test_ast.py
โ
X
๐ test_asyncgen.py
โ
X
๐ test_asynchat.py
โ
X
๐ test_asyncio/
X
๐ test_asyncore.py
โ
X
๐ test_atexit.py
โ
X
๐ test_audioop.py
โ
X
๐ test_audit.py
โ
X
๐ test_augassign.py
โ
X
๐ test_base64.py
โ
X
๐ test_baseexception.py
โ
X
๐ test_bdb.py
โ
X
๐ test_bigaddrspace.py
โ
X
๐ test_bigmem.py
โ
X
๐ test_binascii.py
โ
X
๐ test_binop.py
โ
X
๐ test_bisect.py
โ
X
๐ test_bool.py
โ
X
๐ test_buffer.py
โ
X
๐ test_bufio.py
โ
X
๐ test_builtin.py
โ
X
๐ test_bytes.py
โ
X
๐ test_bz2.py
โ
X
๐ test_c_locale_coercion.py
โ
X
๐ test_calendar.py
โ
X
๐ test_call.py
โ
X
๐ test_capi/
X
๐ test_cgi.py
โ
X
๐ test_cgitb.py
โ
X
๐ test_charmapcodec.py
โ
X
๐ test_check_c_globals.py
โ
X
๐ test_class.py
โ
X
๐ test_clinic.py
โ
X
๐ test_cmath.py
โ
X
๐ test_cmd.py
โ
X
๐ test_cmd_line.py
โ
X
๐ test_cmd_line_script.py
โ
X
๐ test_code.py
โ
X
๐ test_code_module.py
โ
X
๐ test_codeccallbacks.py
โ
X
๐ test_codecencodings_cn.py
โ
X
๐ test_codecencodings_hk.py
โ
X
๐ test_codecencodings_iso2022.py
โ
X
๐ test_codecencodings_jp.py
โ
X
๐ test_codecencodings_kr.py
โ
X
๐ test_codecencodings_tw.py
โ
X
๐ test_codecmaps_cn.py
โ
X
๐ test_codecmaps_hk.py
โ
X
๐ test_codecmaps_jp.py
โ
X
๐ test_codecmaps_kr.py
โ
X
๐ test_codecmaps_tw.py
โ
X
๐ test_codecs.py
โ
X
๐ test_codeop.py
โ
X
๐ test_collections.py
โ
X
๐ test_colorsys.py
โ
X
๐ test_compare.py
โ
X
๐ test_compile.py
โ
X
๐ test_compileall.py
โ
X
๐ test_complex.py
โ
X
๐ test_concurrent_futures/
X
๐ test_configparser.py
โ
X
๐ test_contains.py
โ
X
๐ test_context.py
โ
X
๐ test_contextlib.py
โ
X
๐ test_contextlib_async.py
โ
X
๐ test_copy.py
โ
X
๐ test_copyreg.py
โ
X
๐ test_coroutines.py
โ
X
๐ test_cppext/
X
๐ test_cprofile.py
โ
X
๐ test_crashers.py
โ
X
๐ test_crypt.py
โ
X
๐ test_csv.py
โ
X
๐ test_ctypes.py
โ
X
๐ test_curses.py
โ
X
๐ test_dataclasses/
X
๐ test_datetime.py
โ
X
๐ test_dbm.py
โ
X
๐ test_dbm_dumb.py
โ
X
๐ test_dbm_gnu.py
โ
X
๐ test_dbm_ndbm.py
โ
X
๐ test_decimal.py
โ
X
๐ test_decorators.py
โ
X
๐ test_defaultdict.py
โ
X
๐ test_deque.py
โ
X
๐ test_descr.py
โ
X
๐ test_descrtut.py
โ
X
๐ test_devpoll.py
โ
X
๐ test_dict.py
โ
X
๐ test_dict_version.py
โ
X
๐ test_dictcomps.py
โ
X
๐ test_dictviews.py
โ
X
๐ test_difflib.py
โ
X
๐ test_difflib_expect.html
โ
X
๐ test_dis.py
โ
X
๐ test_distutils.py
โ
X
๐ test_doctest/
X
๐ test_docxmlrpc.py
โ
X
๐ test_dtrace.py
โ
X
๐ test_dynamic.py
โ
X
๐ test_dynamicclassattribute.py
โ
X
๐ test_eintr.py
โ
X
๐ test_email/
X
๐ test_embed.py
โ
X
๐ test_ensurepip.py
โ
X
๐ test_enum.py
โ
X
๐ test_enumerate.py
โ
X
๐ test_eof.py
โ
X
๐ test_epoll.py
โ
X
๐ test_errno.py
โ
X
๐ test_except_star.py
โ
X
๐ test_exception_group.py
โ
X
๐ test_exception_hierarchy.py
โ
X
๐ test_exception_variations.py
โ
X
๐ test_exceptions.py
โ
X
๐ test_extcall.py
โ
X
๐ test_faulthandler.py
โ
X
๐ test_fcntl.py
โ
X
๐ test_file.py
โ
X
๐ test_file_eintr.py
โ
X
๐ test_filecmp.py
โ
X
๐ test_fileinput.py
โ
X
๐ test_fileio.py
โ
X
๐ test_fileutils.py
โ
X
๐ test_finalization.py
โ
X
๐ test_float.py
โ
X
๐ test_flufl.py
โ
X
๐ test_fnmatch.py
โ
X
๐ test_fork1.py
โ
X
๐ test_format.py
โ
X
๐ test_fractions.py
โ
X
๐ test_frame.py
โ
X
๐ test_frozen.py
โ
X
๐ test_fstring.py
โ
X
๐ test_ftplib.py
โ
X
๐ test_funcattrs.py
โ
X
๐ test_functools.py
โ
X
๐ test_future_stmt/
X
๐ test_gc.py
โ
X
๐ test_gdb/
X
๐ test_generator_stop.py
โ
X
๐ test_generators.py
โ
X
๐ test_genericalias.py
โ
X
๐ test_genericclass.py
โ
X
๐ test_genericpath.py
โ
X
๐ test_genexps.py
โ
X
๐ test_getopt.py
โ
X
๐ test_getpass.py
โ
X
๐ test_getpath.py
โ
X
๐ test_gettext.py
โ
X
๐ test_glob.py
โ
X
๐ test_global.py
โ
X
๐ test_grammar.py
โ
X
๐ test_graphlib.py
โ
X
๐ test_grp.py
โ
X
๐ test_gzip.py
โ
X
๐ test_hash.py
โ
X
๐ test_hashlib.py
โ
X
๐ test_heapq.py
โ
X
๐ test_hmac.py
โ
X
๐ test_html.py
โ
X
๐ test_htmlparser.py
โ
X
๐ test_http_cookiejar.py
โ
X
๐ test_http_cookies.py
โ
X
๐ test_httplib.py
โ
X
๐ test_httpservers.py
โ
X
๐ test_idle.py
โ
X
๐ test_imaplib.py
โ
X
๐ test_imghdr.py
โ
X
๐ test_imp.py
โ
X
๐ test_import/
X
๐ test_importlib/
X
๐ test_index.py
โ
X
๐ test_inspect/
X
๐ test_int.py
โ
X
๐ test_int_literal.py
โ
X
๐ test_interpreters.py
โ
X
๐ test_io.py
โ
X
๐ test_ioctl.py
โ
X
๐ test_ipaddress.py
โ
X
๐ test_isinstance.py
โ
X
๐ test_iter.py
โ
X
๐ test_iterlen.py
โ
X
๐ test_itertools.py
โ
X
๐ test_json/
X
๐ test_keyword.py
โ
X
๐ test_keywordonlyarg.py
โ
X
๐ test_kqueue.py
โ
X
๐ test_largefile.py
โ
X
๐ test_launcher.py
โ
X
๐ test_lib2to3.py
โ
X
๐ test_linecache.py
โ
X
๐ test_list.py
โ
X
๐ test_listcomps.py
โ
X
๐ test_lltrace.py
โ
X
๐ test_locale.py
โ
X
๐ test_logging.py
โ
X
๐ test_long.py
โ
X
๐ test_longexp.py
โ
X
๐ test_lzma.py
โ
X
๐ test_mailbox.py
โ
X
๐ test_mailcap.py
โ
X
๐ test_marshal.py
โ
X
๐ test_math.py
โ
X
๐ test_memoryio.py
โ
X
๐ test_memoryview.py
โ
X
๐ test_metaclass.py
โ
X
๐ test_mimetypes.py
โ
X
๐ test_minidom.py
โ
X
๐ test_mmap.py
โ
X
๐ test_module/
X
๐ test_modulefinder.py
โ
X
๐ test_msilib.py
โ
X
๐ test_multibytecodec.py
โ
X
๐ test_multiprocessing_fork/
X
๐ test_multiprocessing_forkserver/
X
๐ test_multiprocessing_main_handling.py
โ
X
๐ test_multiprocessing_spawn/
X
๐ test_named_expressions.py
โ
X
๐ test_netrc.py
โ
X
๐ test_nis.py
โ
X
๐ test_nntplib.py
โ
X
๐ test_ntpath.py
โ
X
๐ test_numeric_tower.py
โ
X
๐ test_opcache.py
โ
X
๐ test_opcodes.py
โ
X
๐ test_openpty.py
โ
X
๐ test_operator.py
โ
X
๐ test_optparse.py
โ
X
๐ test_ordered_dict.py
โ
X
๐ test_os.py
โ
X
๐ test_ossaudiodev.py
โ
X
๐ test_osx_env.py
โ
X
๐ test_pathlib.py
โ
X
๐ test_patma.py
โ
X
๐ test_pdb.py
โ
X
๐ test_peepholer.py
โ
X
๐ test_peg_generator/
X
๐ test_pep646_syntax.py
โ
X
๐ test_pickle.py
โ
X
๐ test_picklebuffer.py
โ
X
๐ test_pickletools.py
โ
X
๐ test_pipes.py
โ
X
๐ test_pkg.py
โ
X
๐ test_pkgutil.py
โ
X
๐ test_platform.py
โ
X
๐ test_plistlib.py
โ
X
๐ test_poll.py
โ
X
๐ test_popen.py
โ
X
๐ test_poplib.py
โ
X
๐ test_positional_only_arg.py
โ
X
๐ test_posix.py
โ
X
๐ test_posixpath.py
โ
X
๐ test_pow.py
โ
X
๐ test_pprint.py
โ
X
๐ test_print.py
โ
X
๐ test_profile.py
โ
X
๐ test_property.py
โ
X
๐ test_pstats.py
โ
X
๐ test_pty.py
โ
X
๐ test_pulldom.py
โ
X
๐ test_pwd.py
โ
X
๐ test_py_compile.py
โ
X
๐ test_pyclbr.py
โ
X
๐ test_pydoc/
X
๐ test_pyexpat.py
โ
X
๐ test_queue.py
โ
X
๐ test_quopri.py
โ
X
๐ test_raise.py
โ
X
๐ test_random.py
โ
X
๐ test_range.py
โ
X
๐ test_re.py
โ
X
๐ test_readline.py
โ
X
๐ test_regrtest.py
โ
X
๐ test_repl.py
โ
X
๐ test_reprlib.py
โ
X
๐ test_resource.py
โ
X
๐ test_richcmp.py
โ
X
๐ test_rlcompleter.py
โ
X
๐ test_robotparser.py
โ
X
๐ test_runpy.py
โ
X
๐ test_sax.py
โ
X
๐ test_sched.py
โ
X
๐ test_scope.py
โ
X
๐ test_script_helper.py
โ
X
๐ test_secrets.py
โ
X
๐ test_select.py
โ
X
๐ test_selectors.py
โ
X
๐ test_set.py
โ
X
๐ test_setcomps.py
โ
X
๐ test_shelve.py
โ
X
๐ test_shlex.py
โ
X
๐ test_shutil.py
โ
X
๐ test_signal.py
โ
X
๐ test_site.py
โ
X
๐ test_slice.py
โ
X
๐ test_smtpd.py
โ
X
๐ test_smtplib.py
โ
X
๐ test_smtpnet.py
โ
X
๐ test_sndhdr.py
โ
X
๐ test_socket.py
โ
X
๐ test_socketserver.py
โ
X
๐ test_sort.py
โ
X
๐ test_source_encoding.py
โ
X
๐ test_spwd.py
โ
X
๐ test_sqlite3/
X
๐ test_ssl.py
โ
X
๐ test_stable_abi_ctypes.py
โ
X
๐ test_startfile.py
โ
X
๐ test_stat.py
โ
X
๐ test_statistics.py
โ
X
๐ test_strftime.py
โ
X
๐ test_string.py
โ
X
๐ test_string_literals.py
โ
X
๐ test_stringprep.py
โ
X
๐ test_strptime.py
โ
X
๐ test_strtod.py
โ
X
๐ test_struct.py
โ
X
๐ test_structseq.py
โ
X
๐ test_subclassinit.py
โ
X
๐ test_subprocess.py
โ
X
๐ test_sunau.py
โ
X
๐ test_sundry.py
โ
X
๐ test_super.py
โ
X
๐ test_support.py
โ
X
๐ test_symtable.py
โ
X
๐ test_syntax.py
โ
X
๐ test_sys.py
โ
X
๐ test_sys_setprofile.py
โ
X
๐ test_sys_settrace.py
โ
X
๐ test_sysconfig.py
โ
X
๐ test_syslog.py
โ
X
๐ test_tabnanny.py
โ
X
๐ test_tarfile.py
โ
X
๐ test_tcl.py
โ
X
๐ test_telnetlib.py
โ
X
๐ test_tempfile.py
โ
X
๐ test_termios.py
โ
X
๐ test_textwrap.py
โ
X
๐ test_thread.py
โ
X
๐ test_threadedtempfile.py
โ
X
๐ test_threading.py
โ
X
๐ test_threading_local.py
โ
X
๐ test_threadsignals.py
โ
X
๐ test_time.py
โ
X
๐ test_timeit.py
โ
X
๐ test_timeout.py
โ
X
๐ test_tix.py
โ
X
๐ test_tk.py
โ
X
๐ test_tokenize.py
โ
X
๐ test_tomllib/
X
๐ test_tools/
X
๐ test_trace.py
โ
X
๐ test_traceback.py
โ
X
๐ test_tracemalloc.py
โ
X
๐ test_ttk_guionly.py
โ
X
๐ test_ttk_textonly.py
โ
X
๐ test_tty.py
โ
X
๐ test_tuple.py
โ
X
๐ test_turtle.py
โ
X
๐ test_type_annotations.py
โ
X
๐ test_type_cache.py
โ
X
๐ test_type_comments.py
โ
X
๐ test_typechecks.py
โ
X
๐ test_types.py
โ
X
๐ test_typing.py
โ
X
๐ test_ucn.py
โ
X
๐ test_unary.py
โ
X
๐ test_unicode.py
โ
X
๐ test_unicode_file.py
โ
X
๐ test_unicode_file_functions.py
โ
X
๐ test_unicode_identifiers.py
โ
X
๐ test_unicodedata.py
โ
X
๐ test_unittest.py
โ
X
๐ test_univnewlines.py
โ
X
๐ test_unpack.py
โ
X
๐ test_unpack_ex.py
โ
X
๐ test_unparse.py
โ
X
๐ test_urllib.py
โ
X
๐ test_urllib2.py
โ
X
๐ test_urllib2_localnet.py
โ
X
๐ test_urllib2net.py
โ
X
๐ test_urllib_response.py
โ
X
๐ test_urllibnet.py
โ
X
๐ test_urlparse.py
โ
X
๐ test_userdict.py
โ
X
๐ test_userlist.py
โ
X
๐ test_userstring.py
โ
X
๐ test_utf8_mode.py
โ
X
๐ test_utf8source.py
โ
X
๐ test_uu.py
โ
X
๐ test_uuid.py
โ
X
๐ test_venv.py
โ
X
๐ test_wait3.py
โ
X
๐ test_wait4.py
โ
X
๐ test_warnings/
X
๐ test_wave.py
โ
X
๐ test_weakref.py
โ
X
๐ test_weakset.py
โ
X
๐ test_webbrowser.py
โ
X
๐ test_winconsoleio.py
โ
X
๐ test_winreg.py
โ
X
๐ test_winsound.py
โ
X
๐ test_with.py
โ
X
๐ test_wsgiref.py
โ
X
๐ test_xdrlib.py
โ
X
๐ test_xml_dom_minicompat.py
โ
X
๐ test_xml_etree.py
โ
X
๐ test_xml_etree_c.py
โ
X
๐ test_xmlrpc.py
โ
X
๐ test_xmlrpc_net.py
โ
X
๐ test_xxlimited.py
โ
X
๐ test_xxtestfuzz.py
โ
X
๐ test_yield_from.py
โ
X
๐ test_zipapp.py
โ
X
๐ test_zipfile.py
โ
X
๐ test_zipfile64.py
โ
X
๐ test_zipimport.py
โ
X
๐ test_zipimport_support.py
โ
X
๐ test_zlib.py
โ
X
๐ test_zoneinfo/
X
๐ testcodec.py
โ
X
๐ testtar.tar
โ
X
๐ testtar.tar.xz
โ
X
๐ tf_inherit_check.py
โ
X
๐ time_hashlib.py
โ
X
๐ tokenizedata/
X
๐ tracedmodules/
X
๐ typinganndata/
X
๐ win_console_handler.py
โ
X
๐ xmltestdata/
X
๐ xmltests.py
โ
X
๐ zip_cp437_header.zip
โ
X
๐ zipdir.zip
โ
X
๐ zipdir_backslash.zip
โ
X
๐ ziptestdata/
X
SAVING...
BERHASIL DIUBAH!
EDITING: test_multibytecodec.py
# # test_multibytecodec.py # Unit test for multibytecodec itself # import _multibytecodec import codecs import io import sys import textwrap import unittest from test import support from test.support import os_helper from test.support.os_helper import TESTFN ALL_CJKENCODINGS = [ # _codecs_cn 'gb2312', 'gbk', 'gb18030', 'hz', # _codecs_hk 'big5hkscs', # _codecs_jp 'cp932', 'shift_jis', 'euc_jp', 'euc_jisx0213', 'shift_jisx0213', 'euc_jis_2004', 'shift_jis_2004', # _codecs_kr 'cp949', 'euc_kr', 'johab', # _codecs_tw 'big5', 'cp950', # _codecs_iso2022 'iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2', 'iso2022_jp_2004', 'iso2022_jp_3', 'iso2022_jp_ext', 'iso2022_kr', ] class Test_MultibyteCodec(unittest.TestCase): def test_nullcoding(self): for enc in ALL_CJKENCODINGS: self.assertEqual(b''.decode(enc), '') self.assertEqual(str(b'', enc), '') self.assertEqual(''.encode(enc), b'') def test_str_decode(self): for enc in ALL_CJKENCODINGS: self.assertEqual('abcd'.encode(enc), b'abcd') def test_errorcallback_longindex(self): dec = codecs.getdecoder('euc-kr') myreplace = lambda exc: ('', sys.maxsize+1) codecs.register_error('test.cjktest', myreplace) self.assertRaises(IndexError, dec, b'apple\x92ham\x93spam', 'test.cjktest') def test_errorcallback_custom_ignore(self): # Issue #23215: MemoryError with custom error handlers and multibyte codecs data = 100 * "\udc00" codecs.register_error("test.ignore", codecs.ignore_errors) for enc in ALL_CJKENCODINGS: self.assertEqual(data.encode(enc, "test.ignore"), b'') def test_codingspec(self): try: for enc in ALL_CJKENCODINGS: code = '# coding: {}\n'.format(enc) exec(code) finally: os_helper.unlink(TESTFN) def test_init_segfault(self): # bug #3305: this used to segfault self.assertRaises(AttributeError, _multibytecodec.MultibyteStreamReader, None) self.assertRaises(AttributeError, _multibytecodec.MultibyteStreamWriter, None) def test_decode_unicode(self): # Trying to decode a unicode string should raise a TypeError for enc in ALL_CJKENCODINGS: self.assertRaises(TypeError, codecs.getdecoder(enc), "") class Test_IncrementalEncoder(unittest.TestCase): def test_stateless(self): # cp949 encoder isn't stateful at all. encoder = codecs.getincrementalencoder('cp949')() self.assertEqual(encoder.encode('\ud30c\uc774\uc36c \ub9c8\uc744'), b'\xc6\xc4\xc0\xcc\xbd\xe3 \xb8\xb6\xc0\xbb') self.assertEqual(encoder.reset(), None) self.assertEqual(encoder.encode('\u2606\u223c\u2606', True), b'\xa1\xd9\xa1\xad\xa1\xd9') self.assertEqual(encoder.reset(), None) self.assertEqual(encoder.encode('', True), b'') self.assertEqual(encoder.encode('', False), b'') self.assertEqual(encoder.reset(), None) def test_stateful(self): # jisx0213 encoder is stateful for a few code points. eg) # U+00E6 => A9DC # U+00E6 U+0300 => ABC4 # U+0300 => ABDC encoder = codecs.getincrementalencoder('jisx0213')() self.assertEqual(encoder.encode('\u00e6\u0300'), b'\xab\xc4') self.assertEqual(encoder.encode('\u00e6'), b'') self.assertEqual(encoder.encode('\u0300'), b'\xab\xc4') self.assertEqual(encoder.encode('\u00e6', True), b'\xa9\xdc') self.assertEqual(encoder.reset(), None) self.assertEqual(encoder.encode('\u0300'), b'\xab\xdc') self.assertEqual(encoder.encode('\u00e6'), b'') self.assertEqual(encoder.encode('', True), b'\xa9\xdc') self.assertEqual(encoder.encode('', True), b'') def test_stateful_keep_buffer(self): encoder = codecs.getincrementalencoder('jisx0213')() self.assertEqual(encoder.encode('\u00e6'), b'') self.assertRaises(UnicodeEncodeError, encoder.encode, '\u0123') self.assertEqual(encoder.encode('\u0300\u00e6'), b'\xab\xc4') self.assertRaises(UnicodeEncodeError, encoder.encode, '\u0123') self.assertEqual(encoder.reset(), None) self.assertEqual(encoder.encode('\u0300'), b'\xab\xdc') self.assertEqual(encoder.encode('\u00e6'), b'') self.assertRaises(UnicodeEncodeError, encoder.encode, '\u0123') self.assertEqual(encoder.encode('', True), b'\xa9\xdc') def test_state_methods_with_buffer_state(self): # euc_jis_2004 stores state as a buffer of pending bytes encoder = codecs.getincrementalencoder('euc_jis_2004')() initial_state = encoder.getstate() self.assertEqual(encoder.encode('\u00e6\u0300'), b'\xab\xc4') encoder.setstate(initial_state) self.assertEqual(encoder.encode('\u00e6\u0300'), b'\xab\xc4') self.assertEqual(encoder.encode('\u00e6'), b'') partial_state = encoder.getstate() self.assertEqual(encoder.encode('\u0300'), b'\xab\xc4') encoder.setstate(partial_state) self.assertEqual(encoder.encode('\u0300'), b'\xab\xc4') def test_state_methods_with_non_buffer_state(self): # iso2022_jp stores state without using a buffer encoder = codecs.getincrementalencoder('iso2022_jp')() self.assertEqual(encoder.encode('z'), b'z') en_state = encoder.getstate() self.assertEqual(encoder.encode('\u3042'), b'\x1b\x24\x42\x24\x22') jp_state = encoder.getstate() self.assertEqual(encoder.encode('z'), b'\x1b\x28\x42z') encoder.setstate(jp_state) self.assertEqual(encoder.encode('\u3042'), b'\x24\x22') encoder.setstate(en_state) self.assertEqual(encoder.encode('z'), b'z') def test_getstate_returns_expected_value(self): # Note: getstate is implemented such that these state values # are expected to be the same across all builds of Python, # regardless of x32/64 bit, endianness and compiler. # euc_jis_2004 stores state as a buffer of pending bytes buffer_state_encoder = codecs.getincrementalencoder('euc_jis_2004')() self.assertEqual(buffer_state_encoder.getstate(), 0) buffer_state_encoder.encode('\u00e6') self.assertEqual(buffer_state_encoder.getstate(), int.from_bytes( b"\x02" b"\xc3\xa6" b"\x00\x00\x00\x00\x00\x00\x00\x00", 'little')) buffer_state_encoder.encode('\u0300') self.assertEqual(buffer_state_encoder.getstate(), 0) # iso2022_jp stores state without using a buffer non_buffer_state_encoder = codecs.getincrementalencoder('iso2022_jp')() self.assertEqual(non_buffer_state_encoder.getstate(), int.from_bytes( b"\x00" b"\x42\x42\x00\x00\x00\x00\x00\x00", 'little')) non_buffer_state_encoder.encode('\u3042') self.assertEqual(non_buffer_state_encoder.getstate(), int.from_bytes( b"\x00" b"\xc2\x42\x00\x00\x00\x00\x00\x00", 'little')) def test_setstate_validates_input_size(self): encoder = codecs.getincrementalencoder('euc_jp')() pending_size_nine = int.from_bytes( b"\x09" b"\x00\x00\x00\x00\x00\x00\x00\x00" b"\x00\x00\x00\x00\x00\x00\x00\x00", 'little') self.assertRaises(UnicodeError, encoder.setstate, pending_size_nine) def test_setstate_validates_input_bytes(self): encoder = codecs.getincrementalencoder('euc_jp')() invalid_utf8 = int.from_bytes( b"\x01" b"\xff" b"\x00\x00\x00\x00\x00\x00\x00\x00", 'little') self.assertRaises(UnicodeDecodeError, encoder.setstate, invalid_utf8) def test_issue5640(self): encoder = codecs.getincrementalencoder('shift-jis')('backslashreplace') self.assertEqual(encoder.encode('\xff'), b'\\xff') self.assertEqual(encoder.encode('\n'), b'\n') @support.cpython_only def test_subinterp(self): # bpo-42846: Test a CJK codec in a subinterpreter import _testcapi encoding = 'cp932' text = "Python ใฎ้็บใฏใ1990 ๅนดใใใใ้ๅงใใใฆใใพใใ" code = textwrap.dedent(""" import codecs encoding = %r text = %r encoder = codecs.getincrementalencoder(encoding)() text2 = encoder.encode(text).decode(encoding) if text2 != text: raise ValueError(f"encoding issue: {text2!a} != {text!a}") """) % (encoding, text) res = _testcapi.run_in_subinterp(code) self.assertEqual(res, 0) class Test_IncrementalDecoder(unittest.TestCase): def test_dbcs(self): # cp949 decoder is simple with only 1 or 2 bytes sequences. decoder = codecs.getincrementaldecoder('cp949')() self.assertEqual(decoder.decode(b'\xc6\xc4\xc0\xcc\xbd'), '\ud30c\uc774') self.assertEqual(decoder.decode(b'\xe3 \xb8\xb6\xc0\xbb'), '\uc36c \ub9c8\uc744') self.assertEqual(decoder.decode(b''), '') def test_dbcs_keep_buffer(self): decoder = codecs.getincrementaldecoder('cp949')() self.assertEqual(decoder.decode(b'\xc6\xc4\xc0'), '\ud30c') self.assertRaises(UnicodeDecodeError, decoder.decode, b'', True) self.assertEqual(decoder.decode(b'\xcc'), '\uc774') self.assertEqual(decoder.decode(b'\xc6\xc4\xc0'), '\ud30c') self.assertRaises(UnicodeDecodeError, decoder.decode, b'\xcc\xbd', True) self.assertEqual(decoder.decode(b'\xcc'), '\uc774') def test_iso2022(self): decoder = codecs.getincrementaldecoder('iso2022-jp')() ESC = b'\x1b' self.assertEqual(decoder.decode(ESC + b'('), '') self.assertEqual(decoder.decode(b'B', True), '') self.assertEqual(decoder.decode(ESC + b'$'), '') self.assertEqual(decoder.decode(b'B@$'), '\u4e16') self.assertEqual(decoder.decode(b'@$@'), '\u4e16') self.assertEqual(decoder.decode(b'$', True), '\u4e16') self.assertEqual(decoder.reset(), None) self.assertEqual(decoder.decode(b'@$'), '@$') self.assertEqual(decoder.decode(ESC + b'$'), '') self.assertRaises(UnicodeDecodeError, decoder.decode, b'', True) self.assertEqual(decoder.decode(b'B@$'), '\u4e16') def test_decode_unicode(self): # Trying to decode a unicode string should raise a TypeError for enc in ALL_CJKENCODINGS: decoder = codecs.getincrementaldecoder(enc)() self.assertRaises(TypeError, decoder.decode, "") def test_state_methods(self): decoder = codecs.getincrementaldecoder('euc_jp')() # Decode a complete input sequence self.assertEqual(decoder.decode(b'\xa4\xa6'), '\u3046') pending1, _ = decoder.getstate() self.assertEqual(pending1, b'') # Decode first half of a partial input sequence self.assertEqual(decoder.decode(b'\xa4'), '') pending2, flags2 = decoder.getstate() self.assertEqual(pending2, b'\xa4') # Decode second half of a partial input sequence self.assertEqual(decoder.decode(b'\xa6'), '\u3046') pending3, _ = decoder.getstate() self.assertEqual(pending3, b'') # Jump back and decode second half of partial input sequence again decoder.setstate((pending2, flags2)) self.assertEqual(decoder.decode(b'\xa6'), '\u3046') pending4, _ = decoder.getstate() self.assertEqual(pending4, b'') # Ensure state values are preserved correctly decoder.setstate((b'abc', 123456789)) self.assertEqual(decoder.getstate(), (b'abc', 123456789)) def test_setstate_validates_input(self): decoder = codecs.getincrementaldecoder('euc_jp')() self.assertRaises(TypeError, decoder.setstate, 123) self.assertRaises(TypeError, decoder.setstate, ("invalid", 0)) self.assertRaises(TypeError, decoder.setstate, (b"1234", "invalid")) self.assertRaises(UnicodeError, decoder.setstate, (b"123456789", 0)) class Test_StreamReader(unittest.TestCase): def test_bug1728403(self): try: f = open(TESTFN, 'wb') try: f.write(b'\xa1') finally: f.close() f = codecs.open(TESTFN, encoding='cp949') try: self.assertRaises(UnicodeDecodeError, f.read, 2) finally: f.close() finally: os_helper.unlink(TESTFN) class Test_StreamWriter(unittest.TestCase): def test_gb18030(self): s= io.BytesIO() c = codecs.getwriter('gb18030')(s) c.write('123') self.assertEqual(s.getvalue(), b'123') c.write('\U00012345') self.assertEqual(s.getvalue(), b'123\x907\x959') c.write('\uac00\u00ac') self.assertEqual(s.getvalue(), b'123\x907\x959\x827\xcf5\x810\x851') def test_utf_8(self): s= io.BytesIO() c = codecs.getwriter('utf-8')(s) c.write('123') self.assertEqual(s.getvalue(), b'123') c.write('\U00012345') self.assertEqual(s.getvalue(), b'123\xf0\x92\x8d\x85') c.write('\uac00\u00ac') self.assertEqual(s.getvalue(), b'123\xf0\x92\x8d\x85' b'\xea\xb0\x80\xc2\xac') def test_streamwriter_strwrite(self): s = io.BytesIO() wr = codecs.getwriter('gb18030')(s) wr.write('abcd') self.assertEqual(s.getvalue(), b'abcd') class Test_ISO2022(unittest.TestCase): def test_g2(self): iso2022jp2 = b'\x1b(B:hu4:unit\x1b.A\x1bNi de famille' uni = ':hu4:unit\xe9 de famille' self.assertEqual(iso2022jp2.decode('iso2022-jp-2'), uni) def test_iso2022_jp_g0(self): self.assertNotIn(b'\x0e', '\N{SOFT HYPHEN}'.encode('iso-2022-jp-2')) for encoding in ('iso-2022-jp-2004', 'iso-2022-jp-3'): e = '\u3406'.encode(encoding) self.assertFalse(any(x > 0x80 for x in e)) @support.requires_resource('cpu') def test_bug1572832(self): for x in range(0x10000, 0x110000): # Any ISO 2022 codec will cause the segfault chr(x).encode('iso_2022_jp', 'ignore') class TestStateful(unittest.TestCase): text = '\u4E16\u4E16' encoding = 'iso-2022-jp' expected = b'\x1b$B@$@$' reset = b'\x1b(B' expected_reset = expected + reset def test_encode(self): self.assertEqual(self.text.encode(self.encoding), self.expected_reset) def test_incrementalencoder(self): encoder = codecs.getincrementalencoder(self.encoding)() output = b''.join( encoder.encode(char) for char in self.text) self.assertEqual(output, self.expected) self.assertEqual(encoder.encode('', final=True), self.reset) self.assertEqual(encoder.encode('', final=True), b'') def test_incrementalencoder_final(self): encoder = codecs.getincrementalencoder(self.encoding)() last_index = len(self.text) - 1 output = b''.join( encoder.encode(char, index == last_index) for index, char in enumerate(self.text)) self.assertEqual(output, self.expected_reset) self.assertEqual(encoder.encode('', final=True), b'') class TestHZStateful(TestStateful): text = '\u804a\u804a' encoding = 'hz' expected = b'~{ADAD' reset = b'~}' expected_reset = expected + reset if __name__ == "__main__": unittest.main()
SIMPAN PERUBAHAN