我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用werkzeug.url_encode()。
def __call__(self, path=None, path_args=None, **kw): path = path or self.path for k, v in self.args.items(): kw.setdefault(k, v) path_args = set(path_args or []).union(self.path_args) paths, fragments = [], [] for key, value in kw.items(): if value and key in path_args: if isinstance(value, browse_record): paths.append((key, slug(value))) else: paths.append((key, value)) elif value: if isinstance(value, list) or isinstance(value, set): fragments.append(werkzeug.url_encode([(key, item) for item in value])) else: fragments.append(werkzeug.url_encode([(key, value)])) for key, value in paths: path += '/' + key + '/%s' % value if fragments: path += '?' + '&'.join(fragments) return path
def __call__(self, path = None, **kw): if not path: path = self.path for k, v in self.args.items(): kw.setdefault(k, v) l = [] for k, v in kw.items(): if v: if isinstance(v, list) or isinstance(v, set): l.append(werkzeug.url_encode([ (k, i) for i in v ])) else: l.append(werkzeug.url_encode([(k, v)])) if l: path += '?' + '&'.join(l) return path
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))
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
def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" if current_app.config.get('RECAPTCHA_USE_SSL', False): server = RECAPTCHA_SSL_API_SERVER else: server = RECAPTCHA_API_SERVER try: public_key = current_app.config['RECAPTCHA_PUBLIC_KEY'] except KeyError: raise RuntimeError("RECAPTCHA_PUBLIC_KEY config not set") query_options = dict(k=public_key) if field.recaptcha_error is not None: query_options['error'] = text_type(field.recaptcha_error) query = url_encode(query_options) _ = field.gettext options = { 'theme': 'clean', 'custom_translations': { 'visual_challenge': _('Get a visual challenge'), 'audio_challenge': _('Get an audio challenge'), 'refresh_btn': _('Get a new challenge'), 'instructions_visual': _('Type the two words:'), 'instructions_audio': _('Type what you hear:'), 'help_btn': _('Help'), 'play_again': _('Play sound again'), 'cant_hear_this': _('Download sound as MP3'), 'incorrect_try_again': _('Incorrect. Try again.'), } } options.update(current_app.config.get('RECAPTCHA_OPTIONS', {})) return self.recaptcha_html(server, query, options)
def _validate_recaptcha(self, challenge, 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({ 'privatekey': private_key, 'remoteip': remote_addr, 'challenge': challenge, 'response': response }) response = http.urlopen(RECAPTCHA_VERIFY_SERVER, to_bytes(data)) if response.code != 200: return False rv = [l.strip() for l in response.readlines()] if rv and rv[0] == to_bytes('true'): return True if len(rv) > 1: error = rv[1] if error in self._error_codes: raise RuntimeError(self._error_codes[error]) return False
def __call__(self, field, error=None, **kwargs): """Returns the recaptcha input HTML.""" try: public_key = current_app.config['RECAPTCHA_PUBLIC_KEY'] except KeyError: raise RuntimeError("RECAPTCHA_PUBLIC_KEY config not set") query_options = dict(k=public_key) if field.recaptcha_error is not None: query_options['error'] = text_type(field.recaptcha_error) query = url_encode(query_options) _ = field.gettext options = { 'theme': 'clean', 'custom_translations': { 'audio_challenge': _('Get an audio challenge'), 'cant_hear_this': _('Download sound as MP3'), 'help_btn': _('Help'), 'image_alt_text': _('reCAPTCHA challenge image'), 'incorrect_try_again': _('Incorrect. Try again.'), 'instructions_audio': _('Type what you hear'), 'instructions_visual': _('Type the text'), 'play_again': _('Play sound again'), 'privacy_and_terms': _('Privacy & Terms'), 'refresh_btn': _('Get a new challenge'), 'visual_challenge': _('Get a visual challenge'), } } options.update(current_app.config.get('RECAPTCHA_OPTIONS', {})) return self.recaptcha_html(query, options)
def delete_query(*new_values): args = request.args.copy() for key in new_values: del args[key] return '{}?{}'.format(request.path, url_encode(args))
def modify_query(key, value): args = request.args.copy() args[key] = value return '{}?{}'.format(request.path, url_encode(args))
def _validate_recaptcha(self, response, remote_addr): """Performs the actual validation.""" try: private_key = flaskbb_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