├── .coveragerc ├── .flake8 ├── .gitignore ├── .style.yapf ├── .travis.yml ├── AUTHORS.rst ├── CHANGELOG.rst ├── LICENSE ├── README.rst ├── doc ├── Makefile └── source │ ├── authors.rst │ ├── autodoc.rst │ ├── changelog.rst │ ├── conf.py │ ├── index.rst │ ├── testing.rst │ └── usage.rst ├── giturlparse ├── __init__.py └── parser.py ├── pytest.ini ├── requirements-doc.txt ├── requirements-test.txt ├── requirements.txt ├── setup.cfg ├── setup.py ├── test ├── __init__.py ├── conftest.py └── test_parser.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [report] 2 | fail_under = 3 | 100 4 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | exclude = .venv/,.tox/,dist/,build/,doc/,.eggs/ 3 | format = pylint 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.egg-info/ 2 | *.py[rcod] 3 | .cache/ 4 | .coverage 5 | .eggs/ 6 | .tox/ 7 | build/ 8 | coverage.* 9 | dist/ 10 | doc/build/ 11 | htmlcov/ 12 | -------------------------------------------------------------------------------- /.style.yapf: -------------------------------------------------------------------------------- 1 | [style] 2 | based_on_style = pep8 3 | column_limit = 79 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: 4 | - "2.7" 5 | - "3.5" 6 | - "3.4" 7 | - "3.6" 8 | # - "3.7" 9 | 10 | install: 11 | - pip install tox-travis codecov 12 | 13 | script: 14 | - tox 15 | 16 | after_success: 17 | - (cd .tox/ && codecov -v -X gcov --required) 18 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | Credits 3 | ******* 4 | 5 | Development Leads 6 | ================= 7 | 8 | * John Dewey (`@retr0h`_) 9 | 10 | Core Committers 11 | =============== 12 | 13 | Contributors 14 | ============ 15 | 16 | .. _`@retr0h`: https://github.com/retr0h 17 | -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ******* 2 | History 3 | ******* 4 | 5 | 1.2.2 6 | ===== 7 | 8 | * Corrected processing of name with a dot. 9 | 10 | 1.2.1 11 | ===== 12 | 13 | * Corrected processing of URLs with a hyphen. 14 | 15 | 1.2 16 | === 17 | 18 | * Improved parsing speed by compiling regex on global context and reusing 19 | named collection. 20 | 21 | 1.1 22 | === 23 | 24 | * Cleaned up unused packages from requirements. 25 | * Added python 3.4 and 3.5 support. 26 | * Further parsing of valid git URLs. 27 | * Pass pep8 and yapf. 28 | * Added to travis ci. 29 | * Execute one regex at a time. 30 | 31 | 32 | 1.0.2 33 | ===== 34 | 35 | * Corrected pbr version info package name. 36 | 37 | 1.0.1 38 | ===== 39 | 40 | * Support parsing domains which contain a hyphen. 41 | 42 | 1.0 43 | === 44 | 45 | * Initial release. 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 John Dewey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | .. image:: http://img.shields.io/travis/retr0h/git-url-parse.svg?style=popout-square&logo=travis 2 | :target: https://travis-ci.org/retr0h/git-url-parse 3 | 4 | .. image:: https://img.shields.io/codecov/c/github/retr0h/git-url-parse.svg?style=popout-square&logo=codecov 5 | :target: https://codecov.io/gh/retr0h/git-url-parse 6 | 7 | .. image:: https://img.shields.io/pypi/v/git-url-parse.svg?style=popout-square&logo=python 8 | :target: https://pypi.org/project/git-url-parse/ 9 | 10 | .. image:: https://img.shields.io/readthedocs/git-url-parse.svg?style=popout-square&logo=Read%20the%20Docs 11 | :target: https://git-url-parse.readthedocs.io/en/latest/ 12 | 13 | *********** 14 | giturlparse 15 | *********** 16 | 17 | A simple GIT URL parser similar to `giturlparse.py`_. 18 | 19 | .. _`giturlparse.py`: https://github.com/FriendCode/giturlparse.py 20 | 21 | Documentation 22 | ============= 23 | 24 | https://git-url-parse.readthedocs.io/ 25 | 26 | License 27 | ======= 28 | 29 | MIT 30 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/tribe.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/tribe.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/tribe" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/tribe" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /doc/source/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../AUTHORS.rst 2 | -------------------------------------------------------------------------------- /doc/source/autodoc.rst: -------------------------------------------------------------------------------- 1 | Autodoc 2 | ======= 3 | 4 | Parser 5 | ------ 6 | 7 | .. autoclass:: giturlparse.parser.Parser 8 | :members: 9 | 10 | .. autoclass:: giturlparse.parser.ParserError 11 | :members: 12 | -------------------------------------------------------------------------------- /doc/source/changelog.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../CHANGELOG.rst 2 | -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # giturlparse documentation build configuration file, created by 4 | # sphinx-quickstart on Sat Oct 17 16:07:47 2015. 5 | # 6 | # This file is execfile()d with the current directory set to its 7 | # containing dir. 8 | # 9 | # Note that not all possible configuration values are present in this 10 | # autogenerated file. 11 | # 12 | # All configuration values have a default; values that are commented out 13 | # serve to show the default. 14 | 15 | import datetime 16 | import os 17 | import shlex 18 | import sys 19 | 20 | import giturlparse 21 | 22 | import alabaster 23 | 24 | # If extensions (or modules to document with autodoc) are in another directory, 25 | # add these directories to sys.path here. If the directory is relative to the 26 | # documentation root, use os.path.abspath to make it absolute, like shown here. 27 | sys.path.insert(0, os.path.abspath('../..')) 28 | 29 | # -- General configuration ------------------------------------------------ 30 | 31 | # If your documentation needs a minimal Sphinx version, state it here. 32 | #needs_sphinx = '1.0' 33 | 34 | # Add any Sphinx extension module names here, as strings. They can be 35 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 36 | # ones. 37 | extensions = [ 38 | 'sphinx.ext.autodoc', 39 | 'sphinx.ext.doctest', 40 | 'sphinx.ext.coverage', 41 | 'sphinx.ext.todo', 42 | 'alabaster', 43 | ] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix(es) of source filenames. 49 | # You can specify multiple suffix as a list of string: 50 | # source_suffix = ['.rst', '.md'] 51 | source_suffix = '.rst' 52 | 53 | # The encoding of source files. 54 | #source_encoding = 'utf-8-sig' 55 | 56 | # The master toctree document. 57 | master_doc = 'index' 58 | 59 | # General information about the project. 60 | project = u'giturlparse' 61 | copyright = u' %s, John Dewey' % datetime.date.today().year 62 | author = u'AUTHORS.md' 63 | 64 | # The version info for the project you're documenting, acts as replacement for 65 | # |version| and |release|, also used in various other places throughout the 66 | # built documents. 67 | # 68 | # The short X.Y version. 69 | version = giturlparse.__version__ 70 | # The full version, including alpha/beta/rc tags. 71 | release = version 72 | 73 | # The language for content autogenerated by Sphinx. Refer to documentation 74 | # for a list of supported languages. 75 | # 76 | # This is also used if you do content translation via gettext catalogs. 77 | # Usually you set "language" from the command line for these cases. 78 | language = None 79 | 80 | # There are two options for replacing |today|: either, you set today to some 81 | # non-false value, then it is used: 82 | #today = '' 83 | # Else, today_fmt is used as the format for a strftime call. 84 | #today_fmt = '%B %d, %Y' 85 | 86 | # List of patterns, relative to source directory, that match files and 87 | # directories to ignore when looking for source files. 88 | exclude_patterns = [] 89 | 90 | # The reST default role (used for this markup: `text`) to use for all 91 | # documents. 92 | #default_role = None 93 | 94 | # If true, '()' will be appended to :func: etc. cross-reference text. 95 | #add_function_parentheses = True 96 | 97 | # If true, the current module name will be prepended to all description 98 | # unit titles (such as .. function::). 99 | #add_module_names = True 100 | 101 | # If true, sectionauthor and moduleauthor directives will be shown in the 102 | # output. They are ignored by default. 103 | #show_authors = False 104 | 105 | # The name of the Pygments (syntax highlighting) style to use. 106 | pygments_style = 'sphinx' 107 | 108 | # A list of ignored prefixes for module index sorting. 109 | #modindex_common_prefix = [] 110 | 111 | # If true, keep warnings as "system message" paragraphs in the built documents. 112 | #keep_warnings = False 113 | 114 | # If true, `todo` and `todoList` produce output, else they produce nothing. 115 | todo_include_todos = True 116 | 117 | # -- Options for HTML output ---------------------------------------------- 118 | 119 | # The theme to use for HTML and HTML Help pages. See the documentation for 120 | # a list of builtin themes. 121 | html_theme = 'alabaster' 122 | 123 | # Theme options are theme-specific and customize the look and feel of a theme 124 | # further. For a list of options available for each theme, see the 125 | # documentation. 126 | # html_theme_options = {} 127 | html_theme_options = { 128 | 'github_user': 'retr0h', 129 | 'github_repo': 'giturlparse', 130 | 'github_button': True, 131 | 'travis_button': False, 132 | 'show_powered_by': False, 133 | 'extra_nav_links': { 134 | 'View on github': 'https://github.com/retr0h/giturlparse', 135 | }, 136 | } 137 | 138 | # Add any paths that contain custom themes here, relative to this directory. 139 | #html_theme_path = [] 140 | html_theme_path = [alabaster.get_path()] 141 | 142 | # The name for this set of Sphinx documents. If None, it defaults to 143 | # " v documentation". 144 | #html_title = None 145 | 146 | # A shorter title for the navigation bar. Default is the same as html_title. 147 | #html_short_title = None 148 | 149 | # The name of an image file (relative to this directory) to place at the top 150 | # of the sidebar. 151 | #html_logo = None 152 | 153 | # The name of an image file (within the static path) to use as favicon of the 154 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 155 | # pixels large. 156 | #html_favicon = None 157 | 158 | # Add any paths that contain custom static files (such as style sheets) here, 159 | # relative to this directory. They are copied after the builtin static files, 160 | # so a file named "default.css" will overwrite the builtin "default.css". 161 | # html_static_path = ['_static'] 162 | 163 | # Add any extra paths that contain custom files (such as robots.txt or 164 | # .htaccess) here, relative to this directory. These files are copied 165 | # directly to the root of the documentation. 166 | #html_extra_path = [] 167 | 168 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 169 | # using the given strftime format. 170 | #html_last_updated_fmt = '%b %d, %Y' 171 | 172 | # If true, SmartyPants will be used to convert quotes and dashes to 173 | # typographically correct entities. 174 | #html_use_smartypants = True 175 | 176 | # Custom sidebar templates, maps document names to template names. 177 | #html_sidebars = {} 178 | html_sidebars = { 179 | '**': [ 180 | 'about.html', 181 | 'navigation.html', 182 | 'searchbox.html', 183 | ], 184 | } 185 | 186 | # Additional templates that should be rendered to pages, maps page names to 187 | # template names. 188 | #html_additional_pages = {} 189 | 190 | # If false, no module index is generated. 191 | #html_domain_indices = True 192 | 193 | # If false, no index is generated. 194 | #html_use_index = True 195 | 196 | # If true, the index is split into individual pages for each letter. 197 | #html_split_index = False 198 | 199 | # If true, links to the reST sources are added to the pages. 200 | html_show_sourcelink = False 201 | 202 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 203 | #html_show_sphinx = True 204 | 205 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 206 | html_show_copyright = False 207 | 208 | # If true, an OpenSearch description file will be output, and all pages will 209 | # contain a tag referring to it. The value of this option must be the 210 | # base URL from which the finished HTML is served. 211 | #html_use_opensearch = '' 212 | 213 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 214 | #html_file_suffix = None 215 | 216 | # Language to be used for generating the HTML full-text search index. 217 | # Sphinx supports the following languages: 218 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' 219 | # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' 220 | #html_search_language = 'en' 221 | 222 | # A dictionary with options for the search language support, empty by default. 223 | # Now only 'ja' uses this config value 224 | #html_search_options = {'type': 'default'} 225 | 226 | # The name of a javascript file (relative to the configuration directory) that 227 | # implements a search results scorer. If empty, the default will be used. 228 | #html_search_scorer = 'scorer.js' 229 | 230 | # Output file base name for HTML help builder. 231 | htmlhelp_basename = 'giturlparsedoc' 232 | 233 | # -- Options for LaTeX output --------------------------------------------- 234 | 235 | latex_elements = { 236 | # The paper size ('letterpaper' or 'a4paper'). 237 | #'papersize': 'letterpaper', 238 | 239 | # The font size ('10pt', '11pt' or '12pt'). 240 | #'pointsize': '10pt', 241 | 242 | # Additional stuff for the LaTeX preamble. 243 | #'preamble': '', 244 | 245 | # Latex figure (float) alignment 246 | #'figure_align': 'htbp', 247 | } 248 | 249 | # Grouping the document tree into LaTeX files. List of tuples 250 | # (source start file, target name, title, 251 | # author, documentclass [howto, manual, or own class]). 252 | latex_documents = [ 253 | (master_doc, 'giturlparse.tex', u'giturlparse Documentation', 254 | u'AUTHORS.md', 'manual'), 255 | ] 256 | 257 | # The name of an image file (relative to this directory) to place at the top of 258 | # the title page. 259 | #latex_logo = None 260 | 261 | # For "manual" documents, if this is true, then toplevel headings are parts, 262 | # not chapters. 263 | #latex_use_parts = False 264 | 265 | # If true, show page references after internal links. 266 | #latex_show_pagerefs = False 267 | 268 | # If true, show URL addresses after external links. 269 | #latex_show_urls = False 270 | 271 | # Documents to append as an appendix to all manuals. 272 | #latex_appendices = [] 273 | 274 | # If false, no module index is generated. 275 | #latex_domain_indices = True 276 | 277 | 278 | # -- Options for manual page output --------------------------------------- 279 | 280 | # One entry per manual page. List of tuples 281 | # (source start file, name, description, authors, manual section). 282 | man_pages = [ 283 | (master_doc, 'giturlparse', u'giturlparse Documentation', 284 | [author], 1) 285 | ] 286 | 287 | # If true, show URL addresses after external links. 288 | #man_show_urls = False 289 | 290 | 291 | # -- Options for Texinfo output ------------------------------------------- 292 | 293 | # Grouping the document tree into Texinfo files. List of tuples 294 | # (source start file, target name, title, author, 295 | # dir menu entry, description, category) 296 | texinfo_documents = [ 297 | (master_doc, 'giturlparse', u'giturlparse Documentation', 298 | author, 'AUTHORS.md', 'A restful port reservation microservice', 299 | 'Miscellaneous'), 300 | ] 301 | 302 | # Documents to append as an appendix to all manuals. 303 | #texinfo_appendices = [] 304 | 305 | # If false, no module index is generated. 306 | #texinfo_domain_indices = True 307 | 308 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 309 | #texinfo_show_urls = 'footnote' 310 | 311 | # If true, do not generate a @detailmenu in the "Top" node's menu. 312 | #texinfo_no_detailmenu = False 313 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../../README.rst 2 | 3 | Contents: 4 | 5 | .. toctree:: 6 | :maxdepth: 3 7 | 8 | usage 9 | testing 10 | changelog 11 | authors 12 | autodoc 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /doc/source/testing.rst: -------------------------------------------------------------------------------- 1 | Testing 2 | ======= 3 | 4 | :: 5 | 6 | $ pip install tox 7 | $ tox 8 | -------------------------------------------------------------------------------- /doc/source/usage.rst: -------------------------------------------------------------------------------- 1 | Usage 2 | ===== 3 | 4 | This tool will parse a GIT URL and return a `Parsed` object. 5 | 6 | :: 7 | 8 | import giturlparse 9 | 10 | p = giturlparse.parse('git@github.com:retr0h/ansible-etcd.git') 11 | p.pathname 12 | p.protocols 13 | p.protocol 14 | p.href 15 | p.resource 16 | p.user 17 | p.port 18 | p.name 19 | p.owner 20 | -------------------------------------------------------------------------------- /giturlparse/__init__.py: -------------------------------------------------------------------------------- 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 2 | 3 | # Copyright (c) 2017 John Dewey 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | from giturlparse import parser 24 | 25 | import pbr.version 26 | 27 | version_info = pbr.version.VersionInfo('git-url-parse') 28 | __version__ = version_info.release_string() 29 | 30 | 31 | def parse(url): # pragma: no cover 32 | p = parser.Parser(url) 33 | 34 | return p.parse() 35 | -------------------------------------------------------------------------------- /giturlparse/parser.py: -------------------------------------------------------------------------------- 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 2 | 3 | # Copyright (c) 2017 John Dewey 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to 7 | # deal in the Software without restriction, including without limitation the 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | # sell copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 | # DEALINGS IN THE SOFTWARE. 22 | 23 | import collections 24 | import re 25 | 26 | Parsed = collections.namedtuple('Parsed', [ 27 | 'pathname', 28 | 'protocols', 29 | 'protocol', 30 | 'href', 31 | 'resource', 32 | 'user', 33 | 'port', 34 | 'name', 35 | 'owner', 36 | ]) 37 | 38 | POSSIBLE_REGEXES = ( 39 | re.compile(r'^(?Phttps?|git|ssh|rsync)\://' 40 | r'(?:(?P.+)@)*' 41 | r'(?P[a-z0-9_.-]*)' 42 | r'[:/]*' 43 | r'(?P[\d]+){0,1}' 44 | r'(?P\/((?P[\w\-]+)\/)?' 45 | r'((?P[\w\-\.]+?)(\.git|\/)?)?)$'), 46 | re.compile(r'(git\+)?' 47 | r'((?P\w+)://)' 48 | r'((?P\w+)@)?' 49 | r'((?P[\w\.\-]+))' 50 | r'(:(?P\d+))?' 51 | r'(?P(\/(?P\w+)/)?' 52 | r'(\/?(?P[\w\-]+)(\.git|\/)?)?)$'), 53 | re.compile(r'^(?:(?P.+)@)*' 54 | r'(?P[a-z0-9_.-]*)[:]*' 55 | r'(?P[\d]+){0,1}' 56 | r'(?P\/?(?P.+)/(?P.+).git)$'), 57 | re.compile(r'((?P\w+)@)?' 58 | r'((?P[\w\.\-]+))' 59 | r'[\:\/]{1,2}' 60 | r'(?P((?P\w+)/)?' 61 | r'((?P[\w\-]+)(\.git|\/)?)?)$'), 62 | ) 63 | 64 | 65 | class ParserError(Exception): 66 | """ Error raised when a URL can't be parsed. """ 67 | pass 68 | 69 | 70 | class Parser(object): 71 | """ 72 | A class responsible for parsing a GIT URL and return a `Parsed` object. 73 | """ 74 | 75 | def __init__(self, url): 76 | self._url = url 77 | 78 | def parse(self): 79 | """ 80 | Parses a GIT URL and returns an object. Raises an exception on invalid 81 | URL. 82 | 83 | :returns: Parsed object 84 | :raise: :class:`.ParserError` 85 | """ 86 | d = { 87 | 'pathname': None, 88 | 'protocols': self._get_protocols(), 89 | 'protocol': 'ssh', 90 | 'href': self._url, 91 | 'resource': None, 92 | 'user': None, 93 | 'port': None, 94 | 'name': None, 95 | 'owner': None, 96 | } 97 | for regex in POSSIBLE_REGEXES: 98 | match = regex.search(self._url) 99 | if match: 100 | d.update(match.groupdict()) 101 | break 102 | else: 103 | msg = "Invalid URL '{}'".format(self._url) 104 | raise ParserError(msg) 105 | 106 | return Parsed(**d) 107 | 108 | def _get_protocols(self): 109 | try: 110 | index = self._url.index('://') 111 | except ValueError: 112 | return [] 113 | 114 | return self._url[:index].split('+') 115 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | addopts = -v -rxXs --doctest-modules --cov giturlparse --cov-report term-missing 3 | norecursedirs = dist doc build .tox .eggs 4 | testpaths = test/ 5 | -------------------------------------------------------------------------------- /requirements-doc.txt: -------------------------------------------------------------------------------- 1 | -e . 2 | alabaster 3 | Sphinx 4 | -------------------------------------------------------------------------------- /requirements-test.txt: -------------------------------------------------------------------------------- 1 | flake8 2 | pytest 3 | pytest-cov 4 | pytest-mock 5 | twine 6 | yapf==0.21.0 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pbr 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = git-url-parse 3 | summary = git-url-parse - A simple GIT URL parser. 4 | description-file = README.rst 5 | author = John Dewey 6 | author-email = john@dewey.ws 7 | home-page = https://github.com/retr0h/git-url-parse 8 | classifier = 9 | Development Status :: 4 - Beta 10 | Environment :: Console 11 | Framework :: Flask 12 | Intended Audience :: Developers 13 | Intended Audience :: Information Technology 14 | Intended Audience :: System Administrators 15 | License :: OSI Approved :: MIT License 16 | Natural Language :: English 17 | Operating System :: OS Independent 18 | Programming Language :: Python :: 2 19 | Programming Language :: Python :: 2.7 20 | Programming Language :: Python :: 3 21 | Programming Language :: Python :: 3.4 22 | Programming Language :: Python :: 3.5 23 | Programming Language :: Python :: 3.6 24 | Topic :: System :: Systems Administration 25 | Topic :: Utilities 26 | 27 | [pbr] 28 | skip_authors = True 29 | skip_changelog = True 30 | warnerrors = True 31 | 32 | [global] 33 | setup-hooks = 34 | pbr.hooks.setup_hook 35 | 36 | [files] 37 | packages = 38 | giturlparse 39 | 40 | [build_sphinx] 41 | all_files = 1 42 | build-dir = doc/build 43 | source-dir = doc/source 44 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 2 | 3 | # Copyright (c) 2017 John Dewey 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | import setuptools 24 | 25 | setuptools.setup(setup_requires=['pbr'], pbr=True) 26 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coala/git-url-parse/d3eac95b21b2b166562e657fdfd974545653dfcc/test/__init__.py -------------------------------------------------------------------------------- /test/conftest.py: -------------------------------------------------------------------------------- 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 2 | 3 | # Copyright (c) 2017 John Dewey 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | import pytest 24 | 25 | 26 | @pytest.fixture() 27 | def first_match_urls(): 28 | return { 29 | 'http://example.com/owner/repo.git': { 30 | 'pathname': '/owner/repo.git', 31 | 'protocols': ['http'], 32 | 'protocol': 'http', 33 | 'href': 'http://example.com/owner/repo.git', 34 | 'resource': 'example.com', 35 | 'user': None, 36 | 'port': None, 37 | 'name': 'repo', 38 | 'owner': 'owner', 39 | }, 40 | 'http://example.com/owner/repo': { 41 | 'pathname': '/owner/repo', 42 | 'protocols': ['http'], 43 | 'protocol': 'http', 44 | 'href': 'http://example.com/owner/repo', 45 | 'resource': 'example.com', 46 | 'user': None, 47 | 'port': None, 48 | 'name': 'repo', 49 | 'owner': 'owner', 50 | }, 51 | 'http://example.com/owner/repo/': { 52 | 'pathname': '/owner/repo/', 53 | 'protocols': ['http'], 54 | 'protocol': 'http', 55 | 'href': 'http://example.com/owner/repo/', 56 | 'resource': 'example.com', 57 | 'user': None, 58 | 'port': None, 59 | 'name': 'repo', 60 | 'owner': 'owner', 61 | }, 62 | 'http://user@example.com/user/repo': { 63 | 'pathname': '/user/repo', 64 | 'protocols': ['http'], 65 | 'protocol': 'http', 66 | 'href': 'http://user@example.com/user/repo', 67 | 'resource': 'example.com', 68 | 'user': 'user', 69 | 'port': None, 70 | 'name': 'repo', 71 | 'owner': 'user', 72 | }, 73 | 'http://example.com:29418/owner/repo.git': { 74 | 'pathname': '/owner/repo.git', 75 | 'protocols': ['http'], 76 | 'protocol': 'http', 77 | 'href': 'http://example.com:29418/owner/repo.git', 78 | 'resource': 'example.com', 79 | 'user': None, 80 | 'port': '29418', 81 | 'name': 'repo', 82 | 'owner': 'owner', 83 | }, 84 | 'http://user@example.com:29418/user/repo': { 85 | 'pathname': '/user/repo', 86 | 'protocols': ['http'], 87 | 'protocol': 'http', 88 | 'href': 'http://user@example.com:29418/user/repo', 89 | 'resource': 'example.com', 90 | 'user': 'user', 91 | 'port': '29418', 92 | 'name': 'repo', 93 | 'owner': 'user', 94 | }, 95 | 'http://user@example.com:29418/user/repo/': { 96 | 'pathname': '/user/repo/', 97 | 'protocols': ['http'], 98 | 'protocol': 'http', 99 | 'href': 'http://user@example.com:29418/user/repo/', 100 | 'resource': 'example.com', 101 | 'user': 'user', 102 | 'port': '29418', 103 | 'name': 'repo', 104 | 'owner': 'user', 105 | }, 106 | 'http://example.com/repo': { 107 | 'pathname': '/repo', 108 | 'protocols': ['http'], 109 | 'protocol': 'http', 110 | 'href': 'http://example.com/repo', 111 | 'resource': 'example.com', 112 | 'user': None, 113 | 'port': None, 114 | 'name': 'repo', 115 | 'owner': None, 116 | }, 117 | 'https://example.com/owner/repo.git': { 118 | 'pathname': '/owner/repo.git', 119 | 'protocols': ['https'], 120 | 'protocol': 'https', 121 | 'href': 'https://example.com/owner/repo.git', 122 | 'resource': 'example.com', 123 | 'user': None, 124 | 'port': None, 125 | 'name': 'repo', 126 | 'owner': 'owner', 127 | }, 128 | 'https://example.com/owner/repo': { 129 | 'pathname': '/owner/repo', 130 | 'protocols': ['https'], 131 | 'protocol': 'https', 132 | 'href': 'https://example.com/owner/repo', 133 | 'resource': 'example.com', 134 | 'user': None, 135 | 'port': None, 136 | 'name': 'repo', 137 | 'owner': 'owner', 138 | }, 139 | 'https://user@example.com/user/repo': { 140 | 'pathname': '/user/repo', 141 | 'protocols': ['https'], 142 | 'protocol': 'https', 143 | 'href': 'https://user@example.com/user/repo', 144 | 'resource': 'example.com', 145 | 'user': 'user', 146 | 'port': None, 147 | 'name': 'repo', 148 | 'owner': 'user', 149 | }, 150 | 'https://example.com:29418/owner/repo.git': { 151 | 'pathname': '/owner/repo.git', 152 | 'protocols': ['https'], 153 | 'protocol': 'https', 154 | 'href': 'https://example.com:29418/owner/repo.git', 155 | 'resource': 'example.com', 156 | 'user': None, 157 | 'port': '29418', 158 | 'name': 'repo', 159 | 'owner': 'owner', 160 | }, 161 | 'https://user@example.com:29418/user/repo': { 162 | 'pathname': '/user/repo', 163 | 'protocols': ['https'], 164 | 'protocol': 'https', 165 | 'href': 'https://user@example.com:29418/user/repo', 166 | 'resource': 'example.com', 167 | 'user': 'user', 168 | 'port': '29418', 169 | 'name': 'repo', 170 | 'owner': 'user', 171 | }, 172 | 'https://example.com/repo': { 173 | 'pathname': '/repo', 174 | 'protocols': ['https'], 175 | 'protocol': 'https', 176 | 'href': 'https://example.com/repo', 177 | 'resource': 'example.com', 178 | 'user': None, 179 | 'port': None, 180 | 'name': 'repo', 181 | 'owner': None, 182 | }, 183 | 'rsync://example.com/owner/repo.git': { 184 | 'pathname': '/owner/repo.git', 185 | 'protocols': ['rsync'], 186 | 'protocol': 'rsync', 187 | 'href': 'rsync://example.com/owner/repo.git', 188 | 'resource': 'example.com', 189 | 'user': None, 190 | 'port': None, 191 | 'name': 'repo', 192 | 'owner': 'owner', 193 | }, 194 | 'git://example.com/owner/repo.git': { 195 | 'pathname': '/owner/repo.git', 196 | 'protocols': ['git'], 197 | 'protocol': 'git', 198 | 'href': 'git://example.com/owner/repo.git', 199 | 'resource': 'example.com', 200 | 'user': None, 201 | 'port': None, 202 | 'name': 'repo', 203 | 'owner': 'owner', 204 | }, 205 | 'git://example.com/owner/repo': { 206 | 'pathname': '/owner/repo', 207 | 'protocols': ['git'], 208 | 'protocol': 'git', 209 | 'href': 'git://example.com/owner/repo', 210 | 'resource': 'example.com', 211 | 'user': None, 212 | 'port': None, 213 | 'name': 'repo', 214 | 'owner': 'owner', 215 | }, 216 | 'git://example.com/owner/repo/': { 217 | 'pathname': '/owner/repo/', 218 | 'protocols': ['git'], 219 | 'protocol': 'git', 220 | 'href': 'git://example.com/owner/repo/', 221 | 'resource': 'example.com', 222 | 'user': None, 223 | 'port': None, 224 | 'name': 'repo', 225 | 'owner': 'owner', 226 | }, 227 | 'ssh://user@example.com/owner/repo.git': { 228 | 'pathname': '/owner/repo.git', 229 | 'protocols': ['ssh'], 230 | 'protocol': 'ssh', 231 | 'href': 'ssh://user@example.com/owner/repo.git', 232 | 'resource': 'example.com', 233 | 'user': 'user', 234 | 'port': None, 235 | 'name': 'repo', 236 | 'owner': 'owner', 237 | }, 238 | 'ssh://user@example.com:29418/owner/repo.git': { 239 | 'pathname': '/owner/repo.git', 240 | 'protocols': ['ssh'], 241 | 'protocol': 'ssh', 242 | 'href': 'ssh://user@example.com:29418/owner/repo.git', 243 | 'resource': 'example.com', 244 | 'user': 'user', 245 | 'port': '29418', 246 | 'name': 'repo', 247 | 'owner': 'owner', 248 | }, 249 | 'ssh://example.com/owner/repo.git': { 250 | 'pathname': '/owner/repo.git', 251 | 'protocols': ['ssh'], 252 | 'protocol': 'ssh', 253 | 'href': 'ssh://example.com/owner/repo.git', 254 | 'resource': 'example.com', 255 | 'user': None, 256 | 'port': None, 257 | 'name': 'repo', 258 | 'owner': 'owner', 259 | }, 260 | 'ssh://example.com:29418/owner/repo.git': { 261 | 'pathname': '/owner/repo.git', 262 | 'protocols': ['ssh'], 263 | 'protocol': 'ssh', 264 | 'href': 'ssh://example.com:29418/owner/repo.git', 265 | 'resource': 'example.com', 266 | 'user': None, 267 | 'port': '29418', 268 | 'name': 'repo', 269 | 'owner': 'owner', 270 | }, 271 | # https://github.com/retr0h/git-url-parse/issues/29 272 | 'https://github.com/sphinx-doc/sphinx.git': { 273 | 'pathname': '/sphinx-doc/sphinx.git', 274 | 'protocols': ['https'], 275 | 'protocol': 'https', 276 | 'href': 'https://github.com/sphinx-doc/sphinx.git', 277 | 'resource': 'github.com', 278 | 'user': None, 279 | 'port': None, 280 | 'name': 'sphinx', 281 | 'owner': 'sphinx-doc', 282 | }, 283 | # https://github.com/retr0h/git-url-parse/issues/33 284 | 'https://github.com/tterranigma/Stouts.openvpn': { 285 | 'pathname': '/tterranigma/Stouts.openvpn', 286 | 'protocols': ['https'], 287 | 'protocol': 'https', 288 | 'href': 'https://github.com/tterranigma/Stouts.openvpn', 289 | 'resource': 'github.com', 290 | 'user': None, 291 | 'port': None, 292 | 'name': 'Stouts.openvpn', 293 | 'owner': 'tterranigma', 294 | }, 295 | 'https://github.com/tterranigma/Stouts.openvpn/': { 296 | 'pathname': '/tterranigma/Stouts.openvpn/', 297 | 'protocols': ['https'], 298 | 'protocol': 'https', 299 | 'href': 'https://github.com/tterranigma/Stouts.openvpn/', 300 | 'resource': 'github.com', 301 | 'user': None, 302 | 'port': None, 303 | 'name': 'Stouts.openvpn', 304 | 'owner': 'tterranigma', 305 | }, 306 | # https://github.com/retr0h/git-url-parse/issues/33 307 | 'https://github.com/tterranigma/Stouts.openvpn.git': { 308 | 'pathname': '/tterranigma/Stouts.openvpn.git', 309 | 'protocols': ['https'], 310 | 'protocol': 'https', 311 | 'href': 'https://github.com/tterranigma/Stouts.openvpn.git', 312 | 'resource': 'github.com', 313 | 'user': None, 314 | 'port': None, 315 | 'name': 'Stouts.openvpn', 316 | 'owner': 'tterranigma', 317 | }, 318 | } 319 | 320 | 321 | @pytest.fixture() 322 | def second_match_urls(): 323 | return { 324 | 'git+ssh://example.com/owner/repo.git': { 325 | 'pathname': '/owner/repo.git', 326 | 'protocols': ['git', 'ssh'], 327 | 'protocol': 'ssh', 328 | 'href': 'git+ssh://example.com/owner/repo.git', 329 | 'resource': 'example.com', 330 | 'user': None, 331 | 'port': None, 332 | 'name': 'repo', 333 | 'owner': 'owner', 334 | }, 335 | 'git+ssh://example.com:9999/owner/repo.git': { 336 | 'pathname': '/owner/repo.git', 337 | 'protocols': ['git', 'ssh'], 338 | 'protocol': 'ssh', 339 | 'href': 'git+ssh://example.com:9999/owner/repo.git', 340 | 'resource': 'example.com', 341 | 'user': None, 342 | 'port': '9999', 343 | 'name': 'repo', 344 | 'owner': 'owner', 345 | }, 346 | 'git+https://example.com/owner/repo.git': { 347 | 'pathname': '/owner/repo.git', 348 | 'protocols': ['git', 'https'], 349 | 'protocol': 'https', 350 | 'href': 'git+https://example.com/owner/repo.git', 351 | 'resource': 'example.com', 352 | 'user': None, 353 | 'port': None, 354 | 'name': 'repo', 355 | 'owner': 'owner', 356 | }, 357 | 'git+https://example.com:9999/owner/repo.git': { 358 | 'pathname': '/owner/repo.git', 359 | 'protocols': ['git', 'https'], 360 | 'protocol': 'https', 361 | 'href': 'git+https://example.com:9999/owner/repo.git', 362 | 'resource': 'example.com', 363 | 'user': None, 364 | 'port': '9999', 365 | 'name': 'repo', 366 | 'owner': 'owner', 367 | }, 368 | } 369 | 370 | 371 | @pytest.fixture() 372 | def third_match_urls(): 373 | return { 374 | 'user@example.com:/owner/repo.git': { 375 | 'pathname': '/owner/repo.git', 376 | 'protocols': [], 377 | 'protocol': 'ssh', 378 | 'href': 'user@example.com:/owner/repo.git', 379 | 'resource': 'example.com', 380 | 'user': 'user', 381 | 'port': None, 382 | 'name': 'repo', 383 | 'owner': 'owner', 384 | }, 385 | 'user@example.com:owner/repo.git': { 386 | 'pathname': 'owner/repo.git', 387 | 'protocols': [], 388 | 'protocol': 'ssh', 389 | 'href': 'user@example.com:owner/repo.git', 390 | 'resource': 'example.com', 391 | 'user': 'user', 392 | 'port': None, 393 | 'name': 'repo', 394 | 'owner': 'owner', 395 | }, 396 | 'user@foo-example.com:owner/repo.git': { 397 | 'pathname': 'owner/repo.git', 398 | 'protocols': [], 399 | 'protocol': 'ssh', 400 | 'href': 'user@foo-example.com:owner/repo.git', 401 | 'resource': 'foo-example.com', 402 | 'user': 'user', 403 | 'port': None, 404 | 'name': 'repo', 405 | 'owner': 'owner', 406 | }, 407 | # GitLab 408 | 'user@foo-example.com:9999/owner/repo.git': { 409 | 'pathname': '/owner/repo.git', 410 | 'protocols': [], 411 | 'protocol': 'ssh', 412 | 'href': 'user@foo-example.com:9999/owner/repo.git', 413 | 'resource': 'foo-example.com', 414 | 'user': 'user', 415 | 'port': '9999', 416 | 'name': 'repo', 417 | 'owner': 'owner', 418 | }, 419 | } 420 | 421 | 422 | @pytest.fixture() 423 | def fourth_match_urls(): 424 | return { 425 | # NOTE(retr0h): This should really be handled by regexp group 3 426 | 'user@example.com:repo.git': { 427 | 'pathname': 'repo.git', 428 | 'protocols': [], 429 | 'protocol': 'ssh', 430 | 'href': 'user@example.com:repo.git', 431 | 'resource': 'example.com', 432 | 'user': 'user', 433 | 'port': None, 434 | 'name': 'repo', 435 | 'owner': None, 436 | }, 437 | 'example.com:/owner/repo.git': { 438 | 'pathname': '/owner/repo.git', 439 | 'protocols': [], 440 | 'protocol': 'ssh', 441 | 'href': 'example.com:/owner/repo.git', 442 | 'resource': 'example.com', 443 | 'user': None, 444 | 'port': None, 445 | 'name': 'repo', 446 | 'owner': 'owner', 447 | }, 448 | 'example.com:owner/repo.git': { 449 | 'pathname': 'owner/repo.git', 450 | 'protocols': [], 451 | 'protocol': 'ssh', 452 | 'href': 'example.com:owner/repo.git', 453 | 'resource': 'example.com', 454 | 'user': None, 455 | 'port': None, 456 | 'name': 'repo', 457 | 'owner': 'owner', 458 | }, 459 | 'example.com:repo.git': { 460 | 'pathname': 'repo.git', 461 | 'protocols': [], 462 | 'protocol': 'ssh', 463 | 'href': 'example.com:repo.git', 464 | 'resource': 'example.com', 465 | 'user': None, 466 | 'port': None, 467 | 'name': 'repo', 468 | 'owner': None, 469 | }, 470 | } 471 | 472 | 473 | @pytest.fixture() 474 | def invalid_strings(): 475 | return ['', 'not a valid URL'] 476 | -------------------------------------------------------------------------------- /test/test_parser.py: -------------------------------------------------------------------------------- 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 2 | 3 | # Copyright (c) 2017 John Dewey 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | # THE SOFTWARE. 22 | 23 | import pytest 24 | 25 | from giturlparse import parser 26 | 27 | 28 | @pytest.mark.parametrize("test_input", [ 29 | 'first_match_urls', 30 | 'second_match_urls', 31 | 'third_match_urls', 32 | 'fourth_match_urls', 33 | ]) 34 | def test_parse(request, test_input): 35 | url_data = request.getfixturevalue(test_input) 36 | for url, d in url_data.items(): 37 | p = parser.Parser(url) 38 | result = p.parse() 39 | 40 | assert d['pathname'] == result.pathname 41 | assert d['protocols'] == result.protocols 42 | assert d['protocol'] == result.protocol 43 | assert d['href'] == result.href 44 | assert d['resource'] == result.resource 45 | assert d['user'] == result.user 46 | assert d['port'] == result.port 47 | assert d['name'] == result.name 48 | assert d['owner'] == result.owner 49 | 50 | 51 | def test_parse_raises_on_invalid_string(invalid_strings): 52 | for invalid_string in invalid_strings: 53 | p = parser.Parser(invalid_string) 54 | with pytest.raises(parser.ParserError): 55 | p.parse() 56 | 57 | 58 | def test_get_protocol_multiple_protocols(): 59 | p = parser.Parser('git+ssh://git@example.com/Owner/Repository.git') 60 | 61 | assert ['git', 'ssh'] == p._get_protocols() 62 | 63 | 64 | def test_get_protocol_no_protocols(): 65 | p = parser.Parser('//example.com/foo') 66 | 67 | assert [] == p._get_protocols() 68 | 69 | 70 | def test_get_protocol_one_protocols(): 71 | p = parser.Parser('ssh://git@example.com/Owner/Repository.git') 72 | 73 | assert ['ssh'] == p._get_protocols() 74 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | minversion = 1.8 3 | envlist = 4 | py{27,34,35,36}-unit 5 | lint 6 | format-check 7 | doc 8 | py{27,36}-build 9 | skipsdist = true 10 | 11 | [travis] 12 | python = 13 | 2.7: py27-unit, lint, format-check, bats 14 | 3.4: py34-unit, lint, format-check, bats 15 | 3.5: py35-unit, lint, format-check, bats 16 | 3.6: py36-unit, lint, format-check, bats 17 | 18 | [testenv] 19 | passenv = * 20 | setenv = COVERAGE_FILE={toxworkdir}/.coverage 21 | deps = 22 | -rrequirements.txt 23 | -rrequirements-test.txt 24 | commands = 25 | unit: py.test -vv 26 | build: python setup.py sdist bdist_wheel 27 | 28 | [testenv:lint] 29 | commands = 30 | flake8 31 | 32 | [testenv:format] 33 | commands = 34 | yapf -i -r giturlparse// test/ 35 | 36 | [testenv:format-check] 37 | commands = 38 | yapf -d -r giturlparse/ test/ 39 | 40 | [testenv:doc] 41 | passenv = * 42 | deps= 43 | -rrequirements-doc.txt 44 | commands= 45 | python setup.py build_sphinx --builder=html 46 | 47 | [testenv:release] 48 | commands= 49 | twine upload dist/* 50 | --------------------------------------------------------------------------------