upa-url 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ # INFO:
2
+ # https://nanobind.readthedocs.io/en/latest/building.html
3
+ #
4
+ cmake_minimum_required(VERSION 3.15...3.27)
5
+ project(upa_url_py LANGUAGES CXX)
6
+
7
+ set(CMAKE_CXX_STANDARD 17)
8
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
9
+
10
+ if (CMAKE_VERSION VERSION_LESS 3.18)
11
+ set(DEV_MODULE Development)
12
+ else()
13
+ set(DEV_MODULE Development.Module)
14
+ endif()
15
+
16
+ find_package(Python 3.8
17
+ COMPONENTS Interpreter ${DEV_MODULE} REQUIRED
18
+ OPTIONAL_COMPONENTS Development.SABIModule)
19
+
20
+ find_package(nanobind CONFIG REQUIRED)
21
+
22
+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
23
+ set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
24
+ set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
25
+ endif()
26
+
27
+ include_directories(ext)
28
+
29
+ nanobind_add_module(
30
+ # Module name
31
+ upa_url
32
+
33
+ # Target the stable ABI for Python 3.12+, which reduces
34
+ # the number of binary wheels that must be built. This
35
+ # does nothing on older Python versions
36
+ STABLE_ABI
37
+
38
+ # Build libnanobind statically and merge it into the
39
+ # extension (which itself remains a shared library)
40
+ NB_STATIC
41
+
42
+ # Source code
43
+ src/upa_url_bind.cpp
44
+ ext/upa/url.cpp)
45
+
46
+ # Install directive for scikit-build-core
47
+ install(TARGETS upa_url LIBRARY DESTINATION upa_url)
upa_url-0.0.2/LICENSE ADDED
@@ -0,0 +1,102 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2016-2025 Rimas Misevičius
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+
26
+ -------------------------------------------------------------------------------
27
+
28
+ Files buffer.h, url.h, url_percent_encode.h contains portions of modified code
29
+ from the Chromium project licensed as follows:
30
+
31
+ // Copyright 2015 The Chromium Authors. All rights reserved.
32
+ //
33
+ // Redistribution and use in source and binary forms, with or without
34
+ // modification, are permitted provided that the following conditions are
35
+ // met:
36
+ //
37
+ // * Redistributions of source code must retain the above copyright
38
+ // notice, this list of conditions and the following disclaimer.
39
+ // * Redistributions in binary form must reproduce the above
40
+ // copyright notice, this list of conditions and the following disclaimer
41
+ // in the documentation and/or other materials provided with the
42
+ // distribution.
43
+ // * Neither the name of Google Inc. nor the names of its
44
+ // contributors may be used to endorse or promote products derived from
45
+ // this software without specific prior written permission.
46
+ //
47
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58
+
59
+ -------------------------------------------------------------------------------
60
+
61
+ Files config.h, url_utf.h contains portions of modified code from the ICU
62
+ project licensed as follows:
63
+
64
+ UNICODE LICENSE V3
65
+
66
+ COPYRIGHT AND PERMISSION NOTICE
67
+
68
+ Copyright © 2016-2023 Unicode, Inc.
69
+
70
+ NOTICE TO USER: Carefully read the following legal agreement. BY
71
+ DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
72
+ SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
73
+ TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
74
+ DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
75
+
76
+ Permission is hereby granted, free of charge, to any person obtaining a
77
+ copy of data files and any associated documentation (the "Data Files") or
78
+ software and any associated documentation (the "Software") to deal in the
79
+ Data Files or Software without restriction, including without limitation
80
+ the rights to use, copy, modify, merge, publish, distribute, and/or sell
81
+ copies of the Data Files or Software, and to permit persons to whom the
82
+ Data Files or Software are furnished to do so, provided that either (a)
83
+ this copyright and permission notice appear with all copies of the Data
84
+ Files or Software, or (b) this copyright and permission notice appear in
85
+ associated Documentation.
86
+
87
+ THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
88
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
89
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
90
+ THIRD PARTY RIGHTS.
91
+
92
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
93
+ BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
94
+ OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
95
+ WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
96
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
97
+ FILES OR SOFTWARE.
98
+
99
+ Except as contained in this notice, the name of a copyright holder shall
100
+ not be used in advertising or otherwise to promote the sale, use or other
101
+ dealings in these Data Files or Software without prior written
102
+ authorization of the copyright holder.
upa_url-0.0.2/PKG-INFO ADDED
@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: upa_url
3
+ Version: 0.0.2
4
+ Summary: WHATWG URL Standard compliant URL parser library
5
+ Author-Email: =?utf-8?q?Rimas_Misevi=C4=8Dius?= <rmisev3@gmail.com>
6
+ License-Expression: BSD-2-Clause
7
+ License-File: LICENSE
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Programming Language :: C++
10
+ Classifier: Programming Language :: Python :: 3
11
+ Project-URL: Homepage, https://github.com/upa-url/upa_url-py
12
+ Project-URL: Issues, https://github.com/upa-url/upa_url-py/issues
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+
16
+ # upa_url package
17
+
18
+ This package provides Python bindings for [Upa URL](https://github.com/upa-url/upa) – a library compliant with the [WHATWG URL standard](https://url.spec.whatwg.org/). This is the same standard followed by modern browsers and JavaScript runtimes such as Bun, Deno, and Node.js.
19
+
20
+ This package is designed to be as close to the URL standard as possible. It uses the same class names ([URL](https://url.spec.whatwg.org/#url-class), [URLSearchParams](https://url.spec.whatwg.org/#interface-urlsearchparams)), their function names, the same function parameters, and the same behavior.
21
+
22
+ ## Installation
23
+
24
+ ```sh
25
+ pip install upa_url
26
+ ```
27
+
28
+ If the binary wheel is not available for your platform, then you will need a C++ compiler that supports C++17 and CMake to build the Python package.
29
+
30
+ ## Getting started
31
+
32
+ First you need import classes:
33
+ ```python
34
+ from upa_url import URL, URLSearchParams
35
+ ```
36
+
37
+ ### URL class
38
+
39
+ The `URL` class provides a structured way to parse, manipulate, and serialize URLs.
40
+
41
+ An URL can be parsed using one of two methods:
42
+ 1. Use `URL` constructor. It throws an exception on error:
43
+ ```python
44
+ try:
45
+ url = URL('https://upa-url.github.io/docs/')
46
+ print(url.href)
47
+ except Exception:
48
+ print('URL parse error')
49
+ ```
50
+ 2. Use `URL.parse` fucntion. It returns `None` on error:
51
+ ```python
52
+ url = URL.parse('docs', 'https://upa-url.github.io')
53
+ if url is not None:
54
+ print(url.href)
55
+ ```
56
+ The parsed URL object components can be accessed using getters and setters: `href`, `origin` (only get value), `protocol`, `username`, `password`, `host`, `hostname`, `port`, `pathname`, `search` and `hash`. Also you can get and change search parameters using `searchParams` getter which returns `URLSearchParams` object associated with URL:
57
+ ```python
58
+ url = URL.parse('https://example.org')
59
+ if url is not None:
60
+ url.searchParams.append('lang', 'lt')
61
+ print(url.href) # https://example.org/?lang=lt
62
+ ```
63
+
64
+ To serialize parsed URL use `url.href` or `str(url)`.
65
+
66
+ If you need only check URL validity, then `URL.canParse` function can be used:
67
+ ```python
68
+ if URL.canParse('docs', 'https://upa-url.github.io'):
69
+ print('URL is valid')
70
+ ```
71
+
72
+ ### URLSearchParams class
73
+
74
+ The `URLSearchParams` class provides a structured way to parse, manipulate, and serialize the query string of a URL.
75
+
76
+ An `URLSearchParams` object can be created by using constructor:
77
+ 1. To create empty: `params = URLSearchParams()`
78
+ 2. Create from string: `params = URLSearchParams('lang=lt&id=123')`
79
+ 3. Create from dictionary or list:
80
+ ```python
81
+ params1 = URLSearchParams({'lang': 'lt', 'id': '123'})
82
+ params2 = URLSearchParams([('lang', 'lt'), ['id', '123']])
83
+ ```
84
+
85
+ Use `get` or `getAll` to retrieve parameter values:
86
+ ```python
87
+ params = URLSearchParams('a=b&a=c&b=10')
88
+ print(params.get('a')) # b
89
+ print(params.getAll('a')) # ['b', 'c']
90
+ ```
91
+
92
+ To check for name and optionally value in parameters, use the `has` function:
93
+ ```python
94
+ print(params.has('a')) # True
95
+ print(params.has('a', 'c')) # True
96
+ print(params.has('c')) # False
97
+ ```
98
+
99
+ Iterate over all parameters:
100
+ ```python
101
+ params = URLSearchParams('a=1&b=2')
102
+ # Get all name - value pairs:
103
+ for name, value in params:
104
+ print(name, '=', value)
105
+ # Get all parameter names
106
+ for name in params.keys():
107
+ print(name)
108
+ # Get all parameter values
109
+ for value in params.values():
110
+ print(value)
111
+ ```
112
+
113
+ Count parameters:
114
+ ```python
115
+ print(params.size) # 2
116
+ print(len(params)) # 2
117
+ ```
118
+
119
+ To serialize `URLSearchParams` object use `str(params)`.
120
+
121
+ There are functions to manipulate search parameters:
122
+ 1. Add or replace parameters:
123
+ ```python
124
+ params = URLSearchParams('a=a')
125
+ params.append('a', 'aa')
126
+ params.append('b', 'bb')
127
+ print(params) # a=a&a=aa&b=bb
128
+ params.set('a', '1')
129
+ print(params) # a=1&b=bb
130
+ ```
131
+ 2. Remove parameters:
132
+ ```python
133
+ params = URLSearchParams('a=a&a=aa&b=b&b=bb')
134
+ params.delete('a')
135
+ print(params) # b=b&b=bb
136
+ params.delete('b', 'bb')
137
+ print(params) # b=b
138
+ ```
139
+ 3. Sort parameters by name:
140
+ ```python
141
+ params = URLSearchParams('c=1&b=2&a=3')
142
+ params.sort()
143
+ print(params) # a=3&b=2&c=1
144
+ ```
145
+
146
+ ## License
147
+
148
+ This package is licensed under the [BSD 2-Clause License](https://opensource.org/license/bsd-2-clause/) (see `LICENSE` file).
@@ -0,0 +1,133 @@
1
+ # upa_url package
2
+
3
+ This package provides Python bindings for [Upa URL](https://github.com/upa-url/upa) – a library compliant with the [WHATWG URL standard](https://url.spec.whatwg.org/). This is the same standard followed by modern browsers and JavaScript runtimes such as Bun, Deno, and Node.js.
4
+
5
+ This package is designed to be as close to the URL standard as possible. It uses the same class names ([URL](https://url.spec.whatwg.org/#url-class), [URLSearchParams](https://url.spec.whatwg.org/#interface-urlsearchparams)), their function names, the same function parameters, and the same behavior.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pip install upa_url
11
+ ```
12
+
13
+ If the binary wheel is not available for your platform, then you will need a C++ compiler that supports C++17 and CMake to build the Python package.
14
+
15
+ ## Getting started
16
+
17
+ First you need import classes:
18
+ ```python
19
+ from upa_url import URL, URLSearchParams
20
+ ```
21
+
22
+ ### URL class
23
+
24
+ The `URL` class provides a structured way to parse, manipulate, and serialize URLs.
25
+
26
+ An URL can be parsed using one of two methods:
27
+ 1. Use `URL` constructor. It throws an exception on error:
28
+ ```python
29
+ try:
30
+ url = URL('https://upa-url.github.io/docs/')
31
+ print(url.href)
32
+ except Exception:
33
+ print('URL parse error')
34
+ ```
35
+ 2. Use `URL.parse` fucntion. It returns `None` on error:
36
+ ```python
37
+ url = URL.parse('docs', 'https://upa-url.github.io')
38
+ if url is not None:
39
+ print(url.href)
40
+ ```
41
+ The parsed URL object components can be accessed using getters and setters: `href`, `origin` (only get value), `protocol`, `username`, `password`, `host`, `hostname`, `port`, `pathname`, `search` and `hash`. Also you can get and change search parameters using `searchParams` getter which returns `URLSearchParams` object associated with URL:
42
+ ```python
43
+ url = URL.parse('https://example.org')
44
+ if url is not None:
45
+ url.searchParams.append('lang', 'lt')
46
+ print(url.href) # https://example.org/?lang=lt
47
+ ```
48
+
49
+ To serialize parsed URL use `url.href` or `str(url)`.
50
+
51
+ If you need only check URL validity, then `URL.canParse` function can be used:
52
+ ```python
53
+ if URL.canParse('docs', 'https://upa-url.github.io'):
54
+ print('URL is valid')
55
+ ```
56
+
57
+ ### URLSearchParams class
58
+
59
+ The `URLSearchParams` class provides a structured way to parse, manipulate, and serialize the query string of a URL.
60
+
61
+ An `URLSearchParams` object can be created by using constructor:
62
+ 1. To create empty: `params = URLSearchParams()`
63
+ 2. Create from string: `params = URLSearchParams('lang=lt&id=123')`
64
+ 3. Create from dictionary or list:
65
+ ```python
66
+ params1 = URLSearchParams({'lang': 'lt', 'id': '123'})
67
+ params2 = URLSearchParams([('lang', 'lt'), ['id', '123']])
68
+ ```
69
+
70
+ Use `get` or `getAll` to retrieve parameter values:
71
+ ```python
72
+ params = URLSearchParams('a=b&a=c&b=10')
73
+ print(params.get('a')) # b
74
+ print(params.getAll('a')) # ['b', 'c']
75
+ ```
76
+
77
+ To check for name and optionally value in parameters, use the `has` function:
78
+ ```python
79
+ print(params.has('a')) # True
80
+ print(params.has('a', 'c')) # True
81
+ print(params.has('c')) # False
82
+ ```
83
+
84
+ Iterate over all parameters:
85
+ ```python
86
+ params = URLSearchParams('a=1&b=2')
87
+ # Get all name - value pairs:
88
+ for name, value in params:
89
+ print(name, '=', value)
90
+ # Get all parameter names
91
+ for name in params.keys():
92
+ print(name)
93
+ # Get all parameter values
94
+ for value in params.values():
95
+ print(value)
96
+ ```
97
+
98
+ Count parameters:
99
+ ```python
100
+ print(params.size) # 2
101
+ print(len(params)) # 2
102
+ ```
103
+
104
+ To serialize `URLSearchParams` object use `str(params)`.
105
+
106
+ There are functions to manipulate search parameters:
107
+ 1. Add or replace parameters:
108
+ ```python
109
+ params = URLSearchParams('a=a')
110
+ params.append('a', 'aa')
111
+ params.append('b', 'bb')
112
+ print(params) # a=a&a=aa&b=bb
113
+ params.set('a', '1')
114
+ print(params) # a=1&b=bb
115
+ ```
116
+ 2. Remove parameters:
117
+ ```python
118
+ params = URLSearchParams('a=a&a=aa&b=b&b=bb')
119
+ params.delete('a')
120
+ print(params) # b=b&b=bb
121
+ params.delete('b', 'bb')
122
+ print(params) # b=b
123
+ ```
124
+ 3. Sort parameters by name:
125
+ ```python
126
+ params = URLSearchParams('c=1&b=2&a=3')
127
+ params.sort()
128
+ print(params) # a=3&b=2&c=1
129
+ ```
130
+
131
+ ## License
132
+
133
+ This package is licensed under the [BSD 2-Clause License](https://opensource.org/license/bsd-2-clause/) (see `LICENSE` file).