pax_global_header00006660000000000000000000000064140223406360014512gustar00rootroot0000000000000052 comment=3a4feda3414bde7b3386e995ed1d2ed36607d4cf fqdn-1.5.1/000077500000000000000000000000001402234063600124465ustar00rootroot00000000000000fqdn-1.5.1/.bumpversion.cfg000066400000000000000000000001751402234063600155610ustar00rootroot00000000000000[bumpversion] current_version = 1.5.1 commit = True tag = True [bumpversion:file:setup.py] [bumpversion:file:docs/conf.py] fqdn-1.5.1/.flake8000066400000000000000000000001571402234063600136240ustar00rootroot00000000000000[flake8] extend-ignore = E203, E266, E501 ;max-line-length = 80 max-complexity = 18 ;select = B,C,E,F,W,T4,B9 fqdn-1.5.1/.github/000077500000000000000000000000001402234063600140065ustar00rootroot00000000000000fqdn-1.5.1/.github/workflows/000077500000000000000000000000001402234063600160435ustar00rootroot00000000000000fqdn-1.5.1/.github/workflows/codeql-analysis.yml000066400000000000000000000044721402234063600216650ustar00rootroot00000000000000# For most projects, this workflow file will not need changing; you simply need # to commit it to your repository. # # You may wish to alter this file to override the set of languages analyzed, # or to provide custom queries or build logic. # # ******** NOTE ******** # We have attempted to detect the languages in your repository. Please check # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # name: "CodeQL" on: push: branches: [ develop ] pull_request: # The branches below must be a subset of the branches above branches: [ develop ] schedule: - cron: '19 9 * * 3' jobs: analyze: name: Analyze runs-on: ubuntu-latest strategy: fail-fast: false matrix: language: [ 'python' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] # Learn more: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: - name: Checkout repository uses: actions/checkout@v2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@v1 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project # uses a compiled language #- run: | # make bootstrap # make release - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 fqdn-1.5.1/.github/workflows/unit-tests.yml000066400000000000000000000030761402234063600207130ustar00rootroot00000000000000# This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: unit tests on: push: branches: [develop] pull_request: branches: [develop] jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, pypy3, pypy2] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install flake8 pytest pytest-cov . - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | cd tests && pytest --cov=./ --cov-report=xml - name: Upload Coverage Report uses: codecov/codecov-action@v1 with: files: tests/coverage.xml env_vars: OS,PYTHON name: codecov-umbrella fail_ci_if_error: true path_to_write_report: ./coverage/codecov_report.txt fqdn-1.5.1/.gitignore000066400000000000000000000003631402234063600144400ustar00rootroot00000000000000__pycache__ *.pyc .cache/ *.diff *.err *.orig *.log *~ .swp *.swp .DS_Store .cache *.pyc .DS_Store tags .tags .netrwhist /MANIFEST /dist /build /*.egg-info /.tox /htmlcov/ /docs/_build/ .coverage *,cover tests/__pycache__ *.pyc .cache/ .eggs fqdn-1.5.1/.mailmap000066400000000000000000000006461402234063600140750ustar00rootroot00000000000000ypcrts <32625281+ypcrts@users.noreply.github.com> ypcrts <32625281+ypcrts@users.noreply.github.com> wakemaster39 Cameron Hurst tednology Greg Dubicki James Alseth milahu fqdn-1.5.1/.pre-commit-config.yaml000066400000000000000000000004061402234063600167270ustar00rootroot00000000000000repos: - repo: https://github.com/psf/black rev: 20.8b1 hooks: - id: black language_version: python3 - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.1 hooks: - id: flake8 additional_dependencies: [flake8-bugbear] fqdn-1.5.1/.prospector.yml000066400000000000000000000005041402234063600154460ustar00rootroot00000000000000output-format: grouped strictness: veryhigh doc-warnings: true test-warnings: false max-line-length: 120 ignore-paths: - docs/ frosted: run: false pyroma: run: true pylint: disable: - bad-builtin - too-few-public-methods - missing-docstring - star-args pep8: full: true disable: - E126 fqdn-1.5.1/LICENSE000066400000000000000000000405251402234063600134610ustar00rootroot00000000000000Mozilla Public License Version 2.0 ================================== 1. Definitions -------------- 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. 1.3. "Contribution" means Covered Software of a particular Contributor. 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. 1.5. "Incompatible With Secondary Licenses" means (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. 1.6. "Executable Form" means any form of the work other than Source Code Form. 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 1.8. "License" means this document. 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. 1.10. "Modifications" means any of the following: (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or (b) any new file in Source Code Form that contains any Covered Software. 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. 1.13. "Source Code Form" means the form of the work preferred for making modifications. 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. License Grants and Conditions -------------------------------- 2.1. Grants Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. 2.2. Effective Date The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. 2.3. Limitations on Grant Scope The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: (a) for any code that a Contributor has removed from Covered Software; or (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). 2.4. Subsequent Licenses No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). 2.5. Representation Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. 2.6. Fair Use This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. 2.7. Conditions Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. 3. Responsibilities ------------------- 3.1. Distribution of Source Form All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. 3.2. Distribution of Executable Form If You distribute Covered Software in Executable Form then: (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. 3.3. Distribution of a Larger Work You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). 3.4. Notices You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. 3.5. Application of Additional Terms You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. 4. Inability to Comply Due to Statute or Regulation --------------------------------------------------- If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 5. Termination -------------- 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. ************************************************************************ * * * 6. Disclaimer of Warranty * * ------------------------- * * * * Covered Software is provided under this License on an "as is" * * basis, without warranty of any kind, either expressed, implied, or * * statutory, including, without limitation, warranties that the * * Covered Software is free of defects, merchantable, fit for a * * particular purpose or non-infringing. The entire risk as to the * * quality and performance of the Covered Software is with You. * * Should any Covered Software prove defective in any respect, You * * (not any Contributor) assume the cost of any necessary servicing, * * repair, or correction. This disclaimer of warranty constitutes an * * essential part of this License. No use of any Covered Software is * * authorized under this License except under this disclaimer. * * * ************************************************************************ ************************************************************************ * * * 7. Limitation of Liability * * -------------------------- * * * * Under no circumstances and under no legal theory, whether tort * * (including negligence), contract, or otherwise, shall any * * Contributor, or anyone who distributes Covered Software as * * permitted above, be liable to You for any direct, indirect, * * special, incidental, or consequential damages of any character * * including, without limitation, damages for lost profits, loss of * * goodwill, work stoppage, computer failure or malfunction, or any * * and all other commercial damages or losses, even if such party * * shall have been informed of the possibility of such damages. This * * limitation of liability shall not apply to liability for death or * * personal injury resulting from such party's negligence to the * * extent applicable law prohibits such limitation. Some * * jurisdictions do not allow the exclusion or limitation of * * incidental or consequential damages, so this exclusion and * * limitation may not apply to You. * * * ************************************************************************ 8. Litigation ------------- Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. 9. Miscellaneous ---------------- This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. 10. Versions of the License --------------------------- 10.1. New Versions Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. 10.2. Effect of New Versions You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. 10.3. Modified Versions If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice ------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. You may add additional accurate notices of copyright ownership. Exhibit B - "Incompatible With Secondary Licenses" Notice --------------------------------------------------------- This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. fqdn-1.5.1/README.rst000066400000000000000000000163661402234063600141510ustar00rootroot00000000000000.. ............................................................................. .. AMAZING REFERENCES .. ............................................................................. .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/fqdn.svg :target: https://pypi.org/project/fqdn/ .. |Build Status| image:: https://github.com/ypcrts/fqdn/actions/workflows/unit-tests.yml/badge.svg?branch=develop :target: https://github.com/ypcrts/fqdn/actions/workflows/unit-tests.tml?query=branch%3Adevelop .. |Coverage Status| image:: https://codecov.io/gh/ypcrts/fqdn/branch/develop/graph/badge.svg?token=cavArywW2X :target: https://codecov.io/gh/ypcrts/fqdn .. |Latest PyPI Version| image:: https://img.shields.io/pypi/v/fqdn.svg :target: https://pypi.python.org/pypi/fqdn .. |Downloads| image:: https://pepy.tech/badge/fqdn :target: https://pepy.tech/project/fqdn .. |Monthly Downloads| image:: https://pepy.tech/badge/fqdn/month :target: https://pepy.tech/project/fqdn/month .. |License Status| image:: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fypcrts%2Ffqdn.svg?type=shield :target: https://app.fossa.com/projects/git%2Bgithub.com%2Fypcrts%2Ffqdn?ref=badge_shield .. |License Status Shield| image:: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fypcrts%2Ffqdn.svg?type=large :target: https://app.fossa.com/projects/git%2Bgithub.com%2Fypcrts%2Ffqdn ================================================================================ Python FQDN Fully-Qualified Domain Names ================================================================================ |License Status| |Build Status| |Coverage Status| |Latest PyPI Version| |Downloads| |Monthly Downloads| |Python Versions| This package validates Fully Qualified Domain Names (FQDNs) conforming to the Internet Engineering Task Force specification [#spec]_. The design intent is to validate that a string would be traditionally acceptable as a public Internet hostname to RFC-conforming software, which is a strict subset of the logic in modern web browsers like Mozilla Firefox and Chromium that determines whether make a DNS lookup [#letsencrypt]_. Configuration options can relax constraints so that short hostnames without periods or others with underscores will be valid. These relaxations are closer to how modern web browsers work [#browsers]_ . >>> from fqdn import FQDN >>> domain = 'bbc.co.uk' >>> bbc_fqdn = FQDN(domain) >>> bbc_fqdn.is_valid True >>> bbc_fqdn.absolute 'bbc.co.uk.' >>> bbc_fqdn.relative 'bbc.co.uk' Equality checks are implemented case insensitive conforming to to the IETF specification [#equality]. >>> FQDN('BBC.CO.UK.') == FQDN('BbC.Co.uK') True >>> hash(FQDN('BBC.CO.UK.')) == hash(FQDN('BbC.Co.uK')) True .. [#spec] See `IETF Specification`_. .. [#letsencrypt] Certificate Authorities like Let's Encrypt run a narrower set of string validation logic to determine validity for issuance. This package is not intended to achieve functional parity with CA issuance, because they may have proprietary or custom login. `Boulder's code `_ is starkly different from Chromium's, as outlined in `Issue #14 `_. .. [#browsers] See `Issue #14 `_. Standards Conformance ================================================================================ In the default configuration, this package adds only one additional constraint to the IETF specification, requiring a minimum of two labels, separated by periods. This extra restriction can be disabled. It is enabled by default to prevent breaking backwards compatibility. Review the tests for examples of the impact of this. IETF Specification -------------------------------------------------------------------------------- The IETF specification restricts domain names to alphanumeric ASCII characters and hyphens as described below. `RFC 1123 `_: Requirements for Internet Hosts - Application and Support, October 1989 This RFC is an official specification for the Internet community. It incorporates by reference, amends, corrects, and supplements the primary protocol standards documents relating to hosts. .. 2.1 Host Names and Numbers The syntax of a legal Internet host name was specified in RFC-952 [DNS:4]. One aspect of host name syntax is hereby changed: the restriction on the first character is relaxed to allow either a letter or a digit. Host software MUST support this more liberal syntax. Host software MUST handle host names of up to 63 characters and SHOULD handle host names of up to 255 characters. Whenever a user inputs the identity of an Internet host, it SHOULD be possible to enter either (1) a host domain name or (2) an IP address in dotted-decimal ("#.#.#.#") form. The host SHOULD check the string syntactically for a dotted-decimal number before looking it up in the Domain Name System. `RFC 952 `_: DoD Internet host table specification, October 1985 This RFC is the official specification of the format of the Internet Host Table. .. .. code:: text ::= *["."] ::= [*[]] Commentary -------------------------------------------------------------------------------- `RFC-1034 `_: Domain Name Concepts and Facilities, November 1987 - Section 3.5 specifies a "preferred name syntax", which is non-compulsory. 3.5. Preferred name syntax The DNS specifications attempt to be as general as possible in the rules for constructing domain names. The idea is that the name of any existing object can be expressed as a domain name with minimal changes. However, when assigning a domain name for an object, the prudent user will select a name which satisfies both the rules of the domain system and any existing rules for the object, whether these rules are published or implied by existing programs. For example, when naming a mail domain, the user should satisfy both the rules of this memo and those in RFC-822. When creating a new host name, the old rules for HOSTS.TXT should be followed. This avoids problems when old software is converted to use domain names. `RFC-1035 `_: Domain Names - Implementation and Specification, November 1987 - Section 2.3.1 repeats the "preferred name syntax" proposal from RFC-1034. `RFC-2181 `_: Clarification to the DNS Specification, July 1997 - Section 11 comments that RFC-1035 does not restrict domain names to the preferred name syntax set out in it. Instead Internet hostnames are restricted more or less by a combination of tradition and RFC-2181, where this package finds itself. `RFC-3696 `_: Application Techniques for Checking and Transformation of Names, February 2004 - This memo provides *fascinating* commentary of the history of string validation for domain names. Licenses ================================================================================ |License Status Shield| fqdn-1.5.1/SECURITY.md000066400000000000000000000014711402234063600142420ustar00rootroot00000000000000# Security Policy ## Supported Versions | Version | Supported | | ------- | ------------------ | | 1.3.x | :white_check_mark: | | < 1.3 | :x: | ## Reporting a Vulnerability ``` -----BEGIN PGP PUBLIC KEY BLOCK----- Version: ProtonMail xjMEXNwsIBYJKwYBBAHaRw8BAQdAk7puaOBaYyC3xqqJAI3Fae6+X+VQJE61 IIbZXu5OOP/NLXlwY3J0c0Bwcm90b25tYWlsLmNvbSA8eXBjcnRzQHByb3Rv bm1haWwuY29tPsJ3BBAWCgAfBQJc3CwgBgsJBwgDAgQVCAoCAxYCAQIZAQIb AwIeAQAKCRCCFGL0zzqppZnNAP0XFd2uhApReRTyruW9gCTJzMgRRVeupuc3 4HmNgdQYdgEA+A51ncDSVHqUK9+N6jPnzCpPd+DoB41drHzvRJlYHA7OOARc 3CwgEgorBgEEAZdVAQUBAQdAyq94ceRhLSmv5NLPjUwyboABh4Lir8Z6NYBk /Q48IDoDAQgHwmEEGBYIAAkFAlzcLCACGwwACgkQghRi9M86qaViZAEAiq2k n0VldzrKmX8QVi97tVlFOS9O6EJW4J++p3LrVusBANEvsK98PVlXDciH6bsC OTNqi7X/RU7YUImpYl0D4soJ =+kNb -----END PGP PUBLIC KEY BLOCK----- ``` fqdn-1.5.1/docs/000077500000000000000000000000001402234063600133765ustar00rootroot00000000000000fqdn-1.5.1/docs/Makefile000066400000000000000000000011341402234063600150350ustar00rootroot00000000000000# Minimal makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = python -msphinx SPHINXPROJ = fqdn SOURCEDIR = . BUILDDIR = _build # Put it first so that "make" without argument is like "make help". help: @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) .PHONY: help Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)fqdn-1.5.1/docs/conf.py000066400000000000000000000121271402234063600147000ustar00rootroot00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # fqdn documentation build configuration file, created by # sphinx-quickstart on Fri Jul 21 10:15:50 2017. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath("."))) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest"] # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] source_suffix = ".rst" # The master toctree document. master_doc = "index" # General information about the project. project = "fqdn" copyright = "2017, ypcrts" author = "ypcrts" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = "1.5.1" # The full version, including alpha/beta/rc tags. release = "1.5.1" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # The name of the Pygments (syntax highlighting) style to use. pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. # html_theme_options = dict(nosidebar=True) # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["_static"] # Custom sidebar templates, must be a dictionary that maps document names # to template names. # # This is required for the alabaster theme # refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars html_sidebars = { "**": [ "about.html", "navigation.html", "relations.html", # needs 'show_related': True theme option to display "searchbox.html", "donate.html", ] } # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. htmlhelp_basename = "fqdndoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. # # 'preamble': '', # Latex figure (float) alignment # # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, "fqdn.tex", "fqdn Documentation", "ypcrts", "manual"), ] # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [(master_doc, "fqdn", "fqdn Documentation", [author], 1)] # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ( master_doc, "fqdn", "fqdn Documentation", author, "fqdn", "One line description of project.", "Miscellaneous", ), ] fqdn-1.5.1/docs/index.rst000066400000000000000000000004561402234063600152440ustar00rootroot00000000000000.. include:: ../README.rst fqdn ================================ .. automodule:: fqdn :members: :undoc-members: :show-inheritance: .. .. toctree:: .. :maxdepth: 2 .. :caption: Contents: .. Index .. ================== .. * :ref:`genindex` .. * :ref:`modindex` .. * :ref:`search` fqdn-1.5.1/docs/make.bat000066400000000000000000000013761402234063600150120ustar00rootroot00000000000000@ECHO OFF pushd %~dp0 REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=python -msphinx ) set SOURCEDIR=. set BUILDDIR=_build set SPHINXPROJ=fqdn if "%1" == "" goto help %SPHINXBUILD% >NUL 2>NUL if errorlevel 9009 ( echo. echo.The Sphinx module was not found. Make sure you have Sphinx installed, echo.then set the SPHINXBUILD environment variable to point to the full echo.path of the 'sphinx-build' executable. Alternatively you may add the echo.Sphinx directory to PATH. echo. echo.If you don't have Sphinx installed, grab it from echo.http://sphinx-doc.org/ exit /b 1 ) %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% goto end :help %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% :end popd fqdn-1.5.1/fqdn/000077500000000000000000000000001402234063600133765ustar00rootroot00000000000000fqdn-1.5.1/fqdn/__init__.py000066400000000000000000000112631402234063600155120ustar00rootroot00000000000000import re from fqdn._compat import cached_property class FQDN: """ From https://tools.ietf.org/html/rfc1035#page-9, RFC 1035 3.1. Name space definitions: Domain names in messages are expressed in terms of a sequence of labels. Each label is represented as a one octet length field followed by that number of octets. Since every domain name ends with the null label of the root, a domain name is terminated by a length byte of zero. The high order two bits of every length octet must be zero, and the remaining six bits of the length field limit the label to 63 octets or less. To simplify implementations, the total length of a domain name (i.e., label octets and label length octets) is restricted to 255 octets or less. Therefore the max length of a domain name is actually 253 ASCII bytes without the trailing null byte or the leading length byte, and the max length of a label is 63 bytes without the leading length byte. """ PREFERRED_NAME_SYNTAX_REGEXSTR = ( r"^((?![-])[-A-Z\d]{1,63}(? 253: return False regex_pass = self._regex.match(self._fqdn) if not regex_pass: return False return self.labels_count >= self._min_labels @property def labels_count(self): has_terminal_dot = self._fqdn[-1] == "." count = self._fqdn.count(".") + (0 if has_terminal_dot else 1) return count @cached_property def is_valid_absolute(self): """ True for a fully-qualified domain name (FQDN) that is RFC preferred-form compliant and ends with a `.`. With relative FQDNS in DNS lookups, the current hosts domain name or search domains may be appended. """ return self._fqdn.endswith(".") and self.is_valid @cached_property def is_valid_relative(self): """ True for a validated fully-qualified domain name that compiles with the RFC preferred-form and does not ends with a `.`. """ return not self._fqdn.endswith(".") and self.is_valid @cached_property def absolute(self): """ The FQDN as a string in absolute form """ if not self.is_valid: raise ValueError("invalid FQDN `{0}`".format(self._fqdn)) if self.is_valid_absolute: return self._fqdn return "{0}.".format(self._fqdn) @cached_property def relative(self): """ The FQDN as a string in relative form """ if not self.is_valid: raise ValueError("invalid FQDN `{0}`".format(self._fqdn)) if self.is_valid_absolute: return self._fqdn[:-1] return self._fqdn def __eq__(self, other): if isinstance(other, FQDN): return self.absolute == other.absolute def __hash__(self): return hash(self.absolute) + hash("fqdn") fqdn-1.5.1/fqdn/_compat.py000066400000000000000000000002561402234063600153750ustar00rootroot00000000000000import sys if sys.version_info[:2] >= (3, 8): from functools import cached_property else: from cached_property import cached_property __all__ = ["cached_property"] fqdn-1.5.1/setup.cfg000066400000000000000000000000511402234063600142630ustar00rootroot00000000000000[metadata] description-file = README.rst fqdn-1.5.1/setup.py000066400000000000000000000030371402234063600141630ustar00rootroot00000000000000from setuptools import setup setup( name="fqdn", packages=["fqdn"], version="1.5.1", description=( "Validates fully-qualified domain names against RFC 1123, " "so that they are acceptable to modern bowsers" ), author="ypcrts", author_email="ypcrts@users.noreply.github.com", url="https://github.com/ypcrts/fqdn", keywords=["fqdn", "domain", "hostname", "RFC3686", "dns"], license="MPL 2.0", zip_safe=True, install_requires=["cached-property>=1.3.0;python_version<'3.8'"], python_requires=">=2.7, !=3.0, !=3.1, !=3.2, !=3.3, !=3.4, <4", test_suite="tests", classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: Name Service (DNS)", "Topic :: Internet", "Topic :: System :: Systems Administration", "Topic :: Utilities", ], ) fqdn-1.5.1/tests/000077500000000000000000000000001402234063600136105ustar00rootroot00000000000000fqdn-1.5.1/tests/__init__.py000066400000000000000000000000001402234063600157070ustar00rootroot00000000000000fqdn-1.5.1/tests/test_fqdn.py000066400000000000000000000270131402234063600161540ustar00rootroot00000000000000# coding=utf-8 import sys import pytest from fqdn import FQDN @pytest.fixture(params=(True, False)) def a_u(request): return request.param class TestFQDNValidation: def test_constructor(self, a_u): with pytest.raises(ValueError): FQDN(None, allow_underscores=a_u) # Python 3-specific tests if sys.version_info >= (3, 0): def test_constructor_raises_on_bytes(self, a_u): with pytest.raises(ValueError): FQDN(b"", allow_underscores=a_u) with pytest.raises(ValueError): FQDN(b"helloworld", allow_underscores=a_u) def test_str(self, a_u): d = "greatdomain.com" f = FQDN(d, allow_underscores=a_u) assert f.absolute == str(f) def test_rfc_1035_s_2_3_4__label_max_length(self, a_u): assert FQDN( "www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com", allow_underscores=a_u, ).is_valid assert FQDN( "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk", allow_underscores=a_u, ).is_valid def test_rfc_1035_s_2_3_4__label_too_long(self, a_u): self.__assert_invalid_from_seq("A" * 64, "com", allow_underscores=a_u) self.__assert_invalid_from_seq("b" * 63, "A" * 64, "com", allow_underscores=a_u) self.__assert_invalid_from_seq("com", "b" * 63, "A" * 64, allow_underscores=a_u) def test_rfc_1035_s_2_3_4__name_too_long_254_octets(self, a_u): parts = [(chr(ord("A") + i % 26)) for i in range(int(254 / 2) - 1)] parts.append("co") fqdn = ".".join(parts) assert len(fqdn) == 254 self.__assert_invalid_from_seq(fqdn, allow_underscores=a_u) def test_rfc_1035_s_2_3_4__name_ok_253_octets(self, a_u): parts = [(chr(ord("A") + i % 26)) for i in range(int(254 / 2))] fqdn = ".".join(parts) assert len(fqdn) == 253 self.__assert_valid_from_seq(fqdn, allow_underscores=a_u) def test_rfc_1035_s_3_1__trailing_byte(self, a_u): parts = [(chr(ord("A") + i % 26)) for i in range(int(254 / 2))] fqdn = ".".join(parts) + "." assert len(fqdn) == 254 self.__assert_valid_from_seq(fqdn, allow_underscores=a_u) def test_rfc_3696_s_2__label_invalid_starts_or_ends_with_hyphen(self): self.__assert_invalid_fwd_and_bkwd_from_seq("-a", "com", allow_underscores=a_u) self.__assert_invalid_fwd_and_bkwd_from_seq("a-", "com", allow_underscores=a_u) self.__assert_invalid_fwd_and_bkwd_from_seq("-a-", "com", allow_underscores=a_u) def test_rfc_3696_s_2__preferred_form_invalid_chars(self, a_u): # these should use punycode instead self.__assert_invalid_fwd_and_bkwd_from_seq("є", "com", allow_underscores=a_u) self.__assert_invalid_fwd_and_bkwd_from_seq( "le-tour-est-joué", "com", allow_underscores=a_u ) self.__assert_invalid_fwd_and_bkwd_from_seq( "invalid", "cóm", allow_underscores=a_u ) self.__assert_invalid_fwd_and_bkwd_from_seq( "ich-hätte-gern-ein-Umlaut", "de", allow_underscores=a_u ) self.__assert_invalid_fwd_and_bkwd_from_seq( "\x01", "com", allow_underscores=a_u ) self.__assert_invalid_fwd_and_bkwd_from_seq( "x", "\x01\x02\x01", allow_underscores=a_u ) def test_underscores_extra_mode(self): self.__assert_valid_fwd_and_bkwd_from_seq("_", "dog", allow_underscores=True) self.__assert_valid_fwd_and_bkwd_from_seq("i_", "dog", allow_underscores=True) self.__assert_valid_fwd_and_bkwd_from_seq("o_o", "dog", allow_underscores=True) self.__assert_invalid_fwd_and_bkwd_from_seq("_", "dog", allow_underscores=False) self.__assert_invalid_fwd_and_bkwd_from_seq( "i_", "dog", allow_underscores=False ) self.__assert_invalid_fwd_and_bkwd_from_seq( "o_o", "dog", allow_underscores=False ) def test_rfc_3696_s_2__valid(self): assert FQDN("net", min_labels=1, allow_underscores=a_u).is_valid assert FQDN("who.is", allow_underscores=a_u).is_valid assert FQDN("bbc.co.uk", allow_underscores=a_u).is_valid self.__assert_valid_fwd_and_bkwd_from_seq( "sh4d05-7357", "c00-mm", allow_underscores=a_u ) def test_rfc_1035_s_2_3_1__label_can_have_inital_digit(self, a_u): self.__assert_valid_fwd_and_bkwd_from_seq("www", "1", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("1w", "1", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("1w", "a", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("1w1", "d", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("111", "a", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("www", "1a", allow_underscores=a_u) def test_rfc_1123__label_can_have_medial_and_terminal_digits(self, a_u): self.__assert_valid_fwd_and_bkwd_from_seq("www1", "a", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("ww1a", "c", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("w2w", "c", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("a111", "a", allow_underscores=a_u) self.__assert_valid_fwd_and_bkwd_from_seq("a1c1", "a", allow_underscores=a_u) def __assert_valid_fwd_and_bkwd_from_seq(self, *seq, **kwargs): rseq = reversed(seq) self.__assert_valid_from_seq(*rseq, **kwargs) def __assert_invalid_fwd_and_bkwd_from_seq(self, *seq, **kwargs): rseq = reversed(seq) self.__assert_invalid_from_seq(*rseq, **kwargs) def __assert_invalid_from_seq(self, *seq, **kwargs): assert not (self.__is_valid_fqdn_from_labels_seq(seq, **kwargs)) def __assert_valid_from_seq(self, *seq, **kwargs): assert self.__is_valid_fqdn_from_labels_seq(seq, **kwargs) def __is_valid_fqdn_from_labels_seq(self, fqdn_labels_seq, **kwargs): fqdn = ".".join(fqdn_labels_seq) return FQDN(fqdn, **kwargs).is_valid class TestMinLabels: def test_labels_count(self, a_u): assert FQDN("label").labels_count == 1 assert FQDN("label.").labels_count == 1 assert FQDN("label.babel").labels_count == 2 assert FQDN("label.babel.").labels_count == 2 assert FQDN(".label.babel.").labels_count == 3 def test_min_labels_defaults_to_require_2(self): dn = FQDN("label") assert dn._min_labels == 2 assert dn.labels_count == 1 assert not dn.is_valid def test_min_labels_valid_set_to_1(self): with pytest.raises(ValueError): FQDN("", min_labels=1).is_valid assert FQDN("label", min_labels=1).is_valid assert not FQDN(".label", min_labels=1).is_valid assert FQDN("label.babel", min_labels=1).is_valid assert FQDN("label.babel.", min_labels=1).is_valid assert not FQDN(".label.babel", min_labels=1).is_valid def test_min_labels_valid_set_to_3(self): assert not FQDN("label", min_labels=3).is_valid assert not FQDN("label.babel", min_labels=3).is_valid assert not FQDN(".babel", min_labels=3).is_valid assert not FQDN("babel.", min_labels=3).is_valid assert not FQDN(".babel.", min_labels=3).is_valid assert not FQDN("label.babel.", min_labels=3).is_valid assert not FQDN(".label.babel.", min_labels=3).is_valid assert FQDN("fable.label.babel.", min_labels=3).is_valid assert FQDN("fable.label.babel", min_labels=3).is_valid class TestAbsoluteFQDN: def test_absolute_fqdn(self, a_u): assert FQDN("trainwreck.com.", allow_underscores=a_u).is_valid_absolute is True def test_absolute_fqdn__fail(self, a_u): assert FQDN("trainwreck.com", allow_underscores=a_u).is_valid_absolute is False def test_to_absolute_fqdn_from_relative(self, a_u): assert ( FQDN("trainwreck.com", allow_underscores=a_u).absolute == "trainwreck.com." ) def test_to_absolute_fqdn_from_absolute(self, a_u): assert ( FQDN("absolutetrainwreck.com.", allow_underscores=a_u).absolute == "absolutetrainwreck.com." ) def test_to_absolute_fqdn__raises_ValueError(self, a_u): with pytest.raises(ValueError): FQDN("trainwreckcom", allow_underscores=a_u).absolute def test_relative_fqdn_true(self, a_u): assert FQDN("relative.com", allow_underscores=a_u).is_valid_relative is True def test_relative_fqdn_false(self, a_u): assert FQDN("relative.com.", allow_underscores=a_u).is_valid_relative is False class TestRelativeFQDN: def test_relative_fqdn_from_relative(self, a_u): assert ( FQDN("trainwreck.com", allow_underscores=a_u).relative == "trainwreck.com" ) def test_relative_fqdn_from_absolute(self, a_u): assert ( FQDN("trainwreck.com.", allow_underscores=a_u).relative == "trainwreck.com" ) def test_relative_fqdn_from_invalid(self, a_u): with pytest.raises(ValueError): FQDN("trainwreck..", allow_underscores=a_u).relative class TestEquality: def test_absolutes_are_equal(self, a_u): assert FQDN("trainwreck.com.", allow_underscores=a_u) == FQDN( "trainwreck.com.", allow_underscores=a_u ) def test_relatives_are_equal(self, a_u): assert FQDN("trainwreck.com", allow_underscores=a_u) == FQDN( "trainwreck.com", allow_underscores=a_u ) def test_mismatch_are_equal(self, a_u): assert FQDN("trainwreck.com.", allow_underscores=a_u) == FQDN( "trainwreck.com", allow_underscores=a_u ) def test_equality_is_case_insensitive(self, a_u): assert FQDN( "all-letters-were-created-equal.com.", allow_underscores=a_u ) == FQDN("ALL-LETTERS-WERE-CREATED-EQUAL.COM.", allow_underscores=a_u) def test_strict_and_loose_can_be_equal(self): assert FQDN("trainwreck.com.", allow_underscores=False) == FQDN( "trainwreck.com", allow_underscores=True ) class TestHash: def test_is_hashable(self, a_u): assert hash(FQDN("trainwreck.com.")) def test_absolutes_are_equal(self, a_u): assert hash(FQDN("trainwreck.com.", allow_underscores=a_u)) == hash( FQDN("trainwreck.com.", allow_underscores=a_u) ) def test_relatives_are_equal(self, a_u): assert hash(FQDN("trainwreck.com", allow_underscores=a_u)) == hash( FQDN("trainwreck.com", allow_underscores=a_u) ) def test_mismatch_are_equal(self, a_u): assert hash(FQDN("trainwreck.com.", allow_underscores=a_u)) == hash( FQDN("trainwreck.com", allow_underscores=a_u) ) def test_equality_is_case_insensitive(self, a_u): assert hash( FQDN("all-letters-were-created-equal.com.", allow_underscores=a_u) ) == hash(FQDN("ALL-LETTERS-WERE-CREATED-EQUAL.COM.", allow_underscores=a_u)) def test_not_equal_to_string(self, a_u): assert hash(FQDN("trainwreck.com.", allow_underscores=a_u)) != hash( "trainwreck.com." ) def test_different_fqdns_are_not_equal(self, a_u): assert hash(FQDN("trainwreck.com.")) != hash(FQDN("test.com.")) def test_strict_and_loose_hashs_are_equal(self): assert hash(FQDN("trainwreck.com.", allow_underscores=False)) == hash( FQDN("trainwreck.com", allow_underscores=True) ) fqdn-1.5.1/tox.ini000066400000000000000000000001671402234063600137650ustar00rootroot00000000000000[tox] ;envlist = py39,py37,py27 [testenv] changedir = tests deps = pytest pytest-cov commands = pytest --cov=./