<s> """<STR_LIT>""" <EOL> from collections import namedtuple <EOL> import datetime <EOL> from django . core . exceptions import ValidationError <EOL> from django . forms import MultipleChoiceField , Field <EOL> from django . utils . formats import sanitize_separators <EOL> from osgeo import osr <EOL> import re <EOL> def _from_today ( match ) : <EOL> plusminus = match . group ( <NUM_LIT:1> ) <EOL> amt = match . group ( <NUM_LIT:2> ) <EOL> if plusminus == '<STR_LIT:->' : <EOL> return datetime . date . today ( ) - datetime . timedelta ( days = int ( amt ) ) <EOL> else : <EOL> return datetime . date . today ( ) + datetime . timedelta ( days = int ( amt ) ) <EOL> def _from_now ( match ) : <EOL> def maybeint ( i ) : <EOL> if i : <EOL> return int ( i ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> plusminus = match . group ( <NUM_LIT:1> ) <EOL> weeks = maybeint ( match . group ( <NUM_LIT:2> ) ) <EOL> days = maybeint ( match . group ( <NUM_LIT:3> ) ) <EOL> hours = maybeint ( match . group ( <NUM_LIT:4> ) ) <EOL> mins = maybeint ( match . group ( <NUM_LIT:5> ) ) <EOL> seconds = maybeint ( match . group ( <NUM_LIT:6> ) ) <EOL> milliseconds = maybeint ( match . group ( <NUM_LIT:7> ) ) <EOL> if plusminus == '<STR_LIT:->' : <EOL> return datetime . datetime . utcnow ( ) - datetime . timedelta ( <EOL> weeks = weeks , days = days , hours = hours , mins = mins , seconds = seconds , milliseconds = milliseconds ) <EOL> def parsetime ( t ) : <EOL> """<STR_LIT>""" <EOL> timeformats = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> alt_formats = { <EOL> '<STR_LIT>' : datetime . datetime . utcnow ( ) , <EOL> '<STR_LIT>' : datetime . date . today ( ) , <EOL> } <EOL> high_level = [ <EOL> ( re . compile ( '<STR_LIT>' ) , _from_today ) , <EOL> ( re . compile ( '<STR_LIT>' ) , _from_now ) <EOL> ] <EOL> if not t : <EOL> return None <EOL> ret = None <EOL> for tf in timeformats : <EOL> try : <EOL> ret = datetime . datetime . strptime ( t , tf ) <EOL> except : <EOL> pass <EOL> if not ret and t in alt_formats : <EOL> return alt_formats [ t ] <EOL> elif not ret : <EOL> for tf , l in high_level : <EOL> k = tf . match ( t ) <EOL> if k : <EOL> ret = l ( k ) <EOL> if ret : <EOL> return ret <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' + t ) <EOL> def create_spatialref ( srs , srs_format = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> spatialref = osr . SpatialReference ( ) <EOL> if srs_format : <EOL> if srs_format == '<STR_LIT>' : <EOL> spatialref . ImportFromEPSG ( srs ) <EOL> elif srs_format == '<STR_LIT>' : <EOL> spatialref . ImportFromWkt ( srs ) <EOL> elif srs_format == '<STR_LIT>' : <EOL> spatialref . ImportFromProj4 ( srs ) <EOL> else : <EOL> spatialref . ImportFromEPSG ( int ( srs . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] ) ) <EOL> return spatialref <EOL> mimetypes = namedtuple ( "<STR_LIT>" , ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) ( <EOL> json = '<STR_LIT:application/json>' , <EOL> jsonp = '<STR_LIT>' <EOL> ) <EOL> class CaseInsensitiveDict ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , key_to_list_mapping = ( ) ) : <EOL> def fix ( pair ) : <EOL> key , value = pair <EOL> return key . lower ( ) , value <EOL> super ( CaseInsensitiveDict , self ) . __init__ ( [ fix ( kv ) for kv in key_to_list_mapping ] ) <EOL> def __getitem__ ( self , key ) : <EOL> return super ( CaseInsensitiveDict , self ) . __getitem__ ( key . lower ( ) ) <EOL> def __setitem__ ( self , key , value ) : <EOL> return super ( CaseInsensitiveDict , self ) . __setitem__ ( key . lower ( ) , value ) <EOL> def get ( self , key , default = None ) : <EOL> if key not in self : <EOL> return default <EOL> else : <EOL> return self [ key ] <EOL> def getlist ( self , key ) : <EOL> if key not in self : <EOL> return [ ] <EOL> elif isinstance ( self [ key ] , list ) : <EOL> return self [ key ] <EOL> elif isinstance ( self [ key ] , tuple ) : <EOL> return list ( self [ key ] ) <EOL> else : <EOL> return [ self [ key ] ] <EOL> class MultipleValueField ( MultipleChoiceField ) : <EOL> """<STR_LIT>""" <EOL> def validate ( self , value ) : <EOL> if self . required and not value : <EOL> raise ValidationError ( self . error_messages [ '<STR_LIT>' ] ) <EOL> class BBoxField ( Field ) : <EOL> """<STR_LIT>""" <EOL> def to_python ( self , value ) : <EOL> value = super ( BBoxField , self ) . to_python ( value ) <EOL> if not value : <EOL> return - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT> , <NUM_LIT> <EOL> try : <EOL> lx , ly , ux , uy = value . split ( '<STR_LIT:U+002C>' ) <EOL> if self . localize : <EOL> lx = float ( sanitize_separators ( lx ) ) <EOL> ly = float ( sanitize_separators ( ly ) ) <EOL> ux = float ( sanitize_separators ( ux ) ) <EOL> uy = float ( sanitize_separators ( uy ) ) <EOL> if uy < ly or ux < lx : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> except ( ValueError , TypeError ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> lx = float ( sanitize_separators ( lx ) ) <EOL> ly = float ( sanitize_separators ( ly ) ) <EOL> ux = float ( sanitize_separators ( ux ) ) <EOL> uy = float ( sanitize_separators ( uy ) ) <EOL> return lx , ly , ux , uy </s>
