• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rero / sonar / 17425918180

03 Sep 2025 07:11AM UTC coverage: 95.796% (-0.6%) from 96.378%
17425918180

push

github

PascalRepond
translations: extract messages

Co-Authored-by: Pascal Repond <pascal.repond@rero.ch>

7816 of 8159 relevant lines covered (95.8%)

0.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/sonar/resources/resources/responses.py
1
# Swiss Open Access Repository
2
# Copyright (C) 2021 RERO
3
#
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU Affero General Public License as published by
6
# the Free Software Foundation, version 3 of the License.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
12
#
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15

16
"""SONAR resources responses."""
17

18
from flask import Response
1✔
19
from flask import make_response as flask_make_response
1✔
20
from flask_resources.responses import ResponseHandler
1✔
21

22

23
class StreamResponseHandler(ResponseHandler):
1✔
24
    """Stream response."""
25

26
    filename = None
1✔
27

28
    def __init__(self, serializer, filename="records", headers=None):
1✔
29
        """Stream response initialization.
30

31
        :param filename: File name.
32
        :param serializer: Record serializer.
33
        """
34
        self.filename = filename
1✔
35
        super().__init__(serializer=serializer, headers=headers)
1✔
36

37
    def make_response(self, obj_or_list, code, many=False):
1✔
38
        """Builds a response for one object."""
39
        # If view returns a response, bypass the serialization.
40
        if isinstance(obj_or_list, Response):
1✔
41
            return obj_or_list
×
42

43
        # https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask.make_response
44
        # (body, status, header)
45
        serialize = self.serializer.serialize_object_list if many else self.serializer.serialize_object
1✔
46

47
        response = flask_make_response(
1✔
48
            ("" if obj_or_list is None else Response(self.serializer.serialize_object_list(obj_or_list))),
49
            code,
50
        )
51

52
        response.headers["Content-Disposition"] = f"attachment; filename={self.filename}"
1✔
53
        return response
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc