Commit 1ddddac3 authored by Łukasz Nowak's avatar Łukasz Nowak

Simplify parsing.

parent af2f5c36
......@@ -31,44 +31,33 @@ class NetworkcacheClient(object):
- SHACACHE
'''
def parseUrl(self, url):
return_dict = {}
parsed_url = urlparse(url)
return_dict['header_dict'] = {'Content-Type': 'application/json'}
user = parsed_url.username
passwd = parsed_url.password
if user is not None:
authentication_string = '%s:%s' % (user, passwd)
base64string = base64.encodestring(authentication_string).strip()
return_dict['header_dict']['Authorization'] = 'Basic %s' %\
base64string
return_dict['path'] = parsed_url.path
return_dict['host'] = parsed_url.hostname
return_dict['port'] = parsed_url.port
return return_dict
def __init__(self, shacache, shadir):
''' Set the initial values. '''
# ShaCache Properties
if shacache is not None:
shacache_urlparse = urlparse(shacache)
self.shacache_header_dict = {'Content-Type': 'application/json'}
shacache_user = shacache_urlparse.username
shacache_passwd = shacache_urlparse.password
if shacache_user is not None:
authentication_string = '%s:%s' % (shacache_user, shacache_passwd)
base64string = base64.encodestring(authentication_string).strip()
self.shacache_header_dict['Authorization'] = 'Basic %s' % base64string
self.shacache_path = '/'
if shacache_urlparse.path not in ('', '/'):
self.shacache_path = shacache_urlparse.path
self.shacache_host = shacache_urlparse.hostname
self.shacache_port = shacache_urlparse.port
for k, v in self.parseUrl(shacache).iteritems():
setattr(self, 'shacache_%s' % k, v)
self.shacache_url = shacache
# ShaDir Properties
if shadir is not None:
shadir_urlparse = urlparse(shadir)
self.shadir_header_dict = {'Content-Type': 'application/json'}
shadir_user = shadir_urlparse.username
shadir_passwd = shadir_urlparse.password
if shadir_user is not None:
authentication_string = '%s:%s' % (shadir_user, shadir_passwd)
base64string = base64.encodestring(authentication_string).strip()
self.shadir_header_dict['Authorization'] = 'Basic %s' % base64string
self.shadir_path = '/'
if shadir_urlparse.path not in ('', '/'):
self.shadir_path = shadir_urlparse.path
self.shadir_host = shadir_urlparse.hostname
self.shadir_port = shadir_urlparse.port
for k, v in self.parseUrl(shadir).iteritems():
setattr(self, 'shadir_%s' % k, v)
def upload(self, file_descriptor, directory_key=None, **kw):
''' Upload the file to the server.
......
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