Esempio n. 1
0
def main(request, response):
  policyDeliveries = json.loads(request.GET.first('policyDeliveries', '[]'))
  worker_type = request.GET.first('type', 'classic')
  commonjs_url = '%s://%s:%s/common/security-features/resources/common.js' % (
      request.url_parts.scheme, request.url_parts.hostname,
      request.url_parts.port)
  if worker_type == 'classic':
    import_line = 'importScripts("%s");' % commonjs_url
  else:
    import_line = 'import "%s";' % commonjs_url

  maybe_additional_headers = {}
  error = ''
  for delivery in policyDeliveries:
    if delivery['deliveryType'] == 'meta':
      error = '<meta> cannot be used in WorkerGlobalScope'
    elif delivery['deliveryType'] == 'http-rp':
      if delivery['key'] == 'referrerPolicy':
        maybe_additional_headers['Referrer-Policy'] = delivery['value']
      else:
        error = 'invalid delivery key for http-rp: %s' % delivery['key']
    else:
      error = 'invalid deliveryType: %s' % delivery['deliveryType']

  handler = lambda: util.get_template('worker.js.template') % ({
      'import': import_line,
      'error': error
  })
  util.respond(
      request,
      response,
      payload_generator=handler,
      content_type='text/javascript',
      maybe_additional_headers=maybe_additional_headers)
Esempio n. 2
0
def main(request, response):
    policyDeliveries = json.loads(request.GET.first('policyDeliveries', '[]'))
    worker_type = request.GET.first('type', 'classic')
    commonjs_url = '%s://%s:%s/common/security-features/resources/common.sub.js' % (
        request.url_parts.scheme, request.url_parts.hostname,
        request.url_parts.port)
    if worker_type == 'classic':
        import_line = 'importScripts("%s");' % commonjs_url
    else:
        import_line = 'import "%s";' % commonjs_url

    maybe_additional_headers = {}
    error = ''
    for delivery in policyDeliveries:
        if delivery['deliveryType'] == 'meta':
            error = '<meta> cannot be used in WorkerGlobalScope'
        elif delivery['deliveryType'] == 'http-rp':
            if delivery['key'] == 'referrerPolicy':
                maybe_additional_headers['Referrer-Policy'] = delivery['value']
            else:
                error = 'invalid delivery key for http-rp: %s' % delivery['key']
        else:
            error = 'invalid deliveryType: %s' % delivery['deliveryType']

    handler = lambda: util.get_template('worker.js.template') % ({
        'import': import_line,
        'error': error
    })
    util.respond(request,
                 response,
                 payload_generator=handler,
                 content_type='text/javascript',
                 maybe_additional_headers=maybe_additional_headers)
Esempio n. 3
0
def main(request, response):
    policyDeliveries = json.loads(request.GET.first(b"policyDeliveries",
                                                    b"[]"))
    maybe_additional_headers = {}
    meta = u''
    error = u''
    for delivery in policyDeliveries:
        if delivery[u'deliveryType'] == u'meta':
            if delivery[u'key'] == u'referrerPolicy':
                meta += u'<meta name="referrer" content="%s">' % delivery[
                    u'value']
            else:
                error = u'invalid delivery key'
        elif delivery[u'deliveryType'] == u'http-rp':
            if delivery[u'key'] == u'referrerPolicy':
                maybe_additional_headers[
                    b'Referrer-Policy'] = isomorphic_encode(delivery[u'value'])
            else:
                error = u'invalid delivery key'
        else:
            error = u'invalid deliveryType'

    handler = lambda: util.get_template(u"document.html.template"
                                        ) % ({
                                            u"meta": meta,
                                            u"error": error
                                        })
    util.respond(request,
                 response,
                 payload_generator=handler,
                 content_type=b"text/html",
                 maybe_additional_headers=maybe_additional_headers)
def main(request, response):
    policyDeliveries = json.loads(request.GET.first("policyDeliveries", "[]"))
    maybe_additional_headers = {}
    meta = ''
    error = ''
    for delivery in policyDeliveries:
        if delivery['deliveryType'] == 'meta':
            if delivery['key'] == 'referrerPolicy':
                meta += '<meta name="referrer" content="%s">' % delivery[
                    'value']
            else:
                error = 'invalid delivery key'
        elif delivery['deliveryType'] == 'http-rp':
            if delivery['key'] == 'referrerPolicy':
                maybe_additional_headers['Referrer-Policy'] = delivery['value']
            else:
                error = 'invalid delivery key'
        else:
            error = 'invalid deliveryType'

    handler = lambda: util.get_template("document.html.template"
                                        ) % ({
                                            "meta": meta,
                                            "error": error
                                        })
    util.respond(request,
                 response,
                 payload_generator=handler,
                 content_type="text/html",
                 maybe_additional_headers=maybe_additional_headers)
Esempio n. 5
0
    def execute(self, intent, session):
        image = "https://www.wolframalpha.com/images/press/photos/logos/wa-logo-stacked1-large.jpg"
        session_attributes = {}
        card_title = "Wolfram Distance"
        o1 = intent['slots']['objectA']['value']
        o2 = intent['slots']['objectB']['value']
        query = 'distance' + '%20' + 'between%20' + o1 + '%20' + 'and%20' + o2
        url = "http://api.wolframalpha.com/v2/query?"
        url += "appid=238HJV-7G3G7G8VYU&input="
        url += query
        url += "&format=image,plaintext"
        data = urllib.urlopen(url).read()
        response = ET.fromstring(data)

        #xml_data=urllib.urlopen(url).read()
        #incomingDictData = xmltodict.parse(xml_data)
        #print incomingDictData

        speech = ""
        for pod in response.findall('.//pod'):
            if pod.attrib['title'] == 'History' or pod.attrib['title'] == 'Map':
                for im in pod.findall('.//img'):
                    image = im.attrib['src']
            if pod.attrib['title'] == 'Current result' or pod.attrib[
                    'title'] == 'Result':
                for pt in pod.findall('.//plaintext'):
                    if pt.text:
                        speech = pt.text

        image = "https://authenticspokl.tk/pngify/" + base64.b32encode(
            image) + ".png"

        return util.respond(speech, "Wolfram Alpha", speech, image)
Esempio n. 6
0
    def execute(self, intent, session):
        image = "https://www.wolframalpha.com/images/press/photos/logos/wa-logo-stacked1-large.jpg"
        session_attributes = {}
        card_title = "Wolfram Resistor"
        r1 = intent['slots']['resistorA']['value']
        u1 = intent['slots']['runitA']['value']
        r2 = intent['slots']['resistorB']['value']
        u2 = intent['slots']['runitB']['value']
        op = intent['slots']['operation']['value']
        query = r1 + '%20' + u1 + '%20' + 'in%20' + op + '%20' + r2 + '%20' + u2
        url = "http://api.wolframalpha.com/v2/query?"
        url += "appid=238HJV-7G3G7G8VYU&input="
        url += query
        url += "&format=image,plaintext"
        data = urllib.urlopen(url).read()
        response = ET.fromstring(data)

        #xml_data=urllib.urlopen(url).read()
        #incomingDictData = xmltodict.parse(xml_data)
        #print incomingDictData

        speech = ""
        for pod in response.findall('.//pod'):
            if pod.attrib['title'] == 'Equation':
                for im in pod.findall('.//img'):
                    image = im.attrib['src']
            elif pod.attrib['title'] == 'Result':
                for pt in pod.findall('.//plaintext'):
                    if pt.text:
                        speech += pt.text

        image = "https://authenticspokl.tk/pngify/" + base64.b32encode(
            image) + ".png"

        return util.respond(speech, "Wolfram Alpha", speech, image)
Esempio n. 7
0
    def execute(__self__, intent, session):
        image = "https://www.wolframalpha.com/images/press/photos/logos/wa-logo-stacked1-large.jpg"
        session_attributes = {}
        card_title = "Wolfram Computation"
        n1 = intent['slots']['numA']['value']
        n2 = intent['slots']['numB']['value']
        op = intent['slots']['operation']['value']
        query = n1 + '%20' + op + '%20' + n2
        print query
        print query.replace(' ', '%20')
        url = "http://api.wolframalpha.com/v2/query?"
        url += "appid=238HJV-7G3G7G8VYU&input="
        url += query.replace(' ', '%20')
        url += "&format=image,plaintext"
        data = urllib.urlopen(url).read()
        response = ET.fromstring(data)

        #xml_data=urllib.urlopen(url).read()
        #incomingDictData = xmltodict.parse(xml_data)
        #print incomingDictData
        if op == 'divided by':
            speech = str(float(n1) / float(n2))
        else:
            speech = ""
        for pod in response.findall('.//pod'):
            if pod.attrib['title'] == 'Result' or pod.attrib[
                    'title'] == 'Exact Result':
                for pt in pod.findall('.//plaintext'):
                    if pt.text:
                        speech = pt.text

        image = "https://authenticspokl.tk/pngify/" + base64.b32encode(
            image) + ".png"

        return util.respond(speech, "Wolfram Alpha", speech, image)
Esempio n. 8
0
    def execute(self, intent, session):
        image = "https://www.wolframalpha.com/images/press/photos/logos/wa-logo-stacked1-large.jpg"
        session_attributes = {}
        card_title = "Wolfram"
        temp = intent['slots']['query']['value']
        query = temp.replace(' ', '%20')
        url = "http://api.wolframalpha.com/v2/query?"
        url += "appid=238HJV-7G3G7G8VYU&input="
        url += query
        url += "&format=image,plaintext"
        data = urllib.urlopen(url).read()
        response = ET.fromstring(data)

        #xml_data=urllib.urlopen(url).read()
        #incomingDictData = xmltodict.parse(xml_data)
        #print incomingDictData

        speech = ""
        for pod in response.findall('.//pod'):
            if pod.attrib['title'] == 'Result' or pod.attrib[
                    'title'] == 'Circuit diagram':
                for im in pod.findall('.//img'):
                    image = im.attrib['src']
            if pod.attrib['title'] == 'Result' or pod.attrib[
                    'title'] == 'Definition' or pod.attrib[
                        'title'] == 'Equation' or 'forecast' in pod.attrib[
                            'title']:
                for pt in pod.findall('.//plaintext'):
                    if pt.text:
                        speech += pt.text

        image = "https://authenticspokl.tk/pngify/" + base64.b32encode(
            image) + ".png"

        return util.respond(speech, "Wolfram Alpha", speech, image)
Esempio n. 9
0
def main(request, response):
  policyDeliveries = json.loads(request.GET.first(b'policyDeliveries', b'[]'))
  worker_type = request.GET.first(b'type', b'classic')
  commonjs_url = u'%s://%s:%s/common/security-features/resources/common.sub.js' % (
      request.url_parts.scheme, request.url_parts.hostname,
      request.url_parts.port)
  if worker_type == b'classic':
    import_line = u'importScripts("%s");' % commonjs_url
  else:
    import_line = u'import "%s";' % commonjs_url

  maybe_additional_headers = {}
  error = u''
  for delivery in policyDeliveries:
    if delivery[u'deliveryType'] == u'meta':
      error = u'<meta> cannot be used in WorkerGlobalScope'
    elif delivery[u'deliveryType'] == u'http-rp':
      if delivery[u'key'] == u'referrerPolicy':
        maybe_additional_headers[b'Referrer-Policy'] = isomorphic_encode(delivery[u'value'])
      elif delivery[u'key'] == u'mixedContent' and delivery[u'value'] == u'opt-in':
        maybe_additional_headers[b'Content-Security-Policy'] = b'block-all-mixed-content'
      elif delivery[u'key'] == u'upgradeInsecureRequests' and delivery[u'value'] == u'upgrade':
        maybe_additional_headers[b'Content-Security-Policy'] = b'upgrade-insecure-requests'
      else:
        error = u'invalid delivery key for http-rp: %s' % delivery[u'key']
    else:
      error = u'invalid deliveryType: %s' % delivery[u'deliveryType']

  handler = lambda: util.get_template(u'worker.js.template') % ({
      u'import': import_line,
      u'error': error
  })
  util.respond(
      request,
      response,
      payload_generator=handler,
      content_type=b'text/javascript',
      maybe_additional_headers=maybe_additional_headers)
Esempio n. 10
0
    def execute(__self__, intent, session):
        print 'entering Wolfram Function Skill'
        image = "https://www.wolframalpha.com/images/press/photos/logos/wa-logo-stacked1-large.jpg"
        session_attributes = {}
        card_title = "Wolfram Computation"
        f = intent['slots']['function']['value']
        if f == 'sign':
            f = 'sine'
        print f
        e = intent['slots']['expression']['value']
        print e
        query = f + '(' + e.replace(' ', '%20') + ')'
        print query
        url = "http://api.wolframalpha.com/v2/query?"
        url += "appid=238HJV-7G3G7G8VYU&input="
        url += query
        url += "&format=image,plaintext"
        data = urllib.urlopen(url).read()
        response = ET.fromstring(data)

        #xml_data=urllib.urlopen(url).read()
        #incomingDictData = xmltodict.parse(xml_data)
        #print incomingDictData

        speech = ""
        for pod in response.findall('.//pod'):
            if pod.attrib['title'] == 'Result' or pod.attrib[
                    'title'] == 'Exact Result':
                for pt in pod.findall('.//plaintext'):
                    if pt.text:
                        speech = pt.text

        image = "https://authenticspokl.tk/pngify/" + base64.b32encode(
            image) + ".png"

        return util.respond(speech, "Wolfram Alpha", speech, image)