Comments (7)
I agree, this would be beneficial. Can't just have them hash the same as their string representation, though, so some consideration will have to be made. 🤔 (Can't just "pass the buck" down to hash(str(self))
.)
from uri.
After investigation, this is not possible with the URI class, which is mutable. Explanation here. Instead, if one must use these as keys or in sets, you must cast to str
or otherwise explicitly serialize for such use, as confusion may rapidly arise between URI that are equivalent, but hash differently—you must agree on a serialization and normalization, including the relevance of such factors as query string parameters (fragment reference?) in that equivalence.
The URI type as built is intended to represent normalized whole URI (not ones with relative internal markers, and not fragments), and additionally qualifies under RFC-3986 as a backward compatible parser, not a strict one, ref. As it encapsulates a mutable mapping to represent URL-encoded query string parameters, and the incorporated path may be altered in-place, URI is not hashable.
from uri.
mutable? O wow, I did not realize that. That is a deal breaker for the project that uses it as the URI is part of an immutable data structure.
Thanks for all your help so far !
from uri.
I'm worried that there are larger issues at play in your usage of URI without seeming regard to normalization and proper equality comparison. 😕 I'll endeavor to update the documentation to make it more explicit and clear that by virtue of the features provided a URI instance is inherently mutable.
Specific methods, such as resolve
, __div__
(/
) and __floordiv__
(//
) return new instances, leaving the original unmodified. Even unusual behaviour such as slicing notation (uri[user:pass]
) returns a new instance. The problems are the nested mutable collections, inheriting a problem, and that any given attribute may be replaced at any point in time, a far more direct problem.
from uri.
Thanks for the elaboration.
I'm not sure what you are worried about exactly. I quickly scanned the manual and did not spot any issues. I did not expect mutability so I didn't specifically search for it.
I appreciate that things like equality are properly implemented. But that should not result in mutable objects. Because you mention this, I assume you want to cache some intermediate results to support this functionality. But those are caches and should not be considered a mutation of the object; nor should these caches be part of a hash code.
The problems are the nested mutable collections
That is not necessarily a problem, unless you expose these to the outside.
from uri.
[…all of that…]
Noted.
…I assume…
Noted previously.
from uri.
FWIW, not sure if it is any use for you but I slapped together an URI class to fit my needs. I checked several other existing uri packages but none seemed to provide what I want (yours was the only one I really liked).
It's here
https://tracinsy.ewi.tudelft.nl/pubtrac/Utilities/wiki/uri
and the simple class that I made
https://tracinsy.ewi.tudelft.nl/pubtrac/Utilities/browser/uri/uri.py
Basically I cloned an existing URI parser/validator/normalizer tool and added an immutable uri.URI class to it to fit my needs. It does equality testing based on normalized URIs but otherwise it's very limited at this point. At some point I might add some more functionality as needed.
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
- 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.
- Host/host:port and path aren't definitively separated by a slash HOT 7
- 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.