Given a string, produce a new URL instance. The format of the URL generally follows `RFC-1738 <https://www.ietf.org/rfc/rfc1738.txt>`_, with some exceptions, including that underscores, and not dashes or periods, are accepted within the "scheme" portion. If a :class:`.URL` obje
(name_or_url: Union[str, URL])
| 837 | |
| 838 | |
| 839 | def make_url(name_or_url: Union[str, URL]) -> URL: |
| 840 | """Given a string, produce a new URL instance. |
| 841 | |
| 842 | The format of the URL generally follows `RFC-1738 |
| 843 | <https://www.ietf.org/rfc/rfc1738.txt>`_, with some exceptions, including |
| 844 | that underscores, and not dashes or periods, are accepted within the |
| 845 | "scheme" portion. |
| 846 | |
| 847 | If a :class:`.URL` object is passed, it is returned as is. |
| 848 | |
| 849 | .. seealso:: |
| 850 | |
| 851 | :ref:`database_urls` |
| 852 | |
| 853 | """ |
| 854 | |
| 855 | if isinstance(name_or_url, str): |
| 856 | return _parse_url(name_or_url) |
| 857 | elif not isinstance(name_or_url, URL) and not hasattr( |
| 858 | name_or_url, "_sqla_is_testing_if_this_is_a_mock_object" |
| 859 | ): |
| 860 | raise exc.ArgumentError( |
| 861 | f"Expected string or URL object, got {name_or_url!r}" |
| 862 | ) |
| 863 | else: |
| 864 | return name_or_url |
| 865 | |
| 866 | |
| 867 | def _parse_url(name: str) -> URL: |