python-fastbencode_0.2.orig/CODE_OF_CONDUCT.md0000644000000000000000000000642714107676256015744 0ustar00# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at core@breezy-vcs.org. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq python-fastbencode_0.2.orig/COPYING0000644000000000000000000004325414107676256014177 0ustar00 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. python-fastbencode_0.2.orig/MANIFEST.in0000644000000000000000000000016614371716464014674 0ustar00include README.md include COPYING include fastbencode/py.typed recursive-include fastbencode *.py *.pyx *.pxd *.h *.c python-fastbencode_0.2.orig/PKG-INFO0000644000000000000000000000320614371716464014231 0ustar00Metadata-Version: 2.1 Name: fastbencode Version: 0.2 Summary: Implementation of bencode with optional fast C extensions Home-page: https://github.com/breezy-team/fastbencode Maintainer: Breezy Developers Maintainer-email: breezy-core@googlegroups.com License: GPLv2 or later Project-URL: GitHub, https://github.com/breezy-team/fastbencode Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: POSIX Classifier: Operating System :: Microsoft :: Windows Requires-Python: >=3.7 Provides-Extra: cext License-File: COPYING fastbencode =========== fastbencode is an implementation of the bencode serialization format originally used by BitTorrent. The package includes both a pure-Python version and an optional C extension based on Cython. Both provide the same functionality, but the C extension provides significantly better performance. Example: >>> from fastbencode import bencode, bdecode >>> bencode([1, 2, b'a', {b'd': 3}]) b'li1ei2e1:ad1:di3eee' >>> bdecode(bencode([1, 2, b'a', {b'd': 3}])) [1, 2, b'a', {b'd': 3}] License ======= fastbencode is available under the GNU GPL, version 2 or later. Copyright ========= * Original Pure-Python bencoder (c) Petru Paler * Cython version and modifications (c) Canonical Ltd * Split out from Bazaar/Breezy by Jelmer Vernooij python-fastbencode_0.2.orig/README.md0000644000000000000000000000141414313706046014401 0ustar00fastbencode =========== fastbencode is an implementation of the bencode serialization format originally used by BitTorrent. The package includes both a pure-Python version and an optional C extension based on Cython. Both provide the same functionality, but the C extension provides significantly better performance. Example: >>> from fastbencode import bencode, bdecode >>> bencode([1, 2, b'a', {b'd': 3}]) b'li1ei2e1:ad1:di3eee' >>> bdecode(bencode([1, 2, b'a', {b'd': 3}])) [1, 2, b'a', {b'd': 3}] License ======= fastbencode is available under the GNU GPL, version 2 or later. Copyright ========= * Original Pure-Python bencoder (c) Petru Paler * Cython version and modifications (c) Canonical Ltd * Split out from Bazaar/Breezy by Jelmer Vernooij python-fastbencode_0.2.orig/SECURITY.md0000644000000000000000000000016114107676256014723 0ustar00# Security Policy ## Reporting a Vulnerability Please report security issues by e-mail to core@breezy-vcs.org. python-fastbencode_0.2.orig/disperse.conf0000644000000000000000000000036314321336045015606 0ustar00# See https://github.com/jelmer/disperse timeout_days: 5 tag_name: "v$VERSION" verify_command: "python3 -m unittest fastbencode.tests.test_suite" update_version { path: "fastbencode/__init__.py" new_line: '__version__ = $TUPLED_VERSION' } python-fastbencode_0.2.orig/fastbencode.egg-info/0000755000000000000000000000000014371716464017102 5ustar00python-fastbencode_0.2.orig/fastbencode/0000755000000000000000000000000013775471110015401 5ustar00python-fastbencode_0.2.orig/pyproject.toml0000644000000000000000000000015614323732716016044 0ustar00[build-system] requires = ["setuptools", "cython>=0.29", "packaging"] build-backend = "setuptools.build_meta" python-fastbencode_0.2.orig/setup.cfg0000644000000000000000000000171414371716464014757 0ustar00[metadata] name = fastbencode description = Implementation of bencode with optional fast C extensions maintainer = Breezy Developers maintainer_email = breezy-core@googlegroups.com url = https://github.com/breezy-team/fastbencode long_description = file:README.md license = GPLv2 or later version = attr:fastbencode.__version__ project_urls = GitHub = https://github.com/breezy-team/fastbencode classifiers = Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: Implementation :: CPython Programming Language :: Python :: Implementation :: PyPy Operating System :: POSIX Operating System :: Microsoft :: Windows [options] python_requires = >=3.7 packages = fastbencode setup_requires = cython>=0.29 [options.extras_require] cext = cython>=0.29 [egg_info] tag_build = tag_date = 0 python-fastbencode_0.2.orig/setup.py0000755000000000000000000000530314371716464014651 0ustar00#!/usr/bin/python3 import os import sys from setuptools import setup, Extension try: from packaging.version import Version except ImportError: from distutils.version import LooseVersion as Version try: from Cython.Distutils import build_ext from Cython.Compiler.Version import version as cython_version except ImportError: have_cython = False # try to build the extension from the prior generated source. print("") print("The python package 'Cython' is not available." " If the .c files are available,") print("they will be built," " but modifying the .pyx files will not rebuild them.") print("") from distutils.command.build_ext import build_ext else: minimum_cython_version = '0.29' cython_version_info = Version(cython_version) if cython_version_info < Version(minimum_cython_version): print("Version of Cython is too old. " "Current is %s, need at least %s." % (cython_version, minimum_cython_version)) print("If the .c files are available, they will be built," " but modifying the .pyx files will not rebuild them.") have_cython = False else: have_cython = True ext_modules = [] def add_cython_extension(module_name, libraries=None, extra_source=[]): """Add a cython module to build. This will use Cython to auto-generate the .c file if it is available. Otherwise it will fall back on the .c file. If the .c file is not available, it will warn, and not add anything. You can pass any extra options to Extension through kwargs. One example is 'libraries = []'. :param module_name: The python path to the module. This will be used to determine the .pyx and .c files to use. """ path = module_name.replace('.', '/') cython_name = path + '.pyx' c_name = path + '.c' define_macros = [] if sys.platform == 'win32': # cython uses the macro WIN32 to detect the platform, even though it # should be using something like _WIN32 or MS_WINDOWS, oh well, we can # give it the right value. define_macros.append(('WIN32', None)) if have_cython: source = [cython_name] else: if not os.path.isfile(c_name): return else: source = [c_name] source.extend(extra_source) include_dirs = ['fastbencode'] ext_modules.append( Extension( module_name, source, define_macros=define_macros, libraries=libraries, include_dirs=include_dirs, optional=os.environ.get('CIBUILDWHEEL', '0') != '1')) add_cython_extension('fastbencode._bencode_pyx') setup(ext_modules=ext_modules, cmdclass={'build_ext': build_ext}) python-fastbencode_0.2.orig/fastbencode.egg-info/PKG-INFO0000644000000000000000000000320614371716464020200 0ustar00Metadata-Version: 2.1 Name: fastbencode Version: 0.2 Summary: Implementation of bencode with optional fast C extensions Home-page: https://github.com/breezy-team/fastbencode Maintainer: Breezy Developers Maintainer-email: breezy-core@googlegroups.com License: GPLv2 or later Project-URL: GitHub, https://github.com/breezy-team/fastbencode Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: POSIX Classifier: Operating System :: Microsoft :: Windows Requires-Python: >=3.7 Provides-Extra: cext License-File: COPYING fastbencode =========== fastbencode is an implementation of the bencode serialization format originally used by BitTorrent. The package includes both a pure-Python version and an optional C extension based on Cython. Both provide the same functionality, but the C extension provides significantly better performance. Example: >>> from fastbencode import bencode, bdecode >>> bencode([1, 2, b'a', {b'd': 3}]) b'li1ei2e1:ad1:di3eee' >>> bdecode(bencode([1, 2, b'a', {b'd': 3}])) [1, 2, b'a', {b'd': 3}] License ======= fastbencode is available under the GNU GPL, version 2 or later. Copyright ========= * Original Pure-Python bencoder (c) Petru Paler * Cython version and modifications (c) Canonical Ltd * Split out from Bazaar/Breezy by Jelmer Vernooij python-fastbencode_0.2.orig/fastbencode.egg-info/SOURCES.txt0000644000000000000000000000120514371716464020764 0ustar00.gitignore CODE_OF_CONDUCT.md COPYING MANIFEST.in README.md SECURITY.md disperse.conf pyproject.toml setup.cfg setup.py .github/workflows/disperse.yml .github/workflows/pythonpackage.yml .github/workflows/pythonpublish.yml fastbencode/__init__.py fastbencode/_bencode_py.py fastbencode/_bencode_pyx.h fastbencode/_bencode_pyx.pyi fastbencode/_bencode_pyx.pyx fastbencode/py.typed fastbencode/python-compat.h fastbencode.egg-info/PKG-INFO fastbencode.egg-info/SOURCES.txt fastbencode.egg-info/dependency_links.txt fastbencode.egg-info/requires.txt fastbencode.egg-info/top_level.txt fastbencode/tests/__init__.py fastbencode/tests/test_bencode.pypython-fastbencode_0.2.orig/fastbencode.egg-info/dependency_links.txt0000644000000000000000000000000114371716464023150 0ustar00 python-fastbencode_0.2.orig/fastbencode.egg-info/requires.txt0000644000000000000000000000002514371716464021477 0ustar00 [cext] cython>=0.29 python-fastbencode_0.2.orig/fastbencode.egg-info/top_level.txt0000644000000000000000000000001414371716464021627 0ustar00fastbencode python-fastbencode_0.2.orig/fastbencode/__init__.py0000644000000000000000000000450414371716464017524 0ustar00# Copyright (C) 2007, 2009 Canonical Ltd # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Wrapper around the bencode cython and python implementation""" from typing import Type __version__ = (0, 2) _extension_load_failures = [] def failed_to_load_extension(exception): """Handle failing to load a binary extension. This should be called from the ImportError block guarding the attempt to import the native extension. If this function returns, the pure-Python implementation should be loaded instead:: >>> try: >>> import _fictional_extension_pyx >>> except ImportError, e: >>> failed_to_load_extension(e) >>> import _fictional_extension_py """ # NB: This docstring is just an example, not a doctest, because doctest # currently can't cope with the use of lazy imports in this namespace -- # mbp 20090729 # This currently doesn't report the failure at the time it occurs, because # they tend to happen very early in startup when we can't check config # files etc, and also we want to report all failures but not spam the user # with 10 warnings. exception_str = str(exception) if exception_str not in _extension_load_failures: import warnings warnings.warn( 'failed to load compiled extension: %s' % exception_str, UserWarning) _extension_load_failures.append(exception_str) Bencached: Type try: from ._bencode_pyx import bdecode, bdecode_as_tuple, bencode, Bencached except ImportError as e: failed_to_load_extension(e) from ._bencode_py import ( # noqa: F401 bdecode, bdecode_as_tuple, bencode, Bencached, ) python-fastbencode_0.2.orig/fastbencode/_bencode_py.py0000644000000000000000000001042014313706046020214 0ustar00# bencode structured encoding # # Written by Petru Paler # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # Modifications copyright (C) 2008 Canonical Ltd from typing import Dict, Type, Callable, List class BDecoder(object): def __init__(self, yield_tuples=False): """Constructor. :param yield_tuples: if true, decode "l" elements as tuples rather than lists. """ self.yield_tuples = yield_tuples decode_func = {} decode_func[b'l'] = self.decode_list decode_func[b'd'] = self.decode_dict decode_func[b'i'] = self.decode_int decode_func[b'0'] = self.decode_string decode_func[b'1'] = self.decode_string decode_func[b'2'] = self.decode_string decode_func[b'3'] = self.decode_string decode_func[b'4'] = self.decode_string decode_func[b'5'] = self.decode_string decode_func[b'6'] = self.decode_string decode_func[b'7'] = self.decode_string decode_func[b'8'] = self.decode_string decode_func[b'9'] = self.decode_string self.decode_func = decode_func def decode_int(self, x, f): f += 1 newf = x.index(b'e', f) n = int(x[f:newf]) if x[f:f + 2] == b'-0': raise ValueError elif x[f:f + 1] == b'0' and newf != f + 1: raise ValueError return (n, newf + 1) def decode_string(self, x, f): colon = x.index(b':', f) n = int(x[f:colon]) if x[f:f + 1] == b'0' and colon != f + 1: raise ValueError colon += 1 return (x[colon:colon + n], colon + n) def decode_list(self, x, f): r, f = [], f + 1 while x[f:f + 1] != b'e': v, f = self.decode_func[x[f:f + 1]](x, f) r.append(v) if self.yield_tuples: r = tuple(r) return (r, f + 1) def decode_dict(self, x, f): r, f = {}, f + 1 lastkey = None while x[f:f + 1] != b'e': k, f = self.decode_string(x, f) if lastkey is not None and lastkey >= k: raise ValueError lastkey = k r[k], f = self.decode_func[x[f:f + 1]](x, f) return (r, f + 1) def bdecode(self, x): if not isinstance(x, bytes): raise TypeError try: r, l = self.decode_func[x[:1]](x, 0) # noqa: E741 except (IndexError, KeyError, OverflowError) as e: raise ValueError(str(e)) if l != len(x): # noqa: E741 raise ValueError return r _decoder = BDecoder() bdecode = _decoder.bdecode _tuple_decoder = BDecoder(True) bdecode_as_tuple = _tuple_decoder.bdecode class Bencached(object): __slots__ = ['bencoded'] def __init__(self, s): self.bencoded = s def encode_bencached(x, r): r.append(x.bencoded) def encode_bool(x, r): encode_int(int(x), r) def encode_int(x, r): r.extend((b'i', int_to_bytes(x), b'e')) def encode_string(x, r): r.extend((int_to_bytes(len(x)), b':', x)) def encode_list(x, r): r.append(b'l') for i in x: encode_func[type(i)](i, r) r.append(b'e') def encode_dict(x, r): r.append(b'd') ilist = sorted(x.items()) for k, v in ilist: r.extend((int_to_bytes(len(k)), b':', k)) encode_func[type(v)](v, r) r.append(b'e') encode_func: Dict[Type, Callable[[object, List[bytes]], None]] = {} encode_func[type(Bencached(0))] = encode_bencached encode_func[int] = encode_int def int_to_bytes(n): return b'%d' % n encode_func[bytes] = encode_string encode_func[list] = encode_list encode_func[tuple] = encode_list encode_func[dict] = encode_dict encode_func[bool] = encode_bool def bencode(x): r = [] encode_func[type(x)](x, r) return b''.join(r) python-fastbencode_0.2.orig/fastbencode/_bencode_pyx.h0000644000000000000000000000173114107307344020207 0ustar00/* Copyright (C) 2009 Canonical Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Simple header providing some macro definitions for _bencode_pyx.pyx */ #define D_UPDATE_TAIL(self, n) (((self)->size -= (n), (self)->tail += (n))) #define E_UPDATE_TAIL(self, n) (((self)->size += (n), (self)->tail += (n))) python-fastbencode_0.2.orig/fastbencode/_bencode_pyx.pyi0000644000000000000000000000021714306114561020555 0ustar00 def bdecode(bytes) -> object: ... def bdecode_as_tuple(bytes) -> object: ... def bencode(object) -> bytes: ... class Bencached(object): ... python-fastbencode_0.2.orig/fastbencode/_bencode_pyx.pyx0000644000000000000000000002733514107303643020606 0ustar00# Copyright (C) 2007, 2009, 2010 Canonical Ltd # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # cython: language_level=3 """Pyrex implementation for bencode coder/decoder""" from cpython.bool cimport ( PyBool_Check, ) from cpython.bytes cimport ( PyBytes_CheckExact, PyBytes_FromStringAndSize, PyBytes_AS_STRING, PyBytes_GET_SIZE, ) from cpython.dict cimport ( PyDict_CheckExact, ) from cpython.int cimport ( PyInt_CheckExact, PyInt_FromString, ) from cpython.list cimport ( PyList_CheckExact, PyList_Append, ) from cpython.long cimport ( PyLong_CheckExact, ) from cpython.mem cimport ( PyMem_Free, PyMem_Malloc, PyMem_Realloc, ) from cpython.tuple cimport ( PyTuple_CheckExact, ) from libc.stdlib cimport ( strtol, ) from libc.string cimport ( memcpy, ) cdef extern from "python-compat.h": int snprintf(char* buffer, size_t nsize, char* fmt, ...) # Use wrapper with inverted error return so Cython can propogate int BrzPy_EnterRecursiveCall(char *) except 0 cdef extern from "Python.h": void Py_LeaveRecursiveCall() cdef class Decoder cdef class Encoder cdef extern from "_bencode_pyx.h": void D_UPDATE_TAIL(Decoder, int n) void E_UPDATE_TAIL(Encoder, int n) cdef class Decoder: """Bencode decoder""" cdef readonly char *tail cdef readonly int size cdef readonly int _yield_tuples cdef object text def __init__(self, s, yield_tuples=0): """Initialize decoder engine. @param s: Python string. """ if not PyBytes_CheckExact(s): raise TypeError("bytes required") self.text = s self.tail = PyBytes_AS_STRING(s) self.size = PyBytes_GET_SIZE(s) self._yield_tuples = int(yield_tuples) def decode(self): result = self._decode_object() if self.size != 0: raise ValueError('junk in stream') return result def decode_object(self): return self._decode_object() cdef object _decode_object(self): cdef char ch if 0 == self.size: raise ValueError('stream underflow') BrzPy_EnterRecursiveCall(" while bencode decoding") try: ch = self.tail[0] if c'0' <= ch <= c'9': return self._decode_string() elif ch == c'l': D_UPDATE_TAIL(self, 1) return self._decode_list() elif ch == c'i': D_UPDATE_TAIL(self, 1) return self._decode_int() elif ch == c'd': D_UPDATE_TAIL(self, 1) return self._decode_dict() finally: Py_LeaveRecursiveCall() raise ValueError('unknown object type identifier %r' % ch) cdef int _read_digits(self, char stop_char) except -1: cdef int i i = 0 while ((self.tail[i] >= c'0' and self.tail[i] <= c'9') or self.tail[i] == c'-') and i < self.size: i = i + 1 if self.tail[i] != stop_char: raise ValueError("Stop character %c not found: %c" % (stop_char, self.tail[i])) if (self.tail[0] == c'0' or (self.tail[0] == c'-' and self.tail[1] == c'0')): if i == 1: return i else: raise ValueError # leading zeroes are not allowed return i cdef object _decode_int(self): cdef int i i = self._read_digits(c'e') self.tail[i] = 0 try: ret = PyInt_FromString(self.tail, NULL, 10) finally: self.tail[i] = c'e' D_UPDATE_TAIL(self, i+1) return ret cdef object _decode_string(self): cdef int n cdef char *next_tail # strtol allows leading whitespace, negatives, and leading zeros # however, all callers have already checked that '0' <= tail[0] <= '9' # or they wouldn't have called _decode_string # strtol will stop at trailing whitespace, etc n = strtol(self.tail, &next_tail, 10) if next_tail == NULL or next_tail[0] != c':': raise ValueError('string len not terminated by ":"') # strtol allows leading zeros, so validate that we don't have that if (self.tail[0] == c'0' and (n != 0 or (next_tail - self.tail != 1))): raise ValueError('leading zeros are not allowed') D_UPDATE_TAIL(self, next_tail - self.tail + 1) if n == 0: return b'' if n > self.size: raise ValueError('stream underflow') if n < 0: raise ValueError('string size below zero: %d' % n) result = PyBytes_FromStringAndSize(self.tail, n) D_UPDATE_TAIL(self, n) return result cdef object _decode_list(self): result = [] while self.size > 0: if self.tail[0] == c'e': D_UPDATE_TAIL(self, 1) if self._yield_tuples: return tuple(result) else: return result else: # As a quick shortcut, check to see if the next object is a # string, since we know that won't be creating recursion # if self.tail[0] >= c'0' and self.tail[0] <= c'9': PyList_Append(result, self._decode_object()) raise ValueError('malformed list') cdef object _decode_dict(self): cdef char ch result = {} lastkey = None while self.size > 0: ch = self.tail[0] if ch == c'e': D_UPDATE_TAIL(self, 1) return result else: # keys should be strings only if self.tail[0] < c'0' or self.tail[0] > c'9': raise ValueError('key was not a simple string.') key = self._decode_string() if lastkey is not None and lastkey >= key: raise ValueError('dict keys disordered') else: lastkey = key value = self._decode_object() result[key] = value raise ValueError('malformed dict') def bdecode(object s): """Decode string x to Python object""" return Decoder(s).decode() def bdecode_as_tuple(object s): """Decode string x to Python object, using tuples rather than lists.""" return Decoder(s, True).decode() class Bencached(object): __slots__ = ['bencoded'] def __init__(self, s): self.bencoded = s cdef enum: INITSIZE = 1024 # initial size for encoder buffer INT_BUF_SIZE = 32 cdef class Encoder: """Bencode encoder""" cdef readonly char *tail cdef readonly int size cdef readonly char *buffer cdef readonly int maxsize def __init__(self, int maxsize=INITSIZE): """Initialize encoder engine @param maxsize: initial size of internal char buffer """ cdef char *p self.maxsize = 0 self.size = 0 self.tail = NULL p = PyMem_Malloc(maxsize) if p == NULL: raise MemoryError('Not enough memory to allocate buffer ' 'for encoder') self.buffer = p self.maxsize = maxsize self.tail = p def __dealloc__(self): PyMem_Free(self.buffer) self.buffer = NULL self.maxsize = 0 def to_bytes(self): if self.buffer != NULL and self.size != 0: return PyBytes_FromStringAndSize(self.buffer, self.size) return b'' cdef int _ensure_buffer(self, int required) except 0: """Ensure that tail of CharTail buffer has enough size. If buffer is not big enough then function try to realloc buffer. """ cdef char *new_buffer cdef int new_size if self.size + required < self.maxsize: return 1 new_size = self.maxsize while new_size < self.size + required: new_size = new_size * 2 new_buffer = PyMem_Realloc(self.buffer, new_size) if new_buffer == NULL: raise MemoryError('Cannot realloc buffer for encoder') self.buffer = new_buffer self.maxsize = new_size self.tail = &new_buffer[self.size] return 1 cdef int _encode_int(self, int x) except 0: """Encode int to bencode string iNNNe @param x: value to encode """ cdef int n self._ensure_buffer(INT_BUF_SIZE) n = snprintf(self.tail, INT_BUF_SIZE, b"i%de", x) if n < 0: raise MemoryError('int %d too big to encode' % x) E_UPDATE_TAIL(self, n) return 1 cdef int _encode_long(self, x) except 0: return self._append_string(b'i%de' % x) cdef int _append_string(self, s) except 0: cdef Py_ssize_t n n = PyBytes_GET_SIZE(s) self._ensure_buffer(n) memcpy(self.tail, PyBytes_AS_STRING(s), n) E_UPDATE_TAIL(self, n) return 1 cdef int _encode_string(self, x) except 0: cdef int n cdef Py_ssize_t x_len x_len = PyBytes_GET_SIZE(x) self._ensure_buffer(x_len + INT_BUF_SIZE) n = snprintf(self.tail, INT_BUF_SIZE, b'%ld:', x_len) if n < 0: raise MemoryError('string %s too big to encode' % x) memcpy((self.tail+n), PyBytes_AS_STRING(x), x_len) E_UPDATE_TAIL(self, n + x_len) return 1 cdef int _encode_list(self, x) except 0: self._ensure_buffer(1) self.tail[0] = c'l' E_UPDATE_TAIL(self, 1) for i in x: self.process(i) self._ensure_buffer(1) self.tail[0] = c'e' E_UPDATE_TAIL(self, 1) return 1 cdef int _encode_dict(self, x) except 0: self._ensure_buffer(1) self.tail[0] = c'd' E_UPDATE_TAIL(self, 1) for k in sorted(x): if not PyBytes_CheckExact(k): raise TypeError('key in dict should be string') self._encode_string(k) self.process(x[k]) self._ensure_buffer(1) self.tail[0] = c'e' E_UPDATE_TAIL(self, 1) return 1 cpdef object process(self, object x): BrzPy_EnterRecursiveCall(" while bencode encoding") try: if PyBytes_CheckExact(x): self._encode_string(x) elif PyInt_CheckExact(x) and x.bit_length() < 32: self._encode_int(x) elif PyLong_CheckExact(x): self._encode_long(x) elif PyList_CheckExact(x) or PyTuple_CheckExact(x): self._encode_list(x) elif PyDict_CheckExact(x): self._encode_dict(x) elif PyBool_Check(x): self._encode_int(int(x)) elif isinstance(x, Bencached): self._append_string(x.bencoded) else: raise TypeError('unsupported type %r' % x) finally: Py_LeaveRecursiveCall() def bencode(x): """Encode Python object x to string""" encoder = Encoder() encoder.process(x) return encoder.to_bytes() python-fastbencode_0.2.orig/fastbencode/py.typed0000644000000000000000000000000014306114561017061 0ustar00python-fastbencode_0.2.orig/fastbencode/python-compat.h0000644000000000000000000000163714313706046020361 0ustar00/* * Bazaar -- distributed version control * * Copyright (C) 2008 by Canonical Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef BrzPy_EnterRecursiveCall #define BrzPy_EnterRecursiveCall(where) (Py_EnterRecursiveCall(where) == 0) #endif python-fastbencode_0.2.orig/fastbencode/tests/0000755000000000000000000000000014107303643016536 5ustar00python-fastbencode_0.2.orig/fastbencode/tests/__init__.py0000644000000000000000000000211714107303643020650 0ustar00# Copyright (C) 2007, 2009, 2010 Canonical Ltd # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # """Tests for fastbencode.""" import unittest def test_suite(): names = [ 'test_bencode', ] module_names = ['fastbencode.tests.' + name for name in names] result = unittest.TestSuite() loader = unittest.TestLoader() suite = loader.loadTestsFromNames(module_names) result.addTests(suite) return result python-fastbencode_0.2.orig/fastbencode/tests/test_bencode.py0000644000000000000000000003604414371716464021571 0ustar00# Copyright (C) 2007, 2009, 2010, 2016 Canonical Ltd # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """Tests for bencode structured encoding""" import copy import sys from unittest import TestCase, TestSuite def get_named_object(module_name, member_name=None): """Get the Python object named by a given module and member name. This is usually much more convenient than dealing with ``__import__`` directly:: >>> doc = get_named_object('pyutils', 'get_named_object.__doc__') >>> doc.splitlines()[0] 'Get the Python object named by a given module and member name.' :param module_name: a module name, as would be found in sys.modules if the module is already imported. It may contain dots. e.g. 'sys' or 'os.path'. :param member_name: (optional) a name of an attribute in that module to return. It may contain dots. e.g. 'MyClass.some_method'. If not given, the named module will be returned instead. :raises: ImportError or AttributeError. """ # We may have just a module name, or a module name and a member name, # and either may contain dots. __import__'s return value is a bit # unintuitive, so we need to take care to always return the object # specified by the full combination of module name + member name. if member_name: # Give __import__ a from_list. It will return the last module in # the dotted module name. attr_chain = member_name.split('.') from_list = attr_chain[:1] obj = __import__(module_name, {}, {}, from_list) for attr in attr_chain: obj = getattr(obj, attr) else: # We're just importing a module, no attributes, so we have no # from_list. __import__ will return the first module in the dotted # module name, so we look up the module from sys.modules. __import__(module_name, globals(), locals(), []) obj = sys.modules[module_name] return obj def iter_suite_tests(suite): """Return all tests in a suite, recursing through nested suites""" if isinstance(suite, TestCase): yield suite elif isinstance(suite, TestSuite): for item in suite: yield from iter_suite_tests(item) else: raise Exception('unknown type %r for object %r' % (type(suite), suite)) def clone_test(test, new_id): """Clone a test giving it a new id. :param test: The test to clone. :param new_id: The id to assign to it. :return: The new test. """ new_test = copy.copy(test) new_test.id = lambda: new_id # XXX: Workaround , which # causes cloned tests to share the 'details' dict. This makes it hard to # read the test output for parameterized tests, because tracebacks will be # associated with irrelevant tests. try: new_test._TestCase__details except AttributeError: # must be a different version of testtools than expected. Do nothing. pass else: # Reset the '__details' dict. new_test._TestCase__details = {} return new_test def apply_scenario(test, scenario): """Copy test and apply scenario to it. :param test: A test to adapt. :param scenario: A tuple describing the scenario. The first element of the tuple is the new test id. The second element is a dict containing attributes to set on the test. :return: The adapted test. """ new_id = "{}({})".format(test.id(), scenario[0]) new_test = clone_test(test, new_id) for name, value in scenario[1].items(): setattr(new_test, name, value) return new_test def apply_scenarios(test, scenarios, result): """Apply the scenarios in scenarios to test and add to result. :param test: The test to apply scenarios to. :param scenarios: An iterable of scenarios to apply to test. :return: result :seealso: apply_scenario """ for scenario in scenarios: result.addTest(apply_scenario(test, scenario)) return result def multiply_tests(tests, scenarios, result): """Multiply tests_list by scenarios into result. This is the core workhorse for test parameterisation. Typically the load_tests() method for a per-implementation test suite will call multiply_tests and return the result. :param tests: The tests to parameterise. :param scenarios: The scenarios to apply: pairs of (scenario_name, scenario_param_dict). :param result: A TestSuite to add created tests to. This returns the passed in result TestSuite with the cross product of all the tests repeated once for each scenario. Each test is adapted by adding the scenario name at the end of its id(), and updating the test object's __dict__ with the scenario_param_dict. >>> import tests.test_sampler >>> r = multiply_tests( ... tests.test_sampler.DemoTest('test_nothing'), ... [('one', dict(param=1)), ... ('two', dict(param=2))], ... TestUtil.TestSuite()) >>> tests = list(iter_suite_tests(r)) >>> len(tests) 2 >>> tests[0].id() 'tests.test_sampler.DemoTest.test_nothing(one)' >>> tests[0].param 1 >>> tests[1].param 2 """ for test in iter_suite_tests(tests): apply_scenarios(test, scenarios, result) return result def permute_tests_for_extension(standard_tests, loader, py_module_name, ext_module_name): """Helper for permutating tests against an extension module. This is meant to be used inside a modules 'load_tests()' function. It will create 2 scenarios, and cause all tests in the 'standard_tests' to be run against both implementations. Setting 'test.module' to the appropriate module. See tests.test__chk_map.load_tests as an example. :param standard_tests: A test suite to permute :param loader: A TestLoader :param py_module_name: The python path to a python module that can always be loaded, and will be considered the 'python' implementation. (eg '_chk_map_py') :param ext_module_name: The python path to an extension module. If the module cannot be loaded, a single test will be added, which notes that the module is not available. If it can be loaded, all standard_tests will be run against that module. :return: (suite, feature) suite is a test-suite that has all the permuted tests. feature is the Feature object that can be used to determine if the module is available. """ py_module = get_named_object(py_module_name) scenarios = [ ('python', {'module': py_module}), ] suite = loader.suiteClass() try: __import__(ext_module_name) except ModuleNotFoundError: pass else: scenarios.append(('C', {'module': get_named_object(ext_module_name)})) result = multiply_tests(standard_tests, scenarios, suite) return result def load_tests(loader, standard_tests, pattern): return permute_tests_for_extension( standard_tests, loader, 'fastbencode._bencode_py', 'fastbencode._bencode_pyx') class RecursionLimit: """Context manager that lowers recursion limit for testing.""" def __init__(self, limit=100): self._new_limit = limit self._old_limit = sys.getrecursionlimit() def __enter__(self): sys.setrecursionlimit(self._new_limit) return self def __exit__(self, *exc_info): sys.setrecursionlimit(self._old_limit) class TestBencodeDecode(TestCase): module = None def _check(self, expected, source): self.assertEqual(expected, self.module.bdecode(source)) def _run_check_error(self, exc, bad): """Check that bdecoding a string raises a particular exception.""" self.assertRaises(exc, self.module.bdecode, bad) def test_int(self): self._check(0, b'i0e') self._check(4, b'i4e') self._check(123456789, b'i123456789e') self._check(-10, b'i-10e') self._check(int('1' * 1000), b'i' + (b'1' * 1000) + b'e') def test_long(self): self._check(12345678901234567890, b'i12345678901234567890e') self._check(-12345678901234567890, b'i-12345678901234567890e') def test_malformed_int(self): self._run_check_error(ValueError, b'ie') self._run_check_error(ValueError, b'i-e') self._run_check_error(ValueError, b'i-010e') self._run_check_error(ValueError, b'i-0e') self._run_check_error(ValueError, b'i00e') self._run_check_error(ValueError, b'i01e') self._run_check_error(ValueError, b'i-03e') self._run_check_error(ValueError, b'i') self._run_check_error(ValueError, b'i123') self._run_check_error(ValueError, b'i341foo382e') def test_string(self): self._check(b'', b'0:') self._check(b'abc', b'3:abc') self._check(b'1234567890', b'10:1234567890') def test_large_string(self): self.assertRaises(ValueError, self.module.bdecode, b"2147483639:foo") def test_malformed_string(self): self._run_check_error(ValueError, b'10:x') self._run_check_error(ValueError, b'10:') self._run_check_error(ValueError, b'10') self._run_check_error(ValueError, b'01:x') self._run_check_error(ValueError, b'00:') self._run_check_error(ValueError, b'35208734823ljdahflajhdf') self._run_check_error(ValueError, b'432432432432432:foo') self._run_check_error(ValueError, b' 1:x') # leading whitespace self._run_check_error(ValueError, b'-1:x') # negative self._run_check_error(ValueError, b'1 x') # space vs colon self._run_check_error(ValueError, b'1x') # missing colon self._run_check_error(ValueError, (b'1' * 1000) + b':') def test_list(self): self._check([], b'le') self._check([b'', b'', b''], b'l0:0:0:e') self._check([1, 2, 3], b'li1ei2ei3ee') self._check([b'asd', b'xy'], b'l3:asd2:xye') self._check([[b'Alice', b'Bob'], [2, 3]], b'll5:Alice3:Bobeli2ei3eee') def test_list_deepnested(self): import platform if platform.python_implementation() == 'PyPy': self.skipTest('recursion not an issue on pypy') with RecursionLimit(): self._run_check_error(RuntimeError, (b"l" * 100) + (b"e" * 100)) def test_malformed_list(self): self._run_check_error(ValueError, b'l') self._run_check_error(ValueError, b'l01:ae') self._run_check_error(ValueError, b'l0:') self._run_check_error(ValueError, b'li1e') self._run_check_error(ValueError, b'l-3:e') def test_dict(self): self._check({}, b'de') self._check({b'': 3}, b'd0:i3ee') self._check({b'age': 25, b'eyes': b'blue'}, b'd3:agei25e4:eyes4:bluee') self._check({b'spam.mp3': {b'author': b'Alice', b'length': 100000}}, b'd8:spam.mp3d6:author5:Alice6:lengthi100000eee') def test_dict_deepnested(self): with RecursionLimit(): self._run_check_error( RuntimeError, (b"d0:" * 1000) + b'i1e' + (b"e" * 1000)) def test_malformed_dict(self): self._run_check_error(ValueError, b'd') self._run_check_error(ValueError, b'defoobar') self._run_check_error(ValueError, b'd3:fooe') self._run_check_error(ValueError, b'di1e0:e') self._run_check_error(ValueError, b'd1:b0:1:a0:e') self._run_check_error(ValueError, b'd1:a0:1:a0:e') self._run_check_error(ValueError, b'd0:0:') self._run_check_error(ValueError, b'd0:') self._run_check_error(ValueError, b'd432432432432432432:e') def test_empty_string(self): self.assertRaises(ValueError, self.module.bdecode, b'') def test_junk(self): self._run_check_error(ValueError, b'i6easd') self._run_check_error(ValueError, b'2:abfdjslhfld') self._run_check_error(ValueError, b'0:0:') self._run_check_error(ValueError, b'leanfdldjfh') def test_unknown_object(self): self.assertRaises(ValueError, self.module.bdecode, b'relwjhrlewjh') def test_unsupported_type(self): self._run_check_error(TypeError, float(1.5)) self._run_check_error(TypeError, None) self._run_check_error(TypeError, lambda x: x) self._run_check_error(TypeError, object) self._run_check_error(TypeError, "ie") def test_decoder_type_error(self): self.assertRaises(TypeError, self.module.bdecode, 1) class TestBencodeEncode(TestCase): module = None def _check(self, expected, source): self.assertEqual(expected, self.module.bencode(source)) def test_int(self): self._check(b'i4e', 4) self._check(b'i0e', 0) self._check(b'i-10e', -10) def test_long(self): self._check(b'i12345678901234567890e', 12345678901234567890) self._check(b'i-12345678901234567890e', -12345678901234567890) def test_string(self): self._check(b'0:', b'') self._check(b'3:abc', b'abc') self._check(b'10:1234567890', b'1234567890') def test_list(self): self._check(b'le', []) self._check(b'li1ei2ei3ee', [1, 2, 3]) self._check(b'll5:Alice3:Bobeli2ei3eee', [[b'Alice', b'Bob'], [2, 3]]) def test_list_as_tuple(self): self._check(b'le', ()) self._check(b'li1ei2ei3ee', (1, 2, 3)) self._check(b'll5:Alice3:Bobeli2ei3eee', ((b'Alice', b'Bob'), (2, 3))) def test_list_deep_nested(self): top = [] lst = top for unused_i in range(1000): lst.append([]) lst = lst[0] with RecursionLimit(): self.assertRaises(RuntimeError, self.module.bencode, top) def test_dict(self): self._check(b'de', {}) self._check(b'd3:agei25e4:eyes4:bluee', {b'age': 25, b'eyes': b'blue'}) self._check(b'd8:spam.mp3d6:author5:Alice6:lengthi100000eee', {b'spam.mp3': {b'author': b'Alice', b'length': 100000}}) def test_dict_deep_nested(self): d = top = {} for i in range(1000): d[b''] = {} d = d[b''] with RecursionLimit(): self.assertRaises(RuntimeError, self.module.bencode, top) def test_bencached(self): self._check(b'i3e', self.module.Bencached(self.module.bencode(3))) def test_invalid_dict(self): self.assertRaises(TypeError, self.module.bencode, {1: b"foo"}) def test_bool(self): self._check(b'i1e', True) self._check(b'i0e', False)