Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions adafruit_httpserver/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def __hash__(self) -> int:
return hash(self.method) ^ hash(self.path)

def __eq__(self, other: "_HTTPRoute") -> bool:
if self.path[-1] == '*':
prepath = self.path[0:len(self.path)-1]
return self.method == other.method and other.path.startswith(prepath)
Comment on lines +25 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler. You could also use self.path.rstrip("*") instead of self.path[0:-1]`

Suggested change
if self.path[-1] == '*':
prepath = self.path[0:len(self.path)-1]
return self.method == other.method and other.path.startswith(prepath)
if self.path.endswidth("*"):
return self.method == other.method and other.path.startswith(self.path[0:-1])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwriting eq method this way, it can lead to situations where A == B but B != A.

I have been thinking for a while about wildcards in URLs, already working on a more functional approach to this, that will also allow parsing those values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overwriting eq method this way, it can lead to situations where A == B but B != A.

i agree with @michalpokusa's caution about this -- I wasn't sure whether it was something standard in server routing.

return self.method == other.method and self.path == other.path

def __repr__(self) -> str:
Expand Down