Ignore:
Timestamp:
20/06/07 15:12:26 (12 years ago)
Author:
domlowe
Message:

Basic ISO8601 time validator added

Location:
TI05-delivery/ows_framework/trunk/ows_server
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/trunk/ows_server/development_dom.ini

    r2605 r2625  
    99smtp_server = localhost 
    1010error_email_from = paste@localhost 
     11configfile = ows_server/config/ndgDiscovery.config 
    1112 
    1213[server:main] 
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_wcs.py

    r2607 r2625  
    102102    @parameter('Identifier', required=True) 
    103103    @parameter('BoundingBox', required=True, validator=V.bbox_2d) 
    104     @parameter('TimeSequence',required=True)  #TODO, need validator to handle iso8601 time strings 
    105     @parameter('Format', possibleValues=['image/netcdf'], required=True) 
     104    @parameter('TimeSequence',required=True, validator=V.iso8601_time)  #TODO, need validator to handle iso8601 time strings 
     105    @parameter('Format', possibleValues=['application/netcdf'], required=True) 
    106106    @parameter('Store', possibleValues=['true', 'True', 'TRUE']) 
    107107    #TODO some more parameter to add here 
     
    116116     
    117117            #set bounding box TODO 
    118             sel = dict(latitude=(boundingbox[1], boundingbox[3]), longitude=(boundingbox[0], boundingbox[2])) 
     118            sel = dict(latitude=(boundingbox[1], boundingbox[3]), longitude=(boundingbox[0], boundingbox[2]))            
    119119            sel['time']=timesequence #needs validating 
    120120             
     
    127127            #Depending on if the 'store' parameter is set, either return the netcdf file or a link to it. 
    128128            if store is not None:  
    129                 c.hyperlink = 'http://'+request.environ['HTTP_HOST']+'/'+os.path.basename(request.environ['paste.config']['app_conf']['publish_dir'])+'/'+filename 
     129                c.hyperlink = 'http://'+request.environ['HTTP_HOST']+'/'+os.path.basename(request.environ['paste.config']['app_conf']['publish_dir'])+'/'+os.path.basename(filename) 
    130130                c.wcs_request=request.environ['HTTP_REFERER'] 
    131131                return render_response('wcs_asynchronous') 
    132             else: 
     132            else:                 
    133133                netcdfFile=open(filename, 'r') 
    134134                return Response(content=netcdfFile, mimetype='image/netcdf')     
  • TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/validators.py

    r2594 r2625  
    3939 
    4040    return bbox_t 
     41 
     42 
     43def iso8601_time(timestring): 
     44    """ 
     45        Checks if timestring is a valid iso8601 time string or valid iso8601 time interval  
     46        This is not a complete implementation of the full iso8601 spec (although could be extended to be so). 
     47         
     48    """ 
     49    import xml.utils.iso8601 as isoT 
     50    #single time value e.g. 2002-03-01T13:00:00Z 
     51     
     52    #start and end times: e.g 2002-03-01T13:00:00Z/2003-05-11T15:30:00Z 
     53     
     54    def _checkTime(timestring): 
     55        try:  
     56            isoT.parse(timestring) 
     57            return timestring[:-1]  #return without the Z 
     58        except ValueError: 
     59            timestring=timestring + 'Z'   #maybe the Z has just been missed off 
     60            try: 
     61                isoT.parse(timestring) 
     62                return timestring[:-1]#return without the Z 
     63            except ValueError:                
     64                raise InvalidParameterValue("Incorrect TimeSequence specification %s" % timestring, 'timeSequence') 
     65             
     66    if timestring.find(',') == -1: 
     67        timelist=timestring.split('/') 
     68    else: 
     69        timelist=timestring.split(',') 
     70 
     71    if len(timelist) == 1:          
     72        tOK=_checkTime(timelist[0]) 
     73        return tOK 
     74     
     75    else: 
     76        newtimelist=[] 
     77        for t in timelist: 
     78            newtimelist.append(_checkTime(t)) 
     79        return tuple(newtimelist) 
    4180 
    4281 
     
    82121 
    83122    return f 
    84  
Note: See TracChangeset for help on using the changeset viewer.