def xml(self, options={}): track = True if options.get("track", True) else options.get("track") response = XMLBuilder('VAST', version=self.version) if len(self.ads) == 0 and self.VASTErrorURI: response.Error(self.cdata(self.VASTErrorURI)) return response for ad in self.ads: adOptions = {"id": ad.id} if ad.sequence: adOptions["sequence"] = str(ad.sequence) with response.Ad(**adOptions): if ad.structure.lower() == 'wrapper': with response.Wrapper: response.AdSystem( ad.AdSystem["name"], **{"version": ad.AdSystem["version"]}) response.VASTAdTagURI(self.cdata(ad.VASTAdTagURI)) if ad.Error: response.Error(self.cdata(ad.Error)) for impression in ad.impressions: if track: response.Impression( self.cdata(impression["url"])) self.add_creatives(response, ad, track) else: with response.InLine: response.AdSystem( ad.AdSystem["name"], **{"version": ad.AdSystem["version"]}) response.AdTitle(self.cdata(ad.AdTitle)) response.Description(self.cdata(ad.Description or '')) with response.Survey: for survey in ad.surveys: attributes = {} if survey.type: attributes["type"] = survey.type response.Survey(self.cdata(survey.url), **attributes) if ad.Error: response.Error(self.cdata(ad.Error)) for impression in ad.impressions: if track: response.Impression( self.cdata(impression["url"])) self.add_creatives(response, ad, track) if ad.Extensions: for extension in ad.Extensions: response.Extension(extension) return response