Python werkzeug.url_encode() Examples

The following are 10 code examples of werkzeug.url_encode(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module werkzeug , or try the search function .
Example #1
Source File: sale_order.py    From Odoo_Samples with GNU Affero General Public License v3.0 6 votes vote down vote up
def _edi_paypal_url(self, cr, uid, ids, field, arg, context=None):
        res = dict.fromkeys(ids, False)
        for order in self.browse(cr, uid, ids, context=context):
            if order.order_policy in ('prepaid', 'manual') and \
                    order.company_id.paypal_account and order.state != 'draft':
                params = {
                    "cmd": "_xclick",
                    "business": order.company_id.paypal_account,
                    "item_name": order.company_id.name + " Order " + order.name,
                    "invoice": order.name,
                    "amount": order.amount_total,
                    "currency_code": order.pricelist_id.currency_id.name,
                    "button_subtype": "services",
                    "no_note": "1",
                    "bn": "OpenERP_Order_PayNow_" + order.pricelist_id.currency_id.name,
                }
                res[order.id] = "https://www.paypal.com/cgi-bin/webscr?" + url_encode(params)
        return res 
Example #2
Source File: widgets.py    From jbox with MIT License 5 votes vote down vote up
def recaptcha_html(self, public_key):
        html = current_app.config.get('RECAPTCHA_HTML')
        if html:
            return Markup(html)
        params = current_app.config.get('RECAPTCHA_PARAMETERS')
        script = RECAPTCHA_SCRIPT
        if params:
            script += u'?' + url_encode(params)

        attrs = current_app.config.get('RECAPTCHA_DATA_ATTRS', {})
        attrs['sitekey'] = public_key
        snippet = u' '.join([u'data-%s="%s"' % (k, attrs[k]) for k in attrs])
        return Markup(RECAPTCHA_TEMPLATE % (script, snippet)) 
Example #3
Source File: validators.py    From jbox with MIT License 5 votes vote down vote up
def _validate_recaptcha(self, response, remote_addr):
        """Performs the actual validation."""
        try:
            private_key = current_app.config['RECAPTCHA_PRIVATE_KEY']
        except KeyError:
            raise RuntimeError("No RECAPTCHA_PRIVATE_KEY config set")

        data = url_encode({
            'secret':     private_key,
            'remoteip':   remote_addr,
            'response':   response
        })

        http_response = http.urlopen(RECAPTCHA_VERIFY_SERVER, to_bytes(data))

        if http_response.code != 200:
            return False

        json_resp = json.loads(to_unicode(http_response.read()))

        if json_resp["success"]:
            return True

        for error in json_resp.get("error-codes", []):
            if error in RECAPTCHA_ERROR_CODES:
                raise ValidationError(RECAPTCHA_ERROR_CODES[error])

        return False 
Example #4
Source File: widgets.py    From RSSNewsGAE with Apache License 2.0 5 votes vote down vote up
def recaptcha_html(self, public_key):
        html = current_app.config.get('RECAPTCHA_HTML')
        if html:
            return Markup(html)
        params = current_app.config.get('RECAPTCHA_PARAMETERS')
        script = RECAPTCHA_SCRIPT
        if params:
            script += u'?' + url_encode(params)

        attrs = current_app.config.get('RECAPTCHA_DATA_ATTRS', {})
        attrs['sitekey'] = public_key
        snippet = u' '.join([u'data-%s="%s"' % (k, attrs[k]) for k in attrs])
        return Markup(RECAPTCHA_TEMPLATE % (script, snippet)) 
Example #5
Source File: validators.py    From RSSNewsGAE with Apache License 2.0 5 votes vote down vote up
def _validate_recaptcha(self, response, remote_addr):
        """Performs the actual validation."""
        try:
            private_key = current_app.config['RECAPTCHA_PRIVATE_KEY']
        except KeyError:
            raise RuntimeError("No RECAPTCHA_PRIVATE_KEY config set")

        data = url_encode({
            'secret':     private_key,
            'remoteip':   remote_addr,
            'response':   response
        })

        http_response = http.urlopen(RECAPTCHA_VERIFY_SERVER, to_bytes(data))

        if http_response.code != 200:
            return False

        json_resp = json.loads(to_unicode(http_response.read()))

        if json_resp["success"]:
            return True

        for error in json_resp.get("error-codes", []):
            if error in RECAPTCHA_ERROR_CODES:
                raise ValidationError(RECAPTCHA_ERROR_CODES[error])

        return False 
Example #6
Source File: web_main.py    From odoo-development with GNU Affero General Public License v3.0 5 votes vote down vote up
def _build_debug_response(self):
        result = None

        try:
            query = request.params
            query.update({'debug': u''})
            url = '/web?' + werkzeug.url_encode(query)
            result = redirect_with_hash(url)
        except Exception as ex:
            _logger.error(self._error_response.format(ex))

        return result

    # ------------------------ LONG CHARACTER STRING -------------------------- 
Example #7
Source File: helpers.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def url_rewrite(url=None, **kwargs):
    scheme, netloc, path, query, fragments = urlsplit(url or request.url)
    params = url_decode(query)
    for key, value in kwargs.items():
        params.setlist(key,
                       value if isinstance(value, (list, tuple)) else [value])
    return Markup(urlunsplit((scheme, netloc, path, url_encode(params),
                  fragments))) 
Example #8
Source File: helpers.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def url_add(url=None, **kwargs):
    scheme, netloc, path, query, fragments = urlsplit(url or request.url)
    params = url_decode(query)
    for key, value in kwargs.items():
        if value not in params.getlist(key):
            params.add(key, value)
    return Markup(urlunsplit((scheme, netloc, path, url_encode(params),
                              fragments))) 
Example #9
Source File: helpers.py    From udata with GNU Affero General Public License v3.0 5 votes vote down vote up
def url_del(url=None, *args, **kwargs):
    scheme, netloc, path, query, fragments = urlsplit(url or request.url)
    params = url_decode(query)
    for key in args:
        params.poplist(key)
    for key, value in kwargs.items():
        lst = params.poplist(key)
        if str(value) in lst:
            lst.remove(str(value))
        params.setlist(key, lst)
    return Markup(urlunsplit((scheme, netloc, path, url_encode(params),
                              fragments))) 
Example #10
Source File: oauth_login_ext.py    From weodoo with MIT License 5 votes vote down vote up
def _get_auth_link_wo(self, provider=None):
        if not provider:
            provider = request.env(user=1).ref('weodoo.provider_third')

        return_url = request.httprequest.url_root + 'auth_oauth/signin3rd'
        state = self.get_state(provider)
        self._deal_state_r(state)
        params = dict(
            response_type='token',
            client_id=provider['client_id'],
            redirect_uri=return_url,
            scope=provider['scope'],
            state=json.dumps(state),
        )
        return "%s?%s" % (provider['auth_endpoint'], werkzeug.url_encode(params))