Changeset 94

Show
Ignore:
Timestamp:
07/12/06 18:17:05 (2 years ago)
Author:
robin
Message:

function to break dispatch options out of url string

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • streamservice/trunk/src-python/streamservice/clientapi.py

    r92 r94  
    1010 
    1111__all__=( 
    12         'query_parameters clientscript_parse dispatch_batch
    13         'dispatch_queryscript ' 
     12        'options_from_serviceurl query_parameters clientscript_parse
     13        'dispatch_batch dispatch_queryscript ' 
    1414        'HTTPRequestProtocol Dispatcher ' 
    1515        ).split() 
    1616 
     17def options_from_serviceurl(url,  
     18    default_serviceport=8080, 
     19    default_dispatchparamname='dispatcher'): 
     20    urlparts=list(urlparse(url)) 
     21    qp,idispatchparam=query_parameters(urlparts[-2], default_dispatchparamname) 
     22 
     23    host=urlparts[1].split(':',1) 
     24    if len(host)==2: 
     25        host,port=host[0],int(host[1]) 
     26    else: 
     27        host,port=host[0],default_serviceport 
     28    resourcepath='/'.join(urlparts[2].rsplit('/',1)[0]) 
     29    resourcebasename=urlparts[2].rsplit('/',1) 
     30    # [''], ['',''] ['','resource.json'] ['some/path','resource.json'] 
     31    if not resourcebasename[0]: 
     32        resourcebasename = ( 
     33            len(resourcebasename) == 2 and resourcebasename[1] 
     34            or '') 
     35    else: 
     36        resourcebasename=resourcebasename[1] 
     37    return dict( 
     38        scheme=urlparts[0], host=host, port=port, 
     39        path=urlparts[2], 
     40        dispatch_param=qp[idispatchparam][0], 
     41        resourcepath=resourcepath, 
     42        resourcebasename=resourcebasename, 
     43        idispatch_param=idispatchparam) 
     44  
    1745def query_parameters(queryparamstring, dispatchparamname='dispatcher'): 
    1846    """Return the queryparameters and the index of the dispatch parameter.