<s> import re <EOL> class Url ( object ) : <EOL> unsafe_or_hash = r'<STR_LIT>' <EOL> debug = '<STR_LIT>' <EOL> meta = '<STR_LIT>' <EOL> trim = '<STR_LIT>' <EOL> crop = '<STR_LIT>' <EOL> fit_in = '<STR_LIT>' <EOL> dimensions = '<STR_LIT>' <EOL> halign = r'<STR_LIT>' <EOL> valign = r'<STR_LIT>' <EOL> smart = r'<STR_LIT>' <EOL> filters = r'<STR_LIT>' <EOL> image = r'<STR_LIT>' <EOL> compiled_regex = None <EOL> @ classmethod <EOL> def regex ( cls , has_unsafe_or_hash = True ) : <EOL> reg = [ '<STR_LIT>' ] <EOL> if has_unsafe_or_hash : <EOL> reg . append ( cls . unsafe_or_hash ) <EOL> reg . append ( cls . debug ) <EOL> reg . append ( cls . meta ) <EOL> reg . append ( cls . trim ) <EOL> reg . append ( cls . crop ) <EOL> reg . append ( cls . fit_in ) <EOL> reg . append ( cls . dimensions ) <EOL> reg . append ( cls . halign ) <EOL> reg . append ( cls . valign ) <EOL> reg . append ( cls . smart ) <EOL> reg . append ( cls . filters ) <EOL> reg . append ( cls . image ) <EOL> return '<STR_LIT>' . join ( reg ) <EOL> @ classmethod <EOL> def parse_decrypted ( cls , url ) : <EOL> if cls . compiled_regex : <EOL> reg = cls . compiled_regex <EOL> else : <EOL> reg = cls . compiled_regex = re . compile ( cls . regex ( has_unsafe_or_hash = False ) ) <EOL> result = reg . match ( url ) <EOL> if not result : <EOL> return None <EOL> result = result . groupdict ( ) <EOL> def int_or_0 ( value ) : <EOL> return <NUM_LIT:0> if value is None else int ( value ) <EOL> adaptive = ( result . get ( '<STR_LIT>' , '<STR_LIT>' ) or '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) <EOL> full = ( result . get ( '<STR_LIT>' , '<STR_LIT>' ) or '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) <EOL> values = { <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] == '<STR_LIT>' , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] == '<STR_LIT>' , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:left>' : int_or_0 ( result [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : int_or_0 ( result [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT:right>' : int_or_0 ( result [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : int_or_0 ( result [ '<STR_LIT>' ] ) <EOL> } , <EOL> '<STR_LIT>' : adaptive , <EOL> '<STR_LIT>' : full , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] == '<STR_LIT>' , <EOL> '<STR_LIT:width>' : result [ '<STR_LIT:width>' ] == '<STR_LIT>' and '<STR_LIT>' or int_or_0 ( result [ '<STR_LIT:width>' ] ) , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] == '<STR_LIT>' and '<STR_LIT>' or int_or_0 ( result [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] == '<STR_LIT:->' , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] == '<STR_LIT:->' , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] or '<STR_LIT>' , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] or '<STR_LIT>' , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] == '<STR_LIT>' , <EOL> '<STR_LIT>' : result [ '<STR_LIT>' ] or '<STR_LIT>' , <EOL> '<STR_LIT:image>' : '<STR_LIT:image>' in result and result [ '<STR_LIT:image>' ] or None <EOL> } <EOL> return values <EOL> @ classmethod <EOL> def generate_options ( cls , <EOL> debug = False , <EOL> width = <NUM_LIT:0> , <EOL> height = <NUM_LIT:0> , <EOL> smart = False , <EOL> meta = False , <EOL> trim = None , <EOL> adaptive = False , <EOL> full = False , <EOL> fit_in = False , <EOL> horizontal_flip = False , <EOL> vertical_flip = False , <EOL> halign = '<STR_LIT>' , <EOL> valign = '<STR_LIT>' , <EOL> crop_left = None , <EOL> crop_top = None , <EOL> crop_right = None , <EOL> crop_bottom = None , <EOL> filters = None ) : <EOL> url = [ ] <EOL> if debug : <EOL> url . append ( '<STR_LIT>' ) <EOL> if meta : <EOL> url . append ( '<STR_LIT>' ) <EOL> if trim : <EOL> if isinstance ( trim , bool ) : <EOL> url . append ( '<STR_LIT>' ) <EOL> else : <EOL> url . append ( '<STR_LIT>' % trim ) <EOL> crop = crop_left or crop_top or crop_right or crop_bottom <EOL> if crop : <EOL> url . append ( '<STR_LIT>' % ( <EOL> crop_left , <EOL> crop_top , <EOL> crop_right , <EOL> crop_bottom <EOL> ) ) <EOL> if fit_in : <EOL> fit_ops = [ ] <EOL> if adaptive : <EOL> fit_ops . append ( '<STR_LIT>' ) <EOL> if full : <EOL> fit_ops . append ( '<STR_LIT>' ) <EOL> fit_ops . append ( '<STR_LIT>' ) <EOL> url . append ( '<STR_LIT:->' . join ( fit_ops ) ) <EOL> if horizontal_flip : <EOL> width = '<STR_LIT>' % width <EOL> if vertical_flip : <EOL> height = '<STR_LIT>' % height <EOL> if width or height : <EOL> url . append ( '<STR_LIT>' % ( width , height ) ) <EOL> if halign != '<STR_LIT>' : <EOL> url . append ( halign ) <EOL> if valign != '<STR_LIT>' : <EOL> url . append ( valign ) <EOL> if smart : <EOL> url . append ( '<STR_LIT>' ) <EOL> if filters : <EOL> url . append ( '<STR_LIT>' % filters ) <EOL> return '<STR_LIT:/>' . join ( url ) </s>
