Skip to content

Commit 9a75b23

Browse files
committed
Update for list_routes
1 parent c68cdff commit 9a75b23

File tree

3 files changed

+252
-251
lines changed

3 files changed

+252
-251
lines changed

rasa/core/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,25 @@ def find_route(suffix: Text, path: Text) -> Optional[Text]:
9898
return name
9999
return None
100100

101-
for endpoint, route in app.router.routes_all.items():
101+
for route in app.router.routes:
102+
endpoint = route.parts
102103
if endpoint[:-1] in app.router.routes_all and endpoint[-1] == "/":
103104
continue
104105

105106
options = {}
106-
for arg in route.parameters:
107+
for arg in route._params:
107108
options[arg] = f"[{arg}]"
108109

109110
if not isinstance(route.handler, CompositionView):
110-
handlers = [(list(route.methods)[0], route.name)]
111+
handlers = [(list(route.methods)[0], route.name.split(".")[-1])]
111112
else:
112113
handlers = [
113114
(method, find_route(v.__name__, endpoint) or v.__name__)
114115
for method, v in route.handler.handlers.items()
115116
]
116117

117118
for method, name in handlers:
118-
line = unquote(f"{endpoint:50s} {method:30s} {name}")
119+
line = unquote(f"{endpoint[0]:50s} {method:30s} {name}")
119120
output[name] = line
120121

121122
url_table = "\n".join(output[url] for url in sorted(output))

rasa/server.py

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ class ErrorResponse(Exception):
9797
"""Common exception to handle failing API requests."""
9898

9999
def __init__(
100-
self,
101-
status: Union[int, HTTPStatus],
102-
reason: Text,
103-
message: Text,
104-
details: Any = None,
105-
help_url: Optional[Text] = None,
100+
self,
101+
status: Union[int, HTTPStatus],
102+
reason: Text,
103+
message: Text,
104+
details: Any = None,
105+
help_url: Optional[Text] = None,
106106
) -> None:
107107
"""Creates error.
108108
@@ -133,7 +133,7 @@ def _docs(sub_url: Text) -> Text:
133133

134134

135135
def ensure_loaded_agent(
136-
app: Sanic, require_core_is_ready: bool = False
136+
app: Sanic, require_core_is_ready: bool = False
137137
) -> Callable[[Callable], Callable[..., Any]]:
138138
"""Wraps a request handler ensuring there is a loaded and usable agent.
139139
@@ -181,7 +181,7 @@ def decorated(request: Request, *args: Any, **kwargs: Any) -> "SanicResponse":
181181

182182

183183
def requires_auth(
184-
app: Sanic, token: Optional[Text] = None
184+
app: Sanic, token: Optional[Text] = None
185185
) -> Callable[["SanicView"], "SanicView"]:
186186
"""Wraps a request handler with token authentication."""
187187

@@ -200,7 +200,7 @@ def conversation_id_from_args(args: Any, kwargs: Any) -> Optional[Text]:
200200
return None
201201

202202
async def sufficient_scope(
203-
request: Request, *args: Any, **kwargs: Any
203+
request: Request, *args: Any, **kwargs: Any
204204
) -> Optional[bool]:
205205
# This is a coroutine since `sanic-jwt==1.6`
206206
jwt_data = await rasa.utils.common.call_potential_coroutine(
@@ -222,7 +222,7 @@ async def sufficient_scope(
222222

223223
@wraps(f)
224224
async def decorated(
225-
request: Request, *args: Any, **kwargs: Any
225+
request: Request, *args: Any, **kwargs: Any
226226
) -> response.HTTPResponse:
227227

228228
provided = request.args.get("token", None)
@@ -232,7 +232,7 @@ async def decorated(
232232
result = f(request, *args, **kwargs)
233233
return await result if isawaitable(result) else result
234234
elif app.config.get(
235-
"USE_JWT"
235+
"USE_JWT"
236236
) and await rasa.utils.common.call_potential_coroutine(
237237
# This is a coroutine since `sanic-jwt==1.6`
238238
request.app.ctx.auth.is_authenticated(request)
@@ -267,7 +267,7 @@ async def decorated(
267267

268268

269269
def event_verbosity_parameter(
270-
request: Request, default_verbosity: EventVerbosity
270+
request: Request, default_verbosity: EventVerbosity
271271
) -> EventVerbosity:
272272
"""Create `EventVerbosity` object using request params if present."""
273273
event_verbosity_str = request.args.get(
@@ -287,10 +287,10 @@ def event_verbosity_parameter(
287287

288288

289289
def get_test_stories(
290-
processor: "MessageProcessor",
291-
conversation_id: Text,
292-
until_time: Optional[float],
293-
fetch_all_sessions: bool = False,
290+
processor: "MessageProcessor",
291+
conversation_id: Text,
292+
until_time: Optional[float],
293+
fetch_all_sessions: bool = False,
294294
) -> Text:
295295
"""Retrieves test stories from `processor` for all conversation sessions for
296296
`conversation_id`.
@@ -336,10 +336,10 @@ def get_test_stories(
336336

337337

338338
async def update_conversation_with_events(
339-
conversation_id: Text,
340-
processor: "MessageProcessor",
341-
domain: Domain,
342-
events: List[Event],
339+
conversation_id: Text,
340+
processor: "MessageProcessor",
341+
domain: Domain,
342+
events: List[Event],
343343
) -> DialogueStateTracker:
344344
"""Fetches or creates a tracker for `conversation_id` and appends `events` to it.
345345
@@ -398,10 +398,10 @@ async def authenticate(_: Request) -> NoReturn:
398398

399399

400400
def create_ssl_context(
401-
ssl_certificate: Optional[Text],
402-
ssl_keyfile: Optional[Text],
403-
ssl_ca_file: Optional[Text] = None,
404-
ssl_password: Optional[Text] = None,
401+
ssl_certificate: Optional[Text],
402+
ssl_keyfile: Optional[Text],
403+
ssl_ca_file: Optional[Text] = None,
404+
ssl_password: Optional[Text] = None,
405405
) -> Optional["SSLContext"]:
406406
"""Create an SSL context if a proper certificate is passed.
407407
@@ -460,10 +460,10 @@ def _create_emulator(mode: Optional[Text]) -> Emulator:
460460

461461

462462
async def _load_agent(
463-
model_path: Optional[Text] = None,
464-
model_server: Optional[EndpointConfig] = None,
465-
remote_storage: Optional[Text] = None,
466-
endpoints: Optional[AvailableEndpoints] = None,
463+
model_path: Optional[Text] = None,
464+
model_server: Optional[EndpointConfig] = None,
465+
remote_storage: Optional[Text] = None,
466+
endpoints: Optional[AvailableEndpoints] = None,
467467
) -> Agent:
468468
try:
469469
loaded_agent = await rasa.core.agent.load_agent(
@@ -492,7 +492,7 @@ async def _load_agent(
492492

493493

494494
def configure_cors(
495-
app: Sanic, cors_origins: Union[Text, List[Text], None] = ""
495+
app: Sanic, cors_origins: Union[Text, List[Text], None] = ""
496496
) -> None:
497497
"""Configure CORS origins for the given app."""
498498

@@ -533,7 +533,7 @@ def async_if_callback_url(f: Callable[..., Coroutine]) -> Callable:
533533

534534
@wraps(f)
535535
async def decorated_function(
536-
request: Request, *args: Any, **kwargs: Any
536+
request: Request, *args: Any, **kwargs: Any
537537
) -> HTTPResponse:
538538
callback_url = request.args.get("callback_url")
539539
# Only process request asynchronously if the user specified a `callback_url`
@@ -595,7 +595,7 @@ def run_in_thread(f: Callable[..., Coroutine]) -> Callable:
595595

596596
@wraps(f)
597597
async def decorated_function(
598-
request: Request, *args: Any, **kwargs: Any
598+
request: Request, *args: Any, **kwargs: Any
599599
) -> HTTPResponse:
600600
# Use a sync wrapper for our `async` function as `run_in_executor` only supports
601601
# sync functions
@@ -628,13 +628,13 @@ async def decorated_function(*args: Any, **kwargs: Any) -> HTTPResponse:
628628

629629

630630
def create_app(
631-
agent: Optional["Agent"] = None,
632-
cors_origins: Union[Text, List[Text], None] = "*",
633-
auth_token: Optional[Text] = None,
634-
response_timeout: int = DEFAULT_RESPONSE_TIMEOUT,
635-
jwt_secret: Optional[Text] = None,
636-
jwt_method: Text = "HS256",
637-
endpoints: Optional[AvailableEndpoints] = None,
631+
agent: Optional["Agent"] = None,
632+
cors_origins: Union[Text, List[Text], None] = "*",
633+
auth_token: Optional[Text] = None,
634+
response_timeout: int = DEFAULT_RESPONSE_TIMEOUT,
635+
jwt_secret: Optional[Text] = None,
636+
jwt_method: Text = "HS256",
637+
endpoints: Optional[AvailableEndpoints] = None,
638638
) -> Sanic:
639639
"""Class representing a Rasa HTTP server."""
640640
app = Sanic(__name__)
@@ -662,7 +662,7 @@ def create_app(
662662

663663
@app.exception(ErrorResponse)
664664
async def handle_error_response(
665-
request: Request, exception: ErrorResponse
665+
request: Request, exception: ErrorResponse
666666
) -> HTTPResponse:
667667
return response.json(exception.error_info, status=exception.status)
668668

@@ -740,7 +740,7 @@ async def append_events(request: Request, conversation_id: Text) -> HTTPResponse
740740
output_channel = _get_output_channel(request, tracker)
741741

742742
if rasa.utils.endpoints.bool_arg(
743-
request, EXECUTE_SIDE_EFFECTS_QUERY_KEY, False
743+
request, EXECUTE_SIDE_EFFECTS_QUERY_KEY, False
744744
):
745745
await processor.execute_side_effects(
746746
events, tracker, output_channel
@@ -1071,7 +1071,7 @@ async def train(request: Request, temporary_directory: Path) -> HTTPResponse:
10711071
@ensure_loaded_agent(app, require_core_is_ready=True)
10721072
@inject_temp_dir
10731073
async def evaluate_stories(
1074-
request: Request, temporary_directory: Path
1074+
request: Request, temporary_directory: Path
10751075
) -> HTTPResponse:
10761076
"""Evaluate stories against the currently loaded model."""
10771077
validate_request_body(
@@ -1103,7 +1103,7 @@ async def evaluate_stories(
11031103
@run_in_thread
11041104
@inject_temp_dir
11051105
async def evaluate_intents(
1106-
request: Request, temporary_directory: Path
1106+
request: Request, temporary_directory: Path
11071107
) -> HTTPResponse:
11081108
"""Evaluate intents against a Rasa model."""
11091109
validate_request_body(
@@ -1151,7 +1151,7 @@ async def evaluate_intents(
11511151
)
11521152

11531153
async def _evaluate_model_using_test_set(
1154-
model_path: Text, test_data_file: Text
1154+
model_path: Text, test_data_file: Text
11551155
) -> Dict:
11561156
logger.info("Starting model evaluation using test set.")
11571157

@@ -1203,9 +1203,9 @@ async def _cross_validate(data_file: Text, config_file: Text, folds: int) -> Dic
12031203
return evaluation_results
12041204

12051205
def _get_evaluation_results(
1206-
intent_report: CVEvaluationResult,
1207-
entity_report: CVEvaluationResult,
1208-
response_selector_report: CVEvaluationResult,
1206+
intent_report: CVEvaluationResult,
1207+
entity_report: CVEvaluationResult,
1208+
response_selector_report: CVEvaluationResult,
12091209
) -> Dict[Text, Any]:
12101210
eval_name_mapping = {
12111211
"intent_evaluation": intent_report,
@@ -1366,7 +1366,7 @@ async def get_domain(request: Request) -> HTTPResponse:
13661366

13671367

13681368
def _get_output_channel(
1369-
request: Request, tracker: Optional[DialogueStateTracker]
1369+
request: Request, tracker: Optional[DialogueStateTracker]
13701370
) -> OutputChannel:
13711371
"""Returns the `OutputChannel` which should be used for the bot's responses.
13721372
@@ -1381,8 +1381,8 @@ def _get_output_channel(
13811381
requested_output_channel = request.args.get(OUTPUT_CHANNEL_QUERY_KEY)
13821382

13831383
if (
1384-
requested_output_channel == USE_LATEST_INPUT_CHANNEL_AS_OUTPUT_CHANNEL
1385-
and tracker
1384+
requested_output_channel == USE_LATEST_INPUT_CHANNEL_AS_OUTPUT_CHANNEL
1385+
and tracker
13861386
):
13871387
requested_output_channel = tracker.get_latest_input_channel()
13881388

@@ -1398,7 +1398,7 @@ def _get_output_channel(
13981398
# otherwise use `CollectingOutputChannel`
13991399
return reduce(
14001400
lambda output_channel_created_so_far, input_channel: (
1401-
input_channel.get_output_channel() or output_channel_created_so_far
1401+
input_channel.get_output_channel() or output_channel_created_so_far
14021402
),
14031403
matching_channels,
14041404
CollectingOutputChannel(),
@@ -1445,7 +1445,7 @@ def _validate_json_training_payload(rjs: Dict) -> None:
14451445

14461446

14471447
def _training_payload_from_yaml(
1448-
request: Request, temp_dir: Path, file_name: Text = "data.yml"
1448+
request: Request, temp_dir: Path, file_name: Text = "data.yml"
14491449
) -> Dict[Text, Any]:
14501450
logger.debug("Extracting YAML training data from request body.")
14511451

0 commit comments

Comments
 (0)