Skip to content

Commit

Permalink
workaournd fix of invalid pyramid route_prefix path (relates to Pylon…
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Apr 6, 2024
1 parent bab932d commit dc4961d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
4 changes: 1 addition & 3 deletions weaver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
from typing import TYPE_CHECKING

import yaml
from pyramid.config import Configurator
from pyramid.settings import asbool

from weaver.config import WEAVER_DEFAULT_REQUEST_OPTIONS_CONFIG, get_weaver_config_file, get_weaver_configuration
from weaver.database import get_db
from weaver.processes.builtin import register_builtin_processes
from weaver.processes.utils import register_cwl_processes_from_config, register_wps_processes_from_config
from weaver.utils import parse_extra_options, setup_cache, setup_loggers
from weaver.wps_restapi.patches import patch_pyramid_view_no_auto_head_get_method
from weaver.wps_restapi.patches import Configurator, patch_pyramid_view_no_auto_head_get_method

if TYPE_CHECKING:
from typing import Any
Expand Down
39 changes: 38 additions & 1 deletion weaver/wps_restapi/patches.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
"""
Helpers to work around some default view configurations that are not desired.
"""
import contextlib
from typing import TYPE_CHECKING

from cornice import Service as ServiceAutoGetHead
from pyramid.predicates import RequestMethodPredicate
from pyramid.config import Configurator as PyramidConfigurator
from pyramid.util import as_sorted_tuple

if TYPE_CHECKING:
from typing import Any, Tuple, Union

from pyramid.config import Configurator

class Configurator(PyramidConfigurator):
@contextlib.contextmanager
def route_prefix_context(self, route_prefix):
"""
Copy of the original configurator, with tweak for leaving the leading ``/`` of the supplied ``route_prefix``.
.. fixme::
Workaround for https://github.com/Pylons/pyramid/issues/3758
"""
original_route_prefix = self.route_prefix

if route_prefix is None:
route_prefix = ''

old_route_prefix = self.route_prefix
if old_route_prefix is None:
old_route_prefix = ''

route_prefix = '{}/{}'.format(
old_route_prefix.rstrip('/'), route_prefix.lstrip('/')
)

route_prefix = route_prefix.rstrip('/') # FIXME: this is the only change 'strip' -> 'rstrip'

if not route_prefix:
route_prefix = None

self.begin()
try:
self.route_prefix = route_prefix
yield

finally:
self.route_prefix = original_route_prefix
self.end()


class NoAutoHeadList(list):
Expand Down

0 comments on commit dc4961d

Please sign in to comment.