Skip to content

Introduction of aurl utility #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions autils/aurl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat Inc. 2013-2014
# Author: Lucas Meneghel Rodrigues <[email protected]>

"""
URL related functions.

The strange name is to avoid accidental naming collisions in code.
"""

import urllib.parse

#: The most common schemes (protocols) used in URLs
COMMON_SCHEMES = ("http", "https", "ftp", "git")


def is_url(path):
"""Return `True` if path looks like an URL of common protocols.

Refer to :data:`COMMON_SCHEMES` for the list of common protocols.

:param path: path to check.
:rtype: Boolean.
"""
url_parts = urllib.parse.urlparse(path)
return url_parts[0] in COMMON_SCHEMES
16 changes: 16 additions & 0 deletions metadata/aurl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: aurl
description: URL related functions
categories:
- Network
- Files
maintainers:
- name: Jan Richter
email: [email protected]
github_usr_name: richtja
supported_platforms:
- CentOS Stream 9
- Fedora 36
- Fedora 37
tests:
- tests/modules/aurl.py
remote: false
31 changes: 31 additions & 0 deletions tests/modules/aurl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest

from autils import aurl


class TestAUrl(unittest.TestCase):
def test_valid_urls(self):
valid_urls = [
"http://www.example.com",
"https://www.example.com/path",
"ftp://ftp.example.com",
"git://github.com/user/repo.git",
]
for url in valid_urls:
self.assertTrue(aurl.is_url(url), f"Expected {url} to be a valid URL")

invalid_urls = [
"www.example.com",
"htt://example",
"file:///path/to/file",
]
for url in invalid_urls:
self.assertFalse(aurl.is_url(url), f"Expected {url} to be an invalid URL")

non_urls = [
"/path/to/file",
"not a url",
"",
]
for path in non_urls:
self.assertFalse(aurl.is_url(path), f"Expected {path} to not be a URL")
Loading