def _encode_url(self, data): query = self.query if data: data = native_str(data) if isinstance(data, str): data = parse_qsl(data) else: data = mapping_iterator(data) query = parse_qsl(query) query.extend(data) query = urlencode(query) self.query = query
def _encode_url(self, body): query = self.query if body: body = native_str(body) if isinstance(body, str): body = parse_qsl(body) else: body = mapping_iterator(body) query = parse_qsl(query) query.extend(body) self.data = query query = urlencode(query) self.query = query
def _buildurl(self): pre = '' if self._user: if not self._password: raise ImproperlyConfigured('user but not password') pre = '%s:%s@' % (self._user, self._password) elif self._password: raise ImproperlyConfigured('password but not user') assert self._password host = self._host if isinstance(host, tuple): host = '%s:%s' % host host = '%s%s' % (pre, host) path = '/%s' % self._database if self._database else '' query = urlencode(self._urlparams) return urlunparse((self._name, host, path, '', query, ''))
def test_expect(self): http = self.client() data = (('bla', 'foo'), ('unz', 'whatz'), ('numero', '1'), ('numero', '2')) bdata = urlencode(data) r = make_async(http.post(self.httpbin('post'), data=b'', headers=[('expect','100-continue'), ('Content-length', str(len(bdata)))])) yield r response = r.result self.assertEqual(response.status_code, 100) r = make_async(response.write(bdata)) yield r response = r.result self.assertEqual(response.status_code, 200) self.assertEqual(response.connection, None)
def _encode_params(self, data): content_type = self.headers.get('content-type') # No content type given if not content_type: if self.encode_multipart: return encode_multipart_formdata( data, boundary=self.multipart_boundary, charset=self.charset) else: content_type = 'application/x-www-form-urlencoded' body = urlencode(data).encode(self.charset) elif content_type in JSON_CONTENT_TYPES: body = json.dumps(data).encode(self.charset) else: raise ValueError("Don't know how to encode body for %s" % content_type) return body, content_type
def _encode_params(self): content_type = self.headers.get('content-type') # No content type given if not content_type: if self.encode_multipart: return encode_multipart_formdata( self.data, boundary=self.multipart_boundary, charset=self.charset) else: content_type = 'application/x-www-form-urlencoded' body = urlencode(self.data).encode(self.charset) elif content_type in JSON_CONTENT_TYPES: body = json.dumps(self.data).encode(self.charset) else: raise ValueError("Don't know how to encode body for %s" % content_type) return body, content_type
def _buildurl(self, **kw): pre = '' if self._user: if self._password: pre = '%s:%s@' % (self._user, self._password) else: pre = '%s@' % self._user elif self._password: raise ImproperlyConfigured('password but not user') assert self._password host = self._host if isinstance(host, tuple): host = '%s:%s' % host host = '%s%s' % (pre, host) path = '/%s' % self._database if self._database else '' kw.update(self._urlparams) query = urlencode(kw) scheme = self._name if self._scheme: scheme = '%s+%s' % (self._scheme, scheme) return urlunparse((scheme, host, path, '', query, ''))
def ping_google(sitemap_url, ping_url=PING_URL): """ Alerts Google that the sitemap at ``sitemap_url`` has been updated. """ params = urlencode({'sitemap': sitemap_url}) return urllibr.urlopen("%s?%s" % (ping_url, params))