forked from shaba/openuds
Fixed "has_key" and other issues
This commit is contained in:
parent
917dd33349
commit
a06fc617f0
@ -111,7 +111,7 @@ class Module(UserInterface, Environmentable, Serializable):
|
||||
iconFile: typing.ClassVar[str] = 'base.png' # This is expected to be png, use this format always
|
||||
|
||||
# Not defined, but declared. If module is groupable, this value will contain to which group belongs
|
||||
group: str
|
||||
group: typing.ClassVar[str]
|
||||
|
||||
class ValidationException(Exception):
|
||||
"""
|
||||
|
@ -146,7 +146,7 @@ class ServiceProvider(Module):
|
||||
return _type
|
||||
return None
|
||||
|
||||
def __init__(self, environment: Environment, values: Module.ValuesType = None, uuid: typing.Optional[str] = None):
|
||||
def __init__(self, environment: Environment, values: 'Module.ValuesType' = None, uuid: typing.Optional[str] = None):
|
||||
"""
|
||||
Do not forget to invoke this in your derived class using "super(self.__class__, self).__init__(environment, values)"
|
||||
if you override this method. Better is to provide an "__initialize__" method, that will be invoked
|
||||
@ -157,7 +157,7 @@ class ServiceProvider(Module):
|
||||
super().__init__(environment, values, uuid=uuid)
|
||||
self.initialize(values)
|
||||
|
||||
def initialize(self, values: typing.Optional[Module.ValuesType]) -> None:
|
||||
def initialize(self, values: 'Module.ValuesType') -> None:
|
||||
"""
|
||||
This method will be invoked from __init__ constructor.
|
||||
This is provided so you don't have to provide your own __init__ method,
|
||||
|
@ -31,9 +31,9 @@
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from functools import wraps
|
||||
import typing
|
||||
import logging
|
||||
import inspect
|
||||
import typing
|
||||
|
||||
from uds.core.util.html import checkBrowser
|
||||
from uds.web.util import errors
|
||||
@ -41,29 +41,28 @@ from uds.web.util import errors
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
RT = typing.TypeVar('RT')
|
||||
|
||||
# Decorator that protects pages that needs at least a browser version
|
||||
# Default is to deny IE < 9
|
||||
def denyBrowsers(
|
||||
browsers: typing.Optional[typing.List[str]] = None,
|
||||
errorResponse: typing.Callable = lambda request: errors.errorView(request, errors.BROWSER_NOT_SUPPORTED)
|
||||
):
|
||||
) -> typing.Callable[[typing.Callable[..., RT]], typing.Callable[..., RT]]:
|
||||
"""
|
||||
Decorator to set protection to access page
|
||||
Look for samples at uds.core.web.views
|
||||
"""
|
||||
|
||||
if browsers is None:
|
||||
browsers = ['ie<9']
|
||||
|
||||
def wrap(view_func):
|
||||
denied: typing.List[str] = browsers or ['ie<9']
|
||||
|
||||
def wrap(view_func: typing.Callable[..., RT]) -> typing.Callable[..., RT]:
|
||||
@wraps(view_func)
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
def _wrapped_view(request, *args, **kwargs) -> RT:
|
||||
"""
|
||||
Wrapped function for decorator
|
||||
"""
|
||||
for b in browsers:
|
||||
for b in denied:
|
||||
if checkBrowser(request, b):
|
||||
return errorResponse(request)
|
||||
|
||||
@ -74,13 +73,13 @@ def denyBrowsers(
|
||||
return wrap
|
||||
|
||||
|
||||
def deprecated(func):
|
||||
def deprecated(func: typing.Callable[..., RT]) -> typing.Callable[..., RT]:
|
||||
"""This is a decorator which can be used to mark functions
|
||||
as deprecated. It will result in a warning being emitted
|
||||
when the function is used."""
|
||||
|
||||
@wraps(func)
|
||||
def new_func(*args, **kwargs):
|
||||
def new_func(*args, **kwargs) -> RT:
|
||||
try:
|
||||
caller = inspect.stack()[1]
|
||||
logger.warning('Call to deprecated function %s from %s:%s.', func.__name__, caller[1], caller[2])
|
||||
@ -101,7 +100,7 @@ def allowCache(
|
||||
cacheTimeout: int,
|
||||
cachingArgs: typing.Optional[typing.Union[typing.List[int], int]] = None,
|
||||
cachingKeyFnc: typing.Optional[typing.Callable[[typing.Any], str]] = None
|
||||
):
|
||||
) -> typing.Callable[[typing.Callable[..., RT]], typing.Callable[..., RT]]:
|
||||
"""Decorator that give us a "quick& clean" caching feature on service providers.
|
||||
|
||||
Note: This decorator is intended ONLY for service providers
|
||||
@ -111,30 +110,29 @@ def allowCache(
|
||||
:param cachingArgs: The caching args. Can be a single integer or a list.
|
||||
First arg (self) is 0, so normally cachingArgs are 1, or [1,2,..]
|
||||
"""
|
||||
if not cachingKeyFnc:
|
||||
cachingKeyFnc = lambda x: ''
|
||||
keyFnc = cachingKeyFnc or (lambda x: '')
|
||||
|
||||
def allowCacheDecorator(fnc: typing.Callable):
|
||||
def allowCacheDecorator(fnc: typing.Callable[..., RT]) -> typing.Callable[..., RT]:
|
||||
@wraps(fnc)
|
||||
def wrapper(*args, **kwargs):
|
||||
if cachingArgs is not None:
|
||||
def wrapper(*args, **kwargs) -> RT:
|
||||
if cachingArgs:
|
||||
if isinstance(cachingArgs, (list, tuple)):
|
||||
argList = [args[i] if i < len(args) else '' for i in cachingArgs]
|
||||
else:
|
||||
argList = args[cachingArgs] if cachingArgs < len(args) else ''
|
||||
cacheKey = '{}-{}.{}'.format(cachePrefix, cachingKeyFnc(args[0]), argList)
|
||||
cacheKey = '{}-{}.{}'.format(cachePrefix, keyFnc(args[0]), argList)
|
||||
else:
|
||||
cacheKey = '{}-{}.gen'.format(cachePrefix, cachingKeyFnc(args[0]))
|
||||
cacheKey = '{}-{}.gen'.format(cachePrefix, keyFnc(args[0]))
|
||||
|
||||
data = None
|
||||
data: typing.Any = None
|
||||
if kwargs.get('force', False) is False and args[0].cache is not None:
|
||||
data = args[0].cache.get(cacheKey)
|
||||
|
||||
if kwargs.has_key('force'):
|
||||
if 'force' in kwargs:
|
||||
# Remove force key
|
||||
del kwargs['force']
|
||||
|
||||
if data is None:
|
||||
if data is None: # Not in cache...
|
||||
data = fnc(*args, **kwargs)
|
||||
try:
|
||||
# Maybe returned data is not serializable. In that case, cache will fail but no harm is done with this
|
||||
|
@ -85,9 +85,6 @@ class CaseInsensitiveDict(dict):
|
||||
def __contains__(self, key):
|
||||
return super(CaseInsensitiveDict, self).__contains__(self.__class__._k(key))
|
||||
|
||||
def has_key(self, key):
|
||||
return super(CaseInsensitiveDict, self).has_key(self.__class__._k(key))
|
||||
|
||||
def pop(self, key, *args, **kwargs):
|
||||
return super(CaseInsensitiveDict, self).pop(self.__class__._k(key), *args, **kwargs)
|
||||
|
||||
|
@ -179,11 +179,12 @@ class Client: # pylint: disable=too-many-public-methods
|
||||
self._authUrl += '/'
|
||||
|
||||
def _getEndpointFor(self, type_: str) -> str: # If no region is indicatad, first endpoint is returned
|
||||
for i in self._catalog:
|
||||
if i['type'] == type_:
|
||||
for j in i['endpoints']:
|
||||
if j['interface'] == self._access and (self._region is None or j['region'] == self._region):
|
||||
return j['url']
|
||||
if not self._catalog:
|
||||
raise Exception('No catalog for endpoints')
|
||||
for i in filter(lambda v: v['type'] == type_, self._catalog):
|
||||
for j in filter(lambda v: v['interface'] == self._access, i['endpoints']):
|
||||
if not self._region or j['region'] == self._region:
|
||||
return j['url']
|
||||
raise Exception('No endpoint url found')
|
||||
|
||||
def _requestHeaders(self) -> typing.Dict[str, str]:
|
||||
|
File diff suppressed because one or more lines are too long
@ -92,6 +92,6 @@
|
||||
</svg>
|
||||
</div>
|
||||
</uds-root>
|
||||
<script src="/uds/res/admin/runtime.js?stamp=1568977772"></script><script src="/uds/res/admin/polyfills-es5.js?stamp=1568977772" nomodule></script><script src="/uds/res/admin/polyfills.js?stamp=1568977772"></script><script src="/uds/res/admin/main.js?stamp=1568977772"></script></body>
|
||||
<script src="/uds/res/admin/runtime.js?stamp=1569311997"></script><script src="/uds/res/admin/polyfills-es5.js?stamp=1569311997" nomodule></script><script src="/uds/res/admin/polyfills.js?stamp=1569311997"></script><script src="/uds/res/admin/main.js?stamp=1569311997"></script></body>
|
||||
|
||||
</html>
|
||||
|
@ -35,7 +35,6 @@ import typing
|
||||
|
||||
from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.util import os_detector as OsDetector
|
||||
from uds.core.util import tools
|
||||
from .x2go_base import BaseX2GOTransport
|
||||
from . import x2go_file
|
||||
|
||||
|
@ -61,7 +61,7 @@ ERR_USER_SERVICE_NOT_FOUND = 7
|
||||
AUTHENTICATOR_NOT_FOUND = 8
|
||||
INVALID_CALLBACK = 9
|
||||
INVALID_REQUEST = 10
|
||||
BROWSER_NOT_SUPPORTED = 11,
|
||||
BROWSER_NOT_SUPPORTED = 11
|
||||
SERVICE_IN_MAINTENANCE = 12
|
||||
SERVICE_NOT_READY = 13
|
||||
SERVICE_IN_PREPARATION = 14
|
||||
|
Loading…
Reference in New Issue
Block a user