Skip to content
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

Custom scheme is not respected in as_string #38

Open
denizdogan opened this issue Aug 20, 2019 · 1 comment
Open

Custom scheme is not respected in as_string #38

denizdogan opened this issue Aug 20, 2019 · 1 comment

Comments

@denizdogan
Copy link

ipython
Python 3.7.3 (default, Apr 12 2019, 14:40:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from purl import URL

In [2]: url = URL("foobar:///my_path")

In [3]: url.scheme()
Out[3]: 'foobar'

In [4]: url.as_string()
Out[4]: '/my_path'

I expect Out[4] to be "foobar:///my_path"

@ljluestc
Copy link

from purl import URL

class CustomURL(URL):
    def as_string(self):
        # Get the string representation of the URL without the scheme
        url_string = super().as_string()[2:]
        # Add the custom scheme back to the URL string
        return f"{self.scheme()}://{url_string}"

# Test the CustomURL class
url = CustomURL("foobar:///my_path")
print(url.as_string())  # Output: "foobar:///my_path"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants