python 3.x

This commit is contained in:
Adolfo Gómez García 2018-01-16 12:37:56 +01:00
parent c6003536ae
commit 42631f39da
8 changed files with 22 additions and 25 deletions

View File

@ -145,22 +145,16 @@ class Dispatcher(View):
response[k] = val
return response
except RequestError as e:
logger.exception('Error processing request')
return http.HttpResponseBadRequest(six.text_type(e))
except ResponseError as e:
logger.exception('Error processing request')
return http.HttpResponseServerError(six.text_type(e))
except NotSupportedError as e:
logger.exception('Error processing request')
return http.HttpResponseBadRequest(six.text_type(e))
except AccessDenied as e:
logger.exception('Error processing request')
return http.HttpResponseForbidden(six.text_type(e))
except NotFound as e:
logger.exception('Error processing request')
return http.HttpResponseNotFound(six.text_type(e))
except HandlerError as e:
logger.exception('Error processing request')
return http.HttpResponseBadRequest(six.text_type(e))
except Exception as e:
logger.exception('Error processing request')

View File

@ -52,7 +52,6 @@ from uds.models import UserService
logger = logging.getLogger(__name__)
# Actor key, configurable in Security Section of administration interface
actorKey = Config.Config.section(Config.SECURITY_SECTION).value('Master Key',
cryptoManager().uuid(datetime.datetime.now()).replace('-', ''),

View File

@ -63,7 +63,7 @@ class Images(ModelHandler):
]
def beforeSave(self, fields):
fields['data'] = Image.prepareForDb(Image.decode64(fields['data']))
fields['data'] = Image.prepareForDb(Image.decode64(fields['data'].encode('utf8')))
def afterSave(self, item):
# Updates the thumbnail and re-saves it

View File

@ -45,16 +45,16 @@ from uds.core.util.model import processUuid
from uds.models import Tag
import six
from six.moves import filter
import fnmatch
import re
import itertools
import types
import logging
logger = logging.getLogger(__name__)
__updated__ = '2018-01-15'
__updated__ = '2018-01-16'
# a few constants
OVERVIEW = 'overview'
@ -690,7 +690,7 @@ class ModelHandler(BaseModelHandler):
return False
return True
res = list(itertools.ifilter(fltr_function, data))
res = list(filter(fltr_function, data))
logger.debug('After filtering: {}'.format(res))
return res

View File

@ -27,7 +27,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
@ -45,7 +44,7 @@ import ldap
import logging
import six
__updated__ = '2016-04-18'
__updated__ = '2018-01-16'
logger = logging.getLogger(__name__)
@ -131,12 +130,14 @@ class SimpleLDAPAuthenticator(Authenticator):
self._userNameAttr)
def marshal(self):
return '\t'.join(['v1',
self._host, self._port, gui.boolToStr(self._ssl), self._username, self._password, self._timeout,
self._ldapBase, self._userClass, self._groupClass, self._userIdAttr, self._groupIdAttr, self._memberAttr, self._userNameAttr])
return '\t'.join([
'v1',
self._host, self._port, gui.boolToStr(self._ssl), self._username, self._password, self._timeout,
self._ldapBase, self._userClass, self._groupClass, self._userIdAttr, self._groupIdAttr, self._memberAttr, self._userNameAttr
]).encode('utf8')
def unmarshal(self, str_):
data = str_.split('\t')
data = str_.decode('utf8').split('\t')
if data[0] == 'v1':
logger.debug("Data: {0}".format(data[1:]))
self._host, self._port, self._ssl, self._username, self._password, self._timeout, self._ldapBase, self._userClass, self._groupClass, self._userIdAttr, self._groupIdAttr, self._memberAttr, self._userNameAttr = data[1:]

View File

@ -39,7 +39,7 @@ from uds.core.auths.GroupsManager import GroupsManager
from uds.core.auths.Exceptions import InvalidUserException
import logging
__updated__ = '2014-11-11'
__updated__ = '2018-01-16'
logger = logging.getLogger(__name__)
@ -209,14 +209,14 @@ class Authenticator(Module):
This method will allow us to know where to do redirection in case
we need to use callback for authentication
"""
from auth import authCallbackUrl
from .auth import authCallbackUrl
return authCallbackUrl(self.dbAuthenticator())
def infoUrl(self):
"""
Helper method to return info url for this authenticator
"""
from auth import authInfoUrl
from .auth import authInfoUrl
return authInfoUrl(self.dbAuthenticator())
@classmethod

View File

@ -65,6 +65,7 @@ class Config(object):
CHOICE_FIELD = 4 # Choice fields must set its parameters on global "configParams" (better by calling ".setParams" method)
class _Value(object):
def __init__(self, section, key, default='', crypt=False, longText=False, **kwargs):
logger.debug('Var: {} {} KWARGS: {}'.format(section, key, kwargs))
self._type = kwargs.get('type', -1)
@ -171,6 +172,7 @@ class Config(object):
logger.info("Could not save configuration key {0}.{1}".format(self._section.name(), self._key))
class _Section(object):
def __init__(self, sectionName):
self._sectionName = sectionName

View File

@ -31,7 +31,7 @@
from __future__ import unicode_literals
__updated__ = '2015-03-24'
__updated__ = '2018-01-16'
from django.db import models
from django.http import HttpResponse
@ -40,11 +40,11 @@ from uds.models.UUIDModel import UUIDModel
from uds.models.Util import getSqlDatetime
from django.db.models import signals
from uds.core.util import encoders
from PIL import Image as PILImage # @UnresolvedImport
import io
import base64
import logging
logger = logging.getLogger(__name__)
@ -75,11 +75,11 @@ class Image(UUIDModel):
@staticmethod
def encode64(data):
return base64.encodestring(data).replace('\n', '') # Removes \n
return encoders.encode(data, 'base64', asText=True).replace('\n', '') # Removes \n
@staticmethod
def decode64(data64):
return base64.decodestring(data64)
return encoders.decode(data64, 'base64')
@staticmethod
def prepareForDb(data):
@ -190,4 +190,5 @@ class Image(UUIDModel):
logger.debug('Deleted image {0}'.format(toDelete))
signals.pre_delete.connect(Image.beforeDelete, sender=Image)