Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/negotiation.py
Show All 18 Lines | |||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||
# SOFTWARE. | # SOFTWARE. | ||||
# | # | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from decorator import decorator | |||||
from inspect import getcallargs | from inspect import getcallargs | ||||
from decorator import decorator | from typing import Any, List, Optional | ||||
class FormatterNotFound(Exception): | class FormatterNotFound(Exception): | ||||
pass | pass | ||||
class Formatter: | class Formatter: | ||||
format = None | format = None # type: Optional[str] | ||||
mimetypes = [] | mimetypes = [] # type: List[Any] | ||||
def __init__(self, request_mimetype=None): | def __init__(self, request_mimetype=None): | ||||
if request_mimetype is None or request_mimetype not in self.mimetypes: | if request_mimetype is None or request_mimetype not in self.mimetypes: | ||||
try: | try: | ||||
self.response_mimetype = self.mimetypes[0] | self.response_mimetype = self.mimetypes[0] | ||||
except IndexError: | except IndexError: | ||||
raise NotImplementedError( | raise NotImplementedError( | ||||
"%s.mimetypes should be a non-empty list" % | "%s.mimetypes should be a non-empty list" % | ||||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |