<s> from pydenticon import Generator <EOL> from twisted . web . resource import Resource <EOL> FOREGROUND = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> BACKGROUND = "<STR_LIT>" <EOL> SIZE = <NUM_LIT:5> <EOL> class IdenticonResource ( Resource ) : <EOL> isLeaf = True <EOL> def __init__ ( self ) : <EOL> Resource . __init__ ( self ) <EOL> self . generator = Generator ( <EOL> SIZE , SIZE , foreground = FOREGROUND , background = BACKGROUND , <EOL> ) <EOL> def generate_identicon ( self , name , width , height ) : <EOL> v_padding = width % SIZE <EOL> h_padding = height % SIZE <EOL> top_padding = v_padding // <NUM_LIT:2> <EOL> left_padding = h_padding // <NUM_LIT:2> <EOL> bottom_padding = v_padding - top_padding <EOL> right_padding = h_padding - left_padding <EOL> width -= v_padding <EOL> height -= h_padding <EOL> padding = ( top_padding , bottom_padding , left_padding , right_padding ) <EOL> identicon = self . generator . generate ( <EOL> name , width , height , padding = padding <EOL> ) <EOL> return identicon <EOL> def render_GET ( self , request ) : <EOL> name = "<STR_LIT:/>" . join ( request . postpath ) <EOL> width = int ( request . args . get ( "<STR_LIT:width>" , [ <NUM_LIT> ] ) [ <NUM_LIT:0> ] ) <EOL> height = int ( request . args . get ( "<STR_LIT>" , [ <NUM_LIT> ] ) [ <NUM_LIT:0> ] ) <EOL> identicon_bytes = self . generate_identicon ( name , width , height ) <EOL> request . setHeader ( b"<STR_LIT:Content-Type>" , b"<STR_LIT>" ) <EOL> request . setHeader ( <EOL> b"<STR_LIT>" , b"<STR_LIT>" <EOL> ) <EOL> return identicon_bytes </s>
