Commit af2f5c36 authored by Łukasz Nowak's avatar Łukasz Nowak

Avoid playing with url.

HTTPConnection accept port as none, there is no need to play with it.
parent df7a4fa7
...@@ -36,10 +36,6 @@ class NetworkcacheClient(object): ...@@ -36,10 +36,6 @@ class NetworkcacheClient(object):
# ShaCache Properties # ShaCache Properties
if shacache is not None: if shacache is not None:
shacache_urlparse = urlparse(shacache) shacache_urlparse = urlparse(shacache)
self.shacache_host = shacache_urlparse.hostname
if shacache_urlparse.port is not None:
self.shacache_host += ':%s' % shacache_urlparse.port
self.shacache_header_dict = {'Content-Type': 'application/json'} self.shacache_header_dict = {'Content-Type': 'application/json'}
shacache_user = shacache_urlparse.username shacache_user = shacache_urlparse.username
shacache_passwd = shacache_urlparse.password shacache_passwd = shacache_urlparse.password
...@@ -53,8 +49,7 @@ class NetworkcacheClient(object): ...@@ -53,8 +49,7 @@ class NetworkcacheClient(object):
self.shacache_path = shacache_urlparse.path self.shacache_path = shacache_urlparse.path
self.shacache_host = shacache_urlparse.hostname self.shacache_host = shacache_urlparse.hostname
if shacache_urlparse.port is not None: self.shacache_port = shacache_urlparse.port
self.shacache_host += ':%s' % shacache_urlparse.port
self.shacache_url = shacache self.shacache_url = shacache
# ShaDir Properties # ShaDir Properties
...@@ -73,8 +68,7 @@ class NetworkcacheClient(object): ...@@ -73,8 +68,7 @@ class NetworkcacheClient(object):
self.shadir_path = shadir_urlparse.path self.shadir_path = shadir_urlparse.path
self.shadir_host = shadir_urlparse.hostname self.shadir_host = shadir_urlparse.hostname
if shadir_urlparse.port is not None: self.shadir_port = shadir_urlparse.port
self.shadir_host += ':%s' % shadir_urlparse.port
def upload(self, file_descriptor, directory_key=None, **kw): def upload(self, file_descriptor, directory_key=None, **kw):
''' Upload the file to the server. ''' Upload the file to the server.
...@@ -89,7 +83,8 @@ class NetworkcacheClient(object): ...@@ -89,7 +83,8 @@ class NetworkcacheClient(object):
sha512sum = hashlib.sha512(file_content).hexdigest() sha512sum = hashlib.sha512(file_content).hexdigest()
path = os.path.join(self.shacache_path, sha512sum) path = os.path.join(self.shacache_path, sha512sum)
shacache_connection = httplib.HTTPConnection(self.shacache_host) shacache_connection = httplib.HTTPConnection(self.shacache_host,
self.shacache_port)
try: try:
shacache_connection.request('POST', path, file_content, shacache_connection.request('POST', path, file_content,
self.shacache_header_dict) self.shacache_header_dict)
...@@ -119,7 +114,8 @@ class NetworkcacheClient(object): ...@@ -119,7 +114,8 @@ class NetworkcacheClient(object):
signature = '' signature = ''
data = [kw, signature] data = [kw, signature]
shadir_connection = httplib.HTTPConnection(self.shadir_host) shadir_connection = httplib.HTTPConnection(self.shadir_host,
self.shadir_port)
try: try:
shadir_connection.request('POST', path, json.dumps(data), shadir_connection.request('POST', path, json.dumps(data),
self.shadir_header_dict) self.shadir_header_dict)
...@@ -157,7 +153,8 @@ class NetworkcacheClient(object): ...@@ -157,7 +153,8 @@ class NetworkcacheClient(object):
if directory_key is not None: if directory_key is not None:
path_info = os.path.join(self.shadir_path, directory_key) path_info = os.path.join(self.shadir_path, directory_key)
shadir_connection = httplib.HTTPConnection(self.shadir_host) shadir_connection = httplib.HTTPConnection(self.shadir_host,
self.shadir_port)
try: try:
shadir_connection.request('GET', path_info, headers=self.shadir_header_dict) shadir_connection.request('GET', path_info, headers=self.shadir_header_dict)
result = shadir_connection.getresponse() result = shadir_connection.getresponse()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment