mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 12:33:02 +02:00
- New helper class for container testing - New helper class to urllib, Furl Due to extremely weak Python-fu in the undersigned, this patch changes the __init__.py file to add new helper classes for container tests. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
25 lines
754 B
Python
25 lines
754 B
Python
"""Fugly URL fetcher"""
|
|
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
class Furl:
|
|
"""Furl wraps urllib in a way similar to curl"""
|
|
def __init__(self, url):
|
|
"""Create new URL checker"""
|
|
self.url = urllib.parse.quote(url, safe='/:')
|
|
|
|
def check(self, needle):
|
|
"""Connect to web server URL, fetch body and check for needle"""
|
|
try:
|
|
with urllib.request.urlopen(self.url) as response:
|
|
text = response.read().decode('utf-8')
|
|
#print(text)
|
|
return needle in text
|
|
except urllib.error.URLError as _:
|
|
return False
|
|
|
|
def nscheck(self, netns, needle):
|
|
""""Call check() from netns"""
|
|
return netns.call(lambda: self.check(needle))
|