Skip to content

Commit

Permalink
changed to use urllib to construct url
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollman committed Jan 3, 2018
1 parent 1d26028 commit 26751f0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions test/sources/url_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@
from argschema import ArgSchemaParser
from test_classes import MySchema
import requests
try:
from urllib.parse import urlunparse
except:
from urllib import urlunparse

class UrlSourceConfig(DefaultSchema):
input_host = Str(required=True, description="host of url")
input_port = Int(required=False, default=80, description="port of url")
input_port = Int(required=False, default=None, description="port of url")
input_url = Str(required=True, description="location on host of input")
input_protocol = Str(required=False, default='http', description="url protocol to use")

class UrlSource(ArgSource):
ConfigSchema = UrlSourceConfig

def get_dict(self):
url = "{}://{}:{}/{}".format(self.input_protocol,
self.input_host,
self.input_port,
self.input_url)
if self.input_port is None:
netloc = self.input_host
else:
netloc = "{}:{}".format(self.input_host,self.input_port)
url = urlunparse((self.input_protocol,netloc,self.input_url,None,None,None))
response = requests.get(url)
return response.json()

Expand Down

0 comments on commit 26751f0

Please sign in to comment.