MCPcopy
hub / github.com/beetbox/beets / responder

Function responder

beetsplug/web/__init__.py:127–166  ·  view source on GitHub ↗
(ids)

Source from the content-addressed store, hash-verified

125
126 def make_responder(retriever):
127 def responder(ids):
128 entities = [retriever(id_) for id_ in ids]
129 entities = [entity for entity in entities if entity]
130
131 if get_method() == "DELETE":
132 if app.config.get("READONLY", True):
133 return flask.abort(405)
134
135 for entity in entities:
136 entity.remove(delete=is_delete())
137
138 return flask.make_response(jsonify({"deleted": True}), 200)
139
140 if get_method() == "PATCH" and patchable:
141 if app.config.get("READONLY", True):
142 return flask.abort(405)
143
144 for entity in entities:
145 entity.update(flask.request.get_json())
146 entity.try_sync(True, False) # write, don't move
147
148 if len(entities) == 1:
149 return flask.jsonify(_rep(entities[0], expand=is_expand()))
150 if entities:
151 return app.response_class(
152 json_generator(entities, root=name),
153 mimetype="application/json",
154 )
155
156 elif get_method() == "GET":
157 if len(entities) == 1:
158 return flask.jsonify(_rep(entities[0], expand=is_expand()))
159 if entities:
160 return app.response_class(
161 json_generator(entities, root=name),
162 mimetype="application/json",
163 )
164 return flask.abort(404)
165
166 return flask.abort(405)
167
168 responder.__name__ = f"get_{name}"
169

Callers

nothing calls this directly

Calls 11

get_methodFunction · 0.85
is_deleteFunction · 0.85
_repFunction · 0.85
is_expandFunction · 0.85
json_generatorFunction · 0.85
abortMethod · 0.80
getMethod · 0.45
removeMethod · 0.45
updateMethod · 0.45
get_jsonMethod · 0.45
try_syncMethod · 0.45

Tested by

no test coverage detected