mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-13 13:17:54 +03:00
Fixing up things for python 3.x compat
This commit is contained in:
parent
b491c4a2c0
commit
61b8c270c4
server
.pydevproject
src/uds
@ -11,5 +11,5 @@
|
||||
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||
<path>/uds/src</path>
|
||||
</pydev_pathproperty>
|
||||
<pydev_property name="org.python.pydev.PYTHON_ADDITIONAL_GRAMMAR_VALIDATION">3.6</pydev_property>
|
||||
|
||||
</pydev_project>
|
||||
|
@ -123,6 +123,7 @@ class Authenticators(ModelHandler):
|
||||
else:
|
||||
return auth.searchGroups(term)
|
||||
except Exception:
|
||||
logger.exception('Got exception searching:')
|
||||
self.invalidRequestException()
|
||||
|
||||
def test(self, type_):
|
||||
|
@ -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
|
||||
@ -38,15 +37,15 @@ from django.utils.translation import ugettext_noop as _
|
||||
from uds.core.ui.UserInterface import gui
|
||||
from uds.core import auths
|
||||
from uds.core.auths.Exceptions import AuthenticatorException
|
||||
from uds.core.util import tools
|
||||
|
||||
import six
|
||||
import ldap
|
||||
import ldap.filter
|
||||
import re
|
||||
import logging
|
||||
import six
|
||||
|
||||
__updated__ = '2017-10-05'
|
||||
__updated__ = '2018-01-15'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -201,10 +200,10 @@ class RegexLdap(auths.Authenticator):
|
||||
self._host, self._port, gui.boolToStr(self._ssl), self._username, self._password,
|
||||
self._timeout, self._ldapBase, self._userClass, self._userIdAttr,
|
||||
self._groupNameAttr, self._userNameAttr, self._altClass
|
||||
])
|
||||
]).encode('utf8')
|
||||
|
||||
def unmarshal(self, val):
|
||||
data = val.split('\t')
|
||||
data = val.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, \
|
||||
@ -253,7 +252,7 @@ class RegexLdap(auths.Authenticator):
|
||||
l.simple_bind_s(who=username, cred=password)
|
||||
except ldap.LDAPError as e:
|
||||
str_ = _('Ldap connection error: ')
|
||||
if isinstance(e.message, dict):
|
||||
if hasattr(e, 'message') and isinstance(e.message, dict):
|
||||
str_ += ', '.join((e.message.get('info', ''), e.message.get('desc')))
|
||||
else:
|
||||
str_ += six.text_type(e)
|
||||
|
@ -34,7 +34,7 @@ from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
__updated__ = '2014-10-30'
|
||||
__updated__ = '2018-01-15'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -57,7 +57,7 @@ class User(object):
|
||||
If it does not exists, it creates one default from authenticator and
|
||||
returns it.
|
||||
"""
|
||||
from GroupsManager import GroupsManager
|
||||
from .GroupsManager import GroupsManager
|
||||
|
||||
if self._grpsManager is None:
|
||||
self._grpsManager = GroupsManager(self._manager.dbAuthenticator())
|
||||
|
@ -40,8 +40,9 @@ import datetime
|
||||
|
||||
import sys
|
||||
import os
|
||||
import six
|
||||
|
||||
__updated__ = '2017-01-31'
|
||||
__updated__ = '2018-01-15'
|
||||
|
||||
|
||||
class DictAsObj(object):
|
||||
@ -49,6 +50,7 @@ class DictAsObj(object):
|
||||
Returns a mix between a dict and an obj
|
||||
Can be accesses as .xxxx or ['xxx']
|
||||
"""
|
||||
|
||||
def __init__(self, dct=None, **kwargs):
|
||||
if dct is not None:
|
||||
self.__dict__.update(dct)
|
||||
@ -79,6 +81,7 @@ def timestampAsStr(stamp, format_='SHORT_DATETIME_FORMAT'):
|
||||
format_ = formats.get_format(format_)
|
||||
return filters.date(datetime.datetime.fromtimestamp(stamp), format_)
|
||||
|
||||
|
||||
def secondsToString(seconds):
|
||||
seconds = int(seconds)
|
||||
minutes = seconds / 60
|
||||
@ -97,3 +100,21 @@ def secondsToString(seconds):
|
||||
res.append(ugettext('{} seconds').format(seconds))
|
||||
|
||||
return ', '.join(res)
|
||||
|
||||
|
||||
def b2(s):
|
||||
"""
|
||||
Returns a b'' string on python2, or str on python3
|
||||
"""
|
||||
if six.PY2:
|
||||
return s.encode('utf8')
|
||||
return s
|
||||
|
||||
|
||||
def u2(s):
|
||||
"""
|
||||
returns an u'' string on python2, or str on python3
|
||||
"""
|
||||
if six.PY2:
|
||||
return s.decode('utf8')
|
||||
return s
|
||||
|
Loading…
Reference in New Issue
Block a user