Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug #14 - furl.remove() removed port, username, and password ev…

…en if they weren't specifed to be removed. Added equality operator to furl.
  • Loading branch information...
commit b1d3f7e0a6d44ca01196625352877391de985f3e 1 parent d9b901f
Arthur Grunseid authored
Showing with 30 additions and 13 deletions.
  1. +10 −8 furl/furl.py
  2. +20 −5 tests/test_furl.py
View
18 furl/furl.py
@@ -927,10 +927,10 @@ def set(self, args=_absent, path=_absent, fragment=_absent, scheme=_absent,
return self
def remove(self, args=_absent, path=_absent, fragment=_absent, query=_absent,
- query_params=_absent, port=_absent, fragment_path=_absent,
- fragment_args=_absent, username=_absent, password=_absent):
+ query_params=_absent, port=False, fragment_path=_absent,
+ fragment_args=_absent, username=False, password=False):
"""
- Remove components of url and return this furl instance, <self>.
+ Remove components of this furl's URL and return this furl instance, <self>.
Parameters:
args: Shortcut for query_params.
@@ -952,13 +952,12 @@ def remove(self, args=_absent, path=_absent, fragment=_absent, query=_absent,
password: If True, remove the password, if it exists.
Returns: <self>.
"""
- if username:
+ if port is True:
+ self.port = None
+ if username is True:
self.username = ''
- if password:
+ if password is True:
self.password = ''
- if port:
- self.port = None
-
if path is not _absent:
self.path.remove(path)
if args is not _absent:
@@ -982,6 +981,9 @@ def join(self, url):
def copy(self):
return self.__class__(self)
+ def __eq__(self, other):
+ return self.url == other.url
+
def __setattr__(self, attr, value):
if (not PathCompositionInterface.__setattr__(self, attr, value) and
not QueryCompositionInterface.__setattr__(self, attr, value) and
View
25 tests/test_furl.py
@@ -1224,11 +1224,18 @@ def test_set(self):
assert str(f.fragment) == '!a=a'
def test_remove(self):
- url = 'http://host:69/a/big/path/?a=a&b=b&s=s+s#a frag?with=args&a=a'
-
+ url = 'http://u:p@host:69/a/big/path/?a=a&b=b&s=s+s#a frag?with=args&a=a'
f = furl.furl(url)
+
+ # Remove without parameters removes nothing.
+ assert f.url == f.remove().url
+
+ # username, password, and port must be True.
+ assert f == f.copy().remove(username='nope', password='nope', port='nope')
+
+ # Basics.
assert f is f.remove(fragment=True, args=['a', 'b'], path='path/',
- port=True)
+ username=True, password=True, port=True)
assert f.url == 'http://host/a/big/?s=s+s'
# No errors are thrown when removing url components that don't exist.
@@ -1246,9 +1253,10 @@ def test_remove(self):
assert f is f.remove(fragment_path='a frag', fragment_args=['a'],
query_params=['a','b'], path=['big', 'path', ''],
port=True)
- assert f.url == 'http://host/a/?s=s+s#with=args'
+ assert f.url == 'http://u:p@host/a/?s=s+s#with=args'
- assert f is f.remove(path=True, query=True, fragment=True)
+ assert f is f.remove(path=True, query=True, fragment=True, username=True,
+ password=True)
assert f.url == 'http://host'
def test_join(self):
@@ -1291,6 +1299,13 @@ def test_join(self):
for join, result in run_tests:
assert f is f.join(join) and f.url == result
+ def test_equality(self):
+ assert furl.furl() is not furl.furl() and furl.furl() == furl.furl()
+
+ url = 'https://www.yahoo.co.uk/one/two/three?a=a&b=b&m=m%26m#fragment'
+ assert furl.furl(url) == furl.furl(url)
+ assert furl.furl(url).remove(path=True) != furl.furl(url)
+
def test_urlsplit(self):
# Without any delimeters like '://' or '/', the input should be treated as a
# path.
Please sign in to comment.
Something went wrong with that request. Please try again.