<s> from decimal import Decimal <EOL> from . base import Object , Array , String , Field <EOL> from . import constants <EOL> from . import request <EOL> class Impression ( Object ) : <EOL> impid = Field ( String , required = True ) <EOL> wseat = Field ( Array ( String ) ) <EOL> h = Field ( int ) <EOL> w = Field ( int ) <EOL> pos = Field ( constants . AdPosition ) <EOL> instl = Field ( int ) <EOL> btype = Field ( Array ( constants . BannerType ) ) <EOL> battr = Field ( Array ( constants . CreativeAttribute ) ) <EOL> class Device ( Object ) : <EOL> did = Field ( String ) <EOL> dpid = Field ( String ) <EOL> ip = Field ( String ) <EOL> country = Field ( String ) <EOL> carrier = Field ( String ) <EOL> ua = Field ( String ) <EOL> make = Field ( String ) <EOL> model = Field ( String ) <EOL> os = Field ( String ) <EOL> osv = Field ( String ) <EOL> js = Field ( int ) <EOL> loc = Field ( String ) <EOL> class User ( Object ) : <EOL> uid = Field ( String ) <EOL> yob = Field ( int ) <EOL> gender = Field ( String ) <EOL> zip = Field ( String ) <EOL> country = Field ( String ) <EOL> keywords = Field ( String ) <EOL> class Site ( Object ) : <EOL> sid = Field ( String ) <EOL> name = Field ( String ) <EOL> domain = Field ( String ) <EOL> pid = Field ( String ) <EOL> pub = Field ( String ) <EOL> pdomain = Field ( String ) <EOL> cat = Field ( Array ( String ) ) <EOL> keywords = Field ( String ) <EOL> page = Field ( String ) <EOL> ref = Field ( String ) <EOL> search = Field ( String ) <EOL> class App ( Object ) : <EOL> aid = Field ( String ) <EOL> name = Field ( String ) <EOL> domain = Field ( String ) <EOL> pid = Field ( String ) <EOL> pub = Field ( String ) <EOL> pdomain = Field ( String ) <EOL> cat = Field ( Array ( String ) ) <EOL> keywords = Field ( String ) <EOL> ver = Field ( String ) <EOL> bundle = Field ( String ) <EOL> paid = Field ( int ) <EOL> class Restrictions ( Object ) : <EOL> bcat = Field ( Array ( String ) ) <EOL> badv = Field ( Array ( String ) ) <EOL> class BidRequest ( Object ) : <EOL> id = Field ( String , required = True ) <EOL> at = Field ( constants . AuctionType , default = constants . AuctionType . SECOND_PRICE ) <EOL> tmax = Field ( int ) <EOL> imp = Field ( Array ( Impression ) , required = True ) <EOL> site = Field ( Site , default = Site ( ) ) <EOL> app = Field ( App , default = App ( ) ) <EOL> device = Field ( Device , default = Device ( ) ) <EOL> user = Field ( User , default = User ( ) ) <EOL> restrictions = Field ( Restrictions , default = Restrictions ( ) ) <EOL> @ staticmethod <EOL> def minimal ( id , imp_id ) : <EOL> return BidRequest ( id = id , imp = [ Impression ( impid = imp_id ) ] ) <EOL> class OpenRTB20Adapter ( object ) : <EOL> def __init__ ( self , brq ) : <EOL> self . mobile_brq = brq <EOL> params = { <EOL> '<STR_LIT:id>' : brq . id , <EOL> '<STR_LIT>' : [ <EOL> request . Impression ( <EOL> id = imp . impid , <EOL> banner = request . Banner ( <EOL> w = imp . w , <EOL> h = imp . h , <EOL> pos = imp . pos , <EOL> battr = imp . battr , <EOL> btype = imp . btype , <EOL> ) , <EOL> bidfloor = Decimal ( <NUM_LIT:0> ) , <EOL> ) for imp in brq . imp <EOL> ] , <EOL> '<STR_LIT>' : brq . at , <EOL> '<STR_LIT>' : brq . tmax <EOL> } <EOL> if brq . site : <EOL> params [ '<STR_LIT>' ] = request . Site ( <EOL> id = brq . site . sid , <EOL> name = brq . site . name , <EOL> domain = brq . site . domain , <EOL> publisher = request . Publisher ( <EOL> id = brq . site . pid , <EOL> name = brq . site . pub , <EOL> domain = brq . site . pdomain <EOL> ) , <EOL> cat = brq . site . cat , <EOL> keywords = brq . site . keywords , <EOL> page = brq . site . page , <EOL> ref = brq . site . ref , <EOL> search = brq . site . search , <EOL> ) <EOL> if brq . app : <EOL> params [ '<STR_LIT>' ] = request . App ( <EOL> id = brq . app . aid , <EOL> name = brq . app . name , <EOL> domain = brq . app . domain , <EOL> publisher = request . Publisher ( <EOL> id = brq . app . pid , <EOL> name = brq . app . pub , <EOL> pdomain = brq . app . pdomain , <EOL> ) , <EOL> cat = brq . app . cat , <EOL> keywords = brq . app . keywords , <EOL> ver = brq . app . ver , <EOL> bundle = brq . app . bundle , <EOL> paid = brq . app . paid , <EOL> ) <EOL> if brq . device : <EOL> lat = lon = None <EOL> if brq . device . loc : <EOL> lat , lon = brq . device . loc . split ( '<STR_LIT:U+002C>' ) <EOL> lat , lon = float ( lat ) , float ( lon ) <EOL> params [ '<STR_LIT>' ] = request . Device ( <EOL> didsha1 = brq . device . did , <EOL> dpidsha1 = brq . device . dpid , <EOL> ip = brq . device . ip , <EOL> geo = request . Geo ( <EOL> lat = lat , <EOL> lon = lon , <EOL> country = brq . device . country , <EOL> ) , <EOL> carrier = brq . device . carrier , <EOL> ua = brq . device . ua , <EOL> make = brq . device . make , <EOL> model = brq . device . model , <EOL> os = brq . device . os , <EOL> osv = brq . device . osv , <EOL> js = brq . device . js , <EOL> connectiontype = constants . ConnectionType . CELLULAR_UNKNOWN_G , <EOL> devicetype = constants . DeviceType . MOBILE <EOL> ) <EOL> if brq . user : <EOL> params [ '<STR_LIT:user>' ] = request . User ( <EOL> id = brq . user . uid , <EOL> yob = brq . user . yob , <EOL> gender = brq . user . gender , <EOL> keywords = brq . user . keywords , <EOL> geo = request . Geo ( <EOL> country = brq . user . country , <EOL> zip = brq . user . zip <EOL> ) <EOL> ) <EOL> if brq . restrictions : <EOL> params [ '<STR_LIT>' ] = brq . restrictions . badv <EOL> params [ '<STR_LIT>' ] = brq . restrictions . bcat <EOL> self . brq = request . BidRequest ( ** params ) <EOL> def __getattr__ ( self , k ) : <EOL> return getattr ( self . brq , k ) <EOL> @ staticmethod <EOL> def deserialize ( data ) : <EOL> brq = BidRequest . deserialize ( data ) <EOL> return OpenRTB20Adapter ( brq ) </s>
