Comments (7)
btw -- nice work, overall!
from uri.
Actually, you can't reject paths with one. What an awkward state to be in. Is the extra slash in http://foo.bar//blah
possibly meaningful?
I suppose there's no route to rejection. I guess expected behavior would be to implicitly add a slash, and if path
is set manually with a slash, it results in a url like http://foo.com//blah
.
from uri.
Hmm; it is true that you can provide paths that have no root. Technically, your own code above is buggy, though the URI class is not helping. Specifically, assign /blah
, not blah
, or use the division helper:
>>> uri = URI('http://foo.com') # no path part at all
>>> uri.path
PurePosixPath('.')
>>> uri.path = '/foo'
>>> uri
URI('http://foo.com/foo')
>>> uri = URI('http://foo.com')
# "natural" syntax for "extending" the path / resolving relative references
>>> uri / 'foo'
URI('http://foo.com/foo')
# scheme + authority part, plus a path part = rooted path at that authority over that protocol
>>> URI('http://foo.com') / URI('bar/baz')
URI('http://foo.com/bar/baz')
I'll leave this open for now as a reminder that non-root paths should be rooted for presentation, or, if there is an authority present, to only accept rooted paths. foo/bar
isn't a valid URI path, where /foo/bar
is. Good catch!
Edited to add: non-rooted paths remain useful, at least for URI without other, earlier components defined. This would allow you to, for example, use the division operator to combine two URI, the second being a URI fragment. (The second having uri.relative == True
.). Think of relative links on a page; those are very much fragments, usually of non-root paths, and part of the reason why the division operator was added, reference issue #3.
Edited to add: I'm not seeing double slashes if you assign a rooted path. How are you getting that as a result?
from uri.
>>> from uri import URI
>>> uri = URI('http://foo.com') # not a fragment; has an authority
>>> uri.path = '/foo'; uri # rooted path assignment is OK
URI('http://foo.com/foo')
>>> uri.path = 'foo' # rootless path assignment is NOT OK
ValueError Traceback (most recent call last)
<ipython-input-3-d765cb2bdfb3> in <module>()
----> 1 uri.path = 'foo'
~/Projects/marrow/web/uri/uri/part/path.py in __set__(self, obj, value)
28
29 if obj.authority and not value.startswith('/'):
---> 30 raise ValueError("Can only assign rooted paths to URI with authority.")
31
32 super(PathPart, self).__set__(obj, value)
ValueError: Can only assign rooted paths to URI with authority.
>>> uri = URI('http://foo.com')
>>> uri2 = URI() # let's construct a fragment this time
>>> uri2.path = 'foo'; uri2
URI('foo')
>>> uri.resolve(uri2) # relative reference resolution against an authority becomes rooted
URI('http://foo.com/foo')
Available in 84e0787 for testing prior to release. (Tests added in 74a16f6.)
from uri.
from uri.
Marking as resolved. (Rejection is preferable to me; from the Zen of Python: errors should never pass silently, esp. as if you aren't expecting a relative path it might have security implications.). Edited to add: URI are not just URL. This is not a URL object, nor a URL-handling library, specifically. Your bug was intentionally trying to write "http://foo.com" + "blah"
, which URI happily (and incorrectly) allowed you to do. (2+2==42 → if you want this to be true, it's not a bug in Python's addition operator…)
from uri.
I most definitely would not want that to be true -- what I want is for there to be an implicit slash if an unrooted path is attached to a host, or better yet, for the library to reject unrooted paths in that case. Which it does now, so everything's roly-poly.
from uri.
Related Issues (20)
- Use slice notation on URI's for authentication creds HOT 3
- Rootless file URI does not round trip HOT 10
- Add method to reconstruct the request URI from a WSGI environment. HOT 2
- Missing scheme HOT 3
- Utilize "services" index for default port identification.
- Implement "URL fopen"-like behavior.
- Support and utilise native IP address representations. HOT 3
- Automatically handle punycode encoding and decoding. HOT 2
- Deprecation Warning for import of namedtuple from collections instead of collections.abc HOT 7
- disappearing "//" HOT 10
- Implement Python __hash__ method to permit use as dictionary keys and set members. HOT 7
- URI with empty path HOT 9
- URI variant that pulls in page titles during HTML expansion.
- ImportError: cannot import name 'ItemsView' from 'collections' HOT 1
- Correct Pretty-RFC links. HOT 1
- Add "yarl" to the "Migrating"-section in the README
- Please release 3.0.0 HOT 3
- Make "empty path element" handling more explicit.
- For some schemes, URLs with no authority are rendered incorrectly HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uri.