import os
import sys
import time
+import ldb
+from samba.compat import PY3
import samba.param
+from samba import _glue
+if not PY3:
+ from samba._ldb import Ldb as _Ldb
+else:
+ # samba._ldb is not yet ported to Python 3
+ _Ldb = object
def source_tree_topdir():
return True
-import ldb
-from samba._ldb import Ldb as _Ldb
-
-
class Ldb(_Ldb):
"""Simple Samba-specific LDB subclass that takes care
of setting up the modules dir, credentials pointers, etc.
# TODO set debug
def msg(l, text):
- print text
+ print(text)
#self.set_debug(msg)
self.set_utf8_casefold()
if nosync_p is not None and nosync_p:
flags |= ldb.FLG_NOSYNC
- self.set_create_perms(0600)
+ self.set_create_perms(0o600)
if url is not None:
self.connect(url, flags, options)
try:
res = self.search(base=dn, scope=ldb.SCOPE_SUBTREE, attrs=[],
expression="(|(objectclass=user)(objectclass=computer))")
- except ldb.LdbError, (errno, _):
+ except ldb.LdbError as error:
+ (errno, estr) = error.args
if errno == ldb.ERR_NO_SUCH_OBJECT:
# Ignore no such object errors
return
try:
for msg in res:
self.delete(msg.dn, ["relax:0"])
- except ldb.LdbError, (errno, _):
+ except ldb.LdbError as error:
+ (errno, estr) = error.args
if errno != ldb.ERR_NO_SUCH_OBJECT:
# Ignore no such object errors
raise
[], controls=["show_deleted:0", "show_recycled:0"]):
try:
self.delete(msg.dn, ["relax:0"])
- except ldb.LdbError, (errno, _):
+ except ldb.LdbError as error:
+ (errno, estr) = error.args
if errno != ldb.ERR_NO_SUCH_OBJECT:
# Ignore no such object errors
raise
"@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
try:
self.delete(attr, ["relax:0"])
- except ldb.LdbError, (errno, _):
+ except ldb.LdbError as error:
+ (errno, estr) = error.args
if errno != ldb.ERR_NO_SUCH_OBJECT:
# Ignore missing dn errors
raise
for attr in ["@INDEXLIST", "@ATTRIBUTES"]:
try:
self.delete(attr, ["relax:0"])
- except ldb.LdbError, (errno, _):
+ except ldb.LdbError as error:
+ (errno, estr) = error.args
if errno != ldb.ERR_NO_SUCH_OBJECT:
# Ignore missing dn errors
raise
raise Exception("arcfour_encrypt() requires " +
"python*-crypto or python*-m2crypto or m2crypto")
-import _glue
version = _glue.version
interface_ips = _glue.interface_ips
set_debug_level = _glue.set_debug_level
--- /dev/null
+# module which helps with porting to Python 3
+#
+# Copyright (C) Lumir Balhar <lbalhar@redhat.com> 2017
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""module which helps with porting to Python 3"""
+
+import sys
+
+PY3 = sys.version_info[0] == 3
import os
import ldb
import samba
-import samba.auth
from samba import param
-from samba.samdb import SamDB
from samba import credentials
-import samba.ndr
-import samba.dcerpc.dcerpc
-import samba.dcerpc.base
-import samba.dcerpc.epmapper
from samba.credentials import Credentials
-from samba import gensec
import socket
import struct
import subprocess
import sys
import tempfile
import unittest
+from samba.compat import PY3
+if not PY3:
+ # Py2 only
+ import samba.auth
+ from samba.samdb import SamDB
+ import samba.ndr
+ import samba.dcerpc.dcerpc
+ import samba.dcerpc.base
+ import samba.dcerpc.epmapper
+ from samba import gensec
try:
from unittest import SkipTest
try:
try:
self.setUp()
- except SkipTest, e:
+ except SkipTest as e:
self._addSkip(result, str(e))
return
except KeyboardInterrupt:
try:
testMethod()
ok = True
- except SkipTest, e:
+ except SkipTest as e:
self._addSkip(result, str(e))
return
except self.failureException:
try:
self.tearDown()
- except SkipTest, e:
+ except SkipTest as e:
self._addSkip(result, str(e))
except KeyboardInterrupt:
raise
def delete_force(samdb, dn):
try:
samdb.delete(dn)
- except ldb.LdbError, (num, errstr):
+ except ldb.LdbError as error:
+ (num, errstr) = error.args
assert num == ldb.ERR_NO_SUCH_OBJECT, "ldb.delete() failed: %s" % errstr