def validate_form_param(value, encoding): if encoding == 'application/json': return _validate_json_data(value) elif encoding == 'multipart/form-data': return _validate_form_field(value, allow_files=True) elif encoding == 'application/x-www-form-urlencoded': return _validate_form_field(value) msg = 'Unsupported encoding "%s" for outgoing request.' raise exceptions.NetworkError(msg % encoding)
def determine_transport(transports, url): """ Given a URL determine the appropriate transport instance. """ url_components = urlparse.urlparse(url) scheme = url_components.scheme.lower() netloc = url_components.netloc if not scheme: raise exceptions.NetworkError("URL missing scheme '%s'." % url) if not netloc: raise exceptions.NetworkError("URL missing hostname '%s'." % url) for transport in transports: if scheme in transport.schemes: return transport raise exceptions.NetworkError("Unsupported URL scheme '%s'." % scheme)
def validate_body_param(value, encoding): if encoding == 'application/json': return _validate_json_data(value) elif encoding == 'multipart/form-data': return _validate_form_object(value, allow_files=True) elif encoding == 'application/x-www-form-urlencoded': return _validate_form_object(value) elif encoding == 'application/octet-stream': if not is_file(value): msg = 'Must be an file upload.' raise exceptions.ParameterError(msg) return value msg = 'Unsupported encoding "%s" for outgoing request.' raise exceptions.NetworkError(msg % encoding)