Пример #1
0
 def test_as_tuple(self):
     self.assertEqual(tools.as_tuple(None), tuple())
     self.assertEqual(tools.as_tuple(''), tuple())
     self.assertEqual(tools.as_tuple([]), tuple())
     self.assertEqual(tools.as_tuple([1, 2]), (1, 2))
     self.assertEqual(tools.as_tuple(set([1, 2])), (1, 2))
     self.assertEqual(tools.as_tuple({1: 1}), ({1: 1},))
     test = object()
     self.assertEqual(tools.as_tuple(test), (test,))
Пример #2
0
 def test_as_tuple(self):
     self.assertEqual(tools.as_tuple(None), tuple())
     self.assertEqual(tools.as_tuple(''), tuple())
     self.assertEqual(tools.as_tuple([]), tuple())
     self.assertEqual(tools.as_tuple([1, 2]), (1, 2))
     self.assertEqual(tools.as_tuple(set([1, 2])), (1, 2))
     self.assertEqual(tools.as_tuple({1: 1}), ({1: 1}, ))
     test = object()
     self.assertEqual(tools.as_tuple(test), (test, ))
Пример #3
0
    def __new__(mcs, name, bases, params):

        params['meta'] = params.get('meta', MetaOptions())
        cls = super(EmitterMeta, mcs).__new__(mcs, name, bases, params)
        cls.emitters = as_tuple(cls.emitters)
        cls.meta.default_emitter = cls.emitters[0] if cls.emitters else None
        for e in cls.emitters:
            assert issubclass(e, BaseEmitter), "Emitter must be subclass of BaseEmitter"
            cls.meta.emitters_dict[e.media_type] = e
            cls.meta.emitters_types.append(e.media_type)
        return cls
Пример #4
0
    def __new__(mcs, name, bases, params):
        params['meta'] = params.get('meta', MetaOptions())
        cls = super(ParserMeta, mcs).__new__(mcs, name, bases, params)
        cls.parsers = as_tuple(cls.parsers)
        cls.meta.default_parser = cls.parsers[0] if cls.parsers else None

        for p in cls.parsers:
            assert issubclass(p, BaseParser), "Parser must be subclass of BaseParser"
            cls.meta.parsers_dict[p.media_type] = p

        return cls
Пример #5
0
    def __new__(mcs, name, bases, params):
        params['meta'] = params.get('meta', MetaOptions())
        cls = super(ParserMeta, mcs).__new__(mcs, name, bases, params)
        cls.parsers = as_tuple(cls.parsers)
        cls.meta.default_parser = cls.parsers[0] if cls.parsers else None

        for p in cls.parsers:
            assert issubclass(
                p, BaseParser), "Parser must be subclass of BaseParser"
            cls.meta.parsers_dict[p.media_type] = p

        return cls
Пример #6
0
    def __new__(mcs, name, bases, params):

        params['meta'] = params.get('meta', MetaOptions())
        cls = super(EmitterMeta, mcs).__new__(mcs, name, bases, params)
        cls.emitters = as_tuple(cls.emitters)
        cls.meta.default_emitter = cls.emitters[0] if cls.emitters else None
        for e in cls.emitters:
            assert issubclass(
                e, BaseEmitter), "Emitter must be subclass of BaseEmitter"
            cls.meta.emitters_dict[e.media_type] = e
            cls.meta.emitters_types.append(e.media_type)
        return cls
Пример #7
0
def check_authenticators(authenticators):
    authenticators = as_tuple(authenticators)
    for a in authenticators:
        assert issubclass(a, BaseAuthenticator), "Authenticators must be subclasses of BaseAuthenticator"
    return authenticators
Пример #8
0
" Adrest API settings. "
from django.conf import settings

from adrest.utils.tools import as_tuple

# Enable Adrest API logs
ACCESS_LOG = getattr(settings, 'ADREST_ACCESS_LOG', False)

# Auto create adrest access-key for created user
ACCESSKEY = getattr(settings, 'ADREST_ACCESSKEY', 'django.contrib.auth'
                    in settings.INSTALLED_APPS)
AUTO_CREATE_ACCESSKEY = getattr(settings, 'ADREST_AUTO_CREATE_ACCESSKEY',
                                False)

# Max resources per page in list views
LIMIT_PER_PAGE = int(getattr(settings, 'ADREST_LIMIT_PER_PAGE', 50))

# Display django standart technical 500 page
DEBUG = getattr(settings, 'ADREST_DEBUG', False)
MAIL_ERRORS = as_tuple(getattr(settings, 'ADREST_MAIL_ERRORS', 500))

# Limit request number per second from same identifier, null is not limited
THROTTLE_AT = getattr(settings, 'ADREST_THROTTLE_AT', 120)
THROTTLE_TIMEFRAME = getattr(settings, 'ADREST_THROTTLE_TIMEFRAME', 60)

# We do not restrict access for OPTIONS request.
ALLOW_OPTIONS = getattr(settings, 'ADREST_ALLOW_OPTIONS', False)
Пример #9
0
" Adrest API settings. "
from django.conf import settings

from adrest.utils.tools import as_tuple


# Enable Adrest API logs
ACCESS_LOG = getattr(settings, 'ADREST_ACCESS_LOG', False)

# Auto create adrest access-key for created user
ACCESSKEY = getattr(settings, 'ADREST_ACCESSKEY', 'django.contrib.auth' in settings.INSTALLED_APPS)
AUTO_CREATE_ACCESSKEY = getattr(settings, 'ADREST_AUTO_CREATE_ACCESSKEY', False)

# Max resources per page in list views
LIMIT_PER_PAGE = int(getattr(settings, 'ADREST_LIMIT_PER_PAGE', 50))

# Display django standart technical 500 page
DEBUG = getattr(settings, 'ADREST_DEBUG', False)
MAIL_ERRORS = as_tuple(getattr(settings, 'ADREST_MAIL_ERRORS', 500))

# Limit request number per second from same identifier, null is not limited
THROTTLE_AT = getattr(settings, 'ADREST_THROTTLE_AT', 120)
THROTTLE_TIMEFRAME = getattr(settings, 'ADREST_THROTTLE_TIMEFRAME', 60)

# We do not restrict access for OPTIONS request.
ALLOW_OPTIONS = getattr(settings, 'ADREST_ALLOW_OPTIONS', False)