#NEWLINE# def parse_url( url ) : #NEWLINE# #INDENT# "Parses the supplied Redis URL and returns a dict with the parsed/split data.\n\n    For ambiguous URLs like redis://localhost and redis://my_socket_file this function will prioritize network URLs over\n    socket URLs. redis://my_socket_file will be interpreted as a network URL, with the Redis server having a hostname of\n    'my_socket_file'. Use the file:// or redis+socket:// (Celery compatibility) URL scheme to force socket URL\n    interpretations over network URLs.\n\n    Positional arguments:\n    url -- URL to redis server. Examples are in this file's Redis class docstring under REDIS_URL.\n\n    Returns:\n    Dictionary with parsed data, compatible with StrictRedis.__init__() keyword arguments.\n\n    Raises:\n    ValueError -- if the supplies URL was malformed or invalid.\n    " #NEWLINE# try : #NEWLINE# #INDENT# split = urlsplit ( url . rstrip ( '/' ) ) #NEWLINE# #UNINDENT# except ( AttributeError , TypeError ) as e : #NEWLINE# #INDENT# raise ValueError ( 'Malformed URL specified: {0}' . format ( e ) ) #NEWLINE# #UNINDENT# if ( split . scheme not in [ 'redis+socket' , 'redis' , 'file' ] ) : #NEWLINE# #INDENT# raise ValueError ( 'Malformed URL specified.' ) #NEWLINE# #UNINDENT# scheme = split . scheme #NEWLINE# netloc = split . netloc #NEWLINE# hostname = split . hostname #NEWLINE# path = split . path #NEWLINE# password = split . password #NEWLINE# try : #NEWLINE# #INDENT# port = split . port #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# port = None #NEWLINE# #UNINDENT# if ( ( os . name == 'nt' ) and ( not path ) and ( '\\' in netloc ) ) : #NEWLINE# #INDENT# if ( '@' in netloc ) : #NEWLINE# #INDENT# position = ( netloc . find ( '@' ) + 1 ) #NEWLINE# path = netloc [ position : ] #NEWLINE# netloc = netloc [ : position ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# path = netloc #NEWLINE# netloc = '' #NEWLINE# #UNINDENT# #UNINDENT# if ( ( scheme == 'redis' ) and netloc and ( not netloc . endswith ( '.' ) ) and ( not netloc . endswith ( '@' ) ) ) : #NEWLINE# #INDENT# result = dict ( host = hostname ) #NEWLINE# if password : #NEWLINE# #INDENT# result [ 'password' ] = password #NEWLINE# #UNINDENT# if port : #NEWLINE# #INDENT# result [ 'port' ] = port #NEWLINE# #UNINDENT# if path : #NEWLINE# #INDENT# if ( not path [ 1 : ] . isdigit ( ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Network URL path has non-digit characters: {0}' . format ( path [ 1 : ] ) ) #NEWLINE# #UNINDENT# result [ 'db' ] = int ( path [ 1 : ] ) #NEWLINE# #UNINDENT# return result #NEWLINE# #UNINDENT# if port : #NEWLINE# #INDENT# raise ValueError ( 'Socket URL looks like non-socket URL.' ) #NEWLINE# #UNINDENT# if ( not password ) : #NEWLINE# #INDENT# socket_path = '{0}{1}' . format ( netloc , path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if netloc . endswith ( '.' ) : #NEWLINE# #INDENT# socket_path = '{0}{1}' . format ( netloc . split ( '@' ) [ 1 ] , path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not split ) : #NEWLINE# #INDENT# socket_path = netloc . split ( '@' ) [ 1 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# socket_path = path #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# parent_dir = os . path . split ( socket_path ) [ 0 ] #NEWLINE# if ( parent_dir and ( not os . path . isdir ( parent_dir ) ) ) : #NEWLINE# #INDENT# raise ValueError ( "Unix socket path's parent not a dir: {0}" . format ( parent_dir ) ) #NEWLINE# #UNINDENT# result = dict ( unix_socket_path = socket_path ) #NEWLINE# if password : #NEWLINE# #INDENT# result [ 'password' ] = password #NEWLINE# #UNINDENT# return result