Skip to content

Commit

Permalink
bug fix for issue 9. important one so doing a release. big thanks to …
Browse files Browse the repository at this point in the history
…wmacmillan
  • Loading branch information
byteface committed Jul 4, 2021
1 parent 405b771 commit cf14ef3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion domonic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

__version__ = "0.3.15"
__version__ = "0.3.16"
__license__ = 'MIT'
'''
__uri__ = "https://github.com/byteface/domonic"
Expand Down
28 changes: 17 additions & 11 deletions domonic/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,7 @@ def __update__(self):
new = {}
new['protocol'] = self.url.scheme
new['hostname'] = self.url.hostname
new['href'] = self.url.geturl()
new['port'] = self.url.port
new['host'] = '' # self.url.hostname
new['pathname'] = self.url.path
Expand All @@ -1840,20 +1841,19 @@ def __update__(self):
new = {}
new['protocol'] = self.protocol
new['hostname'] = self.hostname
new['href'] = self.href
new['port'] = self.port
new['host'] = self.host
new['pathname'] = self.pathname
new['hash'] = self.hash # self.hash

# rebuild
new['search'] = self.search # self.url.query
new['_searchParams'] = self._searchParams # URLSearchParams(self.url.query)
# NOTE - rebuild happening here
self.url = urllib.parse.urlsplit(
new['protocol'] + "://" + new['host'] + new['pathname'] + new['hash'])

new['search'] = self.url.query
new['_searchParams'] = URLSearchParams(self.url.query)
new['protocol'] + "://" + new['host'] + new['pathname'] + new['hash'] + new['search'])

# reset
self.href = self.url.geturl()

except Exception: # as e:
# print('fails on props called by init as they dont exist yet')
# print(e)
Expand All @@ -1868,16 +1868,13 @@ def __init__(self, url: str = "", *args, **kwargs): # TODO - relative to
url (str): a url
"""
self.url = urllib.parse.urlsplit(url)
self.href = self.url.geturl()

self.href = url # self.url.geturl()
self.protocol = self.url.scheme
self.hostname = self.url.hostname
self.port = self.url.port
self.host = self.url.hostname
self.pathname = self.url.path
self.hash = ''

# print("HERE", self.url.query)
self.search = self.url.query
self._searchParams = URLSearchParams(self.url.query)

Expand All @@ -1886,12 +1883,14 @@ def searchParams(self):
return self._searchParams.toString()

def toString(self):
print('toString CALLED::')
return str(self.href)

# def toJson

# @property
# def href(self):
# TODO - check js vs tag. does js version remove query?. if so detect self.
# return self.href

# @href.setter
Expand Down Expand Up @@ -1977,6 +1976,13 @@ def hash(self, h: str):
# def origin(self):
'''# origin Returns the protocol, hostname and port number of a URL Location'''

def __str__(self):
print("called!!!")
return str(self.href)





class URLSearchParams:
"""[utility methods to work with the query string of a URL]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with open("README.md", "r") as f:
long_description=f.read()

version = '0.3.15'
version = '0.3.16'

setup(
name='domonic',
Expand Down
20 changes: 20 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,5 +821,25 @@ def test_domonic_render_a_tag(self):
# print('host:',atag.host)


def test_domonic_render_a_tag_query_params(self):
# from domonic import a, render
urls = [
'example.com/stuff?things=morestuff',
'https://example.com/stuff?things=morestuff',
'https://example.com/stuff',
'https://www.example.com/stuff?thing',
'https://www.example.com/?stuff'
]
for url in urls:
print( 'zz',url)
print( 'zz2',render(a(_href=url)) )
assert f'''{render(a(_href=url))}''' == f'''<a href="{url}"></a>'''

# a tag no href TODO
# print( render(a(_name="test")) )




if __name__ == '__main__':
unittest.main()

0 comments on commit cf14ef3

Please sign in to comment.