def get_url(ctx, *path, **query): path = [ urllib.quote(unicode(sub_fragment).encode('utf-8'), safe=',/:').decode('utf-8') for fragment in path if fragment for sub_fragment in unicode(fragment).split(u'/') if sub_fragment ] query = dict((str(name), strings.deep_encode(value)) for name, value in sorted(query.iteritems()) if value not in (None, [], (), '')) return u'{0}/{1}{2}'.format( get_base_url(ctx), u'/'.join(path), ('?' + urllib.urlencode(query, doseq=True)) if query else '')
def get_url(ctx, *path, **query): path = [ urllib.quote(unicode(sub_fragment).encode('utf-8'), safe = ',/:').decode('utf-8') for fragment in path if fragment for sub_fragment in unicode(fragment).split(u'/') if sub_fragment ] query = dict( (str(name), strings.deep_encode(value)) for name, value in sorted(query.iteritems()) if value not in (None, [], (), '') ) return u'{0}/{1}{2}'.format(get_base_url(ctx), u'/'.join(path), ('?' + urllib.urlencode(query, doseq = True)) if query else '')
def get_url(ctx, *path, **query): lang = query.pop('lang', None) or ctx.lang[0] path = [ urllib.quote(unicode(sub_fragment).encode('utf-8'), safe=',/:').decode('utf-8') for fragment in itertools.chain( [ lang if lang != conf['languages'][0] else None, ], path, ) if fragment for sub_fragment in unicode(fragment).split(u'/') if sub_fragment ] query = dict((str(name), strings.deep_encode(value)) for name, value in sorted(query.iteritems()) if value not in (None, [], (), '')) return u'{0}/{1}{2}'.format( get_base_url(ctx), u'/'.join(path), ('?' + urllib.urlencode(query, doseq=True)) if query else '')
def iter_full_urls(ctx, *path, **query): assert application_url is not None host_urls = conf['host_urls'] if host_urls is None: yield get_full_url(ctx, *path, **query) else: path = [ urllib.quote(unicode(sub_fragment).encode('utf-8'), safe=',/:').decode('utf-8') for fragment in urlparse.urlsplit(application_url).path.split('/') + path if fragment for sub_fragment in unicode(fragment).split(u'/') if sub_fragment ] query = dict((str(name), strings.deep_encode(value)) for name, value in sorted(query.iteritems()) if value not in (None, [], (), '')) for host_url in host_urls: yield u'{0}{1}{2}'.format( host_url, u'/'.join(path), ('?' + urllib.urlencode(query, doseq=True)) if query else '')
def iter_full_urls(ctx, *path, **query): assert application_url is not None host_urls = conf['host_urls'] if host_urls is None: yield get_full_url(ctx, *path, **query) else: path = [ urllib.quote(unicode(sub_fragment).encode('utf-8'), safe = ',/:').decode('utf-8') for fragment in urlparse.urlsplit(application_url).path.split('/') + path if fragment for sub_fragment in unicode(fragment).split(u'/') if sub_fragment ] query = dict( (str(name), strings.deep_encode(value)) for name, value in sorted(query.iteritems()) if value not in (None, [], (), '') ) for host_url in host_urls: yield u'{0}{1}{2}'.format(host_url, u'/'.join(path), ('?' + urllib.urlencode(query, doseq = True)) if query else '')
def add_file_bytes(self, fieldname, filename, file_bytes, mimetype = None): """Add a file to be uploaded.""" if mimetype is None: mimetype = mimetypes.guess_type(filename)[0] or 'application/octet-stream' self.files.append((str(fieldname), strings.deep_encode(filename), str(mimetype), file_bytes))
def add_field(self, name, value): """Add a simple field to the form data.""" self.form_fields.append((str(name), strings.deep_encode(value)))