Path 1: 1 calls (0.25)

'FOO_' (1)

True (1)

True (1)

{'option_1': 'foo option 1', 'option_2': 'foo option 2'} (1)

1def get_namespace(
2        self, namespace: str, lowercase: bool = True, trim_namespace: bool = True
3    ) -> dict[str, t.Any]:
4        """Returns a dictionary containing a subset of configuration options
5        that match the specified namespace/prefix. Example usage::
6
7            app.config['IMAGE_STORE_TYPE'] = 'fs'
8            app.config['IMAGE_STORE_PATH'] = '/var/app/images'
9            app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
10            image_store_config = app.config.get_namespace('IMAGE_STORE_')
11
12        The resulting dictionary `image_store_config` would look like::
13
14            {
15                'type': 'fs',
16                'path': '/var/app/images',
17                'base_url': 'http://img.website.com'
18            }
19
20        This is often useful when configuration options map directly to
21        keyword arguments in functions or class constructors.
22
23        :param namespace: a configuration namespace
24        :param lowercase: a flag indicating if the keys of the resulting
25                          dictionary should be lowercase
26        :param trim_namespace: a flag indicating if the keys of the resulting
27                          dictionary should not include the namespace
28
29        .. versionadded:: 0.11
30        """
31        rv = {}
32        for k, v in self.items():
33            if not k.startswith(namespace):
34                continue
35            if trim_namespace:
36                key = k[len(namespace) :]
37            else:
38                key = k
39            if lowercase:
40                key = key.lower()
41            rv[key] = v
42        return rv
            

Path 2: 1 calls (0.25)

'BAR_' (1)

False (1)

True (1)

{'STUFF_1': 'bar stuff 1', 'STUFF_2': 'bar stuff 2'} (1)

1def get_namespace(
2        self, namespace: str, lowercase: bool = True, trim_namespace: bool = True
3    ) -> dict[str, t.Any]:
4        """Returns a dictionary containing a subset of configuration options
5        that match the specified namespace/prefix. Example usage::
6
7            app.config['IMAGE_STORE_TYPE'] = 'fs'
8            app.config['IMAGE_STORE_PATH'] = '/var/app/images'
9            app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
10            image_store_config = app.config.get_namespace('IMAGE_STORE_')
11
12        The resulting dictionary `image_store_config` would look like::
13
14            {
15                'type': 'fs',
16                'path': '/var/app/images',
17                'base_url': 'http://img.website.com'
18            }
19
20        This is often useful when configuration options map directly to
21        keyword arguments in functions or class constructors.
22
23        :param namespace: a configuration namespace
24        :param lowercase: a flag indicating if the keys of the resulting
25                          dictionary should be lowercase
26        :param trim_namespace: a flag indicating if the keys of the resulting
27                          dictionary should not include the namespace
28
29        .. versionadded:: 0.11
30        """
31        rv = {}
32        for k, v in self.items():
33            if not k.startswith(namespace):
34                continue
35            if trim_namespace:
36                key = k[len(namespace) :]
37            else:
38                key = k
39            if lowercase:
40                key = key.lower()
41            rv[key] = v
42        return rv
            

Path 3: 1 calls (0.25)

'FOO_' (1)

True (1)

False (1)

{'foo_option_1': 'foo option 1', 'foo_option_2': 'foo option 2'} (1)

1def get_namespace(
2        self, namespace: str, lowercase: bool = True, trim_namespace: bool = True
3    ) -> dict[str, t.Any]:
4        """Returns a dictionary containing a subset of configuration options
5        that match the specified namespace/prefix. Example usage::
6
7            app.config['IMAGE_STORE_TYPE'] = 'fs'
8            app.config['IMAGE_STORE_PATH'] = '/var/app/images'
9            app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
10            image_store_config = app.config.get_namespace('IMAGE_STORE_')
11
12        The resulting dictionary `image_store_config` would look like::
13
14            {
15                'type': 'fs',
16                'path': '/var/app/images',
17                'base_url': 'http://img.website.com'
18            }
19
20        This is often useful when configuration options map directly to
21        keyword arguments in functions or class constructors.
22
23        :param namespace: a configuration namespace
24        :param lowercase: a flag indicating if the keys of the resulting
25                          dictionary should be lowercase
26        :param trim_namespace: a flag indicating if the keys of the resulting
27                          dictionary should not include the namespace
28
29        .. versionadded:: 0.11
30        """
31        rv = {}
32        for k, v in self.items():
33            if not k.startswith(namespace):
34                continue
35            if trim_namespace:
36                key = k[len(namespace) :]
37            else:
38                key = k
39            if lowercase:
40                key = key.lower()
41            rv[key] = v
42        return rv
            

Path 4: 1 calls (0.25)

'BAR_' (1)

False (1)

False (1)

{'BAR_STUFF_1': 'bar stuff 1', 'BAR_STUFF_2': 'bar stuff 2'} (1)

1def get_namespace(
2        self, namespace: str, lowercase: bool = True, trim_namespace: bool = True
3    ) -> dict[str, t.Any]:
4        """Returns a dictionary containing a subset of configuration options
5        that match the specified namespace/prefix. Example usage::
6
7            app.config['IMAGE_STORE_TYPE'] = 'fs'
8            app.config['IMAGE_STORE_PATH'] = '/var/app/images'
9            app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
10            image_store_config = app.config.get_namespace('IMAGE_STORE_')
11
12        The resulting dictionary `image_store_config` would look like::
13
14            {
15                'type': 'fs',
16                'path': '/var/app/images',
17                'base_url': 'http://img.website.com'
18            }
19
20        This is often useful when configuration options map directly to
21        keyword arguments in functions or class constructors.
22
23        :param namespace: a configuration namespace
24        :param lowercase: a flag indicating if the keys of the resulting
25                          dictionary should be lowercase
26        :param trim_namespace: a flag indicating if the keys of the resulting
27                          dictionary should not include the namespace
28
29        .. versionadded:: 0.11
30        """
31        rv = {}
32        for k, v in self.items():
33            if not k.startswith(namespace):
34                continue
35            if trim_namespace:
36                key = k[len(namespace) :]
37            else:
38                key = k
39            if lowercase:
40                key = key.lower()
41            rv[key] = v
42        return rv