Re: [PATCH 1/1] Allow to fallback to xdrlib if xdrlib3 not available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/02/2025 1:23 pm, Petr Vorel wrote:
On certain environments it might be difficult to install xdrlib3 via pip
(e.g. python 3.11, which is a default on current Tumbleweed).

Fixes: dfb0b07 ("Move to xdrlib3")
Suggested-by: Michael Moese <mmoese@xxxxxxxx>
Signed-off-by: Petr Vorel <pvorel@xxxxxxx>
---
Hi,

I admit it would be safer to check if python is really < 3.13.

Kind regards,
Petr

  README                                | 2 ++
  nfs4.0/lib/rpc/rpc.py                 | 6 +++++-
  nfs4.0/lib/rpc/rpcsec/sec_auth_sys.py | 7 ++++++-
  nfs4.0/nfs4lib.py                     | 6 +++++-
  nfs4.0/nfs4server.py                  | 6 +++++-
  rpc/security.py                       | 6 +++++-
  xdr/xdrgen.py                         | 9 +++++++--
  7 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/README b/README
index 8c3ac27..d5214b4 100644
--- a/README
+++ b/README
@@ -19,6 +19,8 @@ python3-standard-xdrlib) or you may install it via pip:
pip install xdrlib3 +If xdrlib3 is not available fallback to old xdrlib (useful for python < 3.13).

It sounds a little like the above is an instruction for the user; if you don't mind I'll fix this up, adding "the code will fallback…", just to make it obvious?

Thanks for the fix Petr, I'll get this in today.

cheers,
c.



+
  You can prepare both versions for use with
./setup.py build
diff --git a/nfs4.0/lib/rpc/rpc.py b/nfs4.0/lib/rpc/rpc.py
index 4751790..7a80241 100644
--- a/nfs4.0/lib/rpc/rpc.py
+++ b/nfs4.0/lib/rpc/rpc.py
@@ -9,12 +9,16 @@
from __future__ import absolute_import
  import struct
-import xdrlib3 as xdrlib
  import socket
  import select
  import threading
  import errno
+try:
+    import xdrlib3 as xdrlib
+except:
+    import xdrlib
+
  from rpc.rpc_const import *
  from rpc.rpc_type import *
  import rpc.rpc_pack as rpc_pack
diff --git a/nfs4.0/lib/rpc/rpcsec/sec_auth_sys.py b/nfs4.0/lib/rpc/rpcsec/sec_auth_sys.py
index 2581a1e..41c6d54 100644
--- a/nfs4.0/lib/rpc/rpcsec/sec_auth_sys.py
+++ b/nfs4.0/lib/rpc/rpcsec/sec_auth_sys.py
@@ -1,7 +1,12 @@
  from .base import SecFlavor, SecError
  from rpc.rpc_const import AUTH_SYS
  from rpc.rpc_type import opaque_auth
-from xdrlib3 import Packer, Error
+import struct
+
+try:
+    from xdrlib3 import Packer, Error
+except:
+    from xdrlib import Packer, Error
class SecAuthSys(SecFlavor):
      # XXX need better defaults
diff --git a/nfs4.0/nfs4lib.py b/nfs4.0/nfs4lib.py
index 2337d8c..92b3c11 100644
--- a/nfs4.0/nfs4lib.py
+++ b/nfs4.0/nfs4lib.py
@@ -41,9 +41,13 @@ import xdrdef.nfs4_const as nfs4_const
  from  xdrdef.nfs4_const import *
  import xdrdef.nfs4_type as nfs4_type
  from xdrdef.nfs4_type import *
-from xdrlib3 import Error as XDRError
  import xdrdef.nfs4_pack as nfs4_pack
+try:
+    from xdrlib3 import Error as XDRError
+except:
+    from xdrlib import Error as XDRError
+
  import nfs_ops
  op4 = nfs_ops.NFS4ops()
diff --git a/nfs4.0/nfs4server.py b/nfs4.0/nfs4server.py
index 10bf28e..e26cecd 100755
--- a/nfs4.0/nfs4server.py
+++ b/nfs4.0/nfs4server.py
@@ -34,7 +34,11 @@ import time, StringIO, random, traceback, codecs
  import StringIO
  import nfs4state
  from nfs4state import NFS4Error, printverf
-from xdrlib3 import Error as XDRError
+
+try:
+    from xdrlib3 import Error as XDRError
+except:
+    from xdrlib import Error as XDRError
unacceptable_names = [ "", ".", ".." ]
  unacceptable_characters = [ "/", "~", "#", ]
diff --git a/rpc/security.py b/rpc/security.py
index 789280c..79e746b 100644
--- a/rpc/security.py
+++ b/rpc/security.py
@@ -3,7 +3,6 @@ from .rpc_const import AUTH_NONE, AUTH_SYS, RPCSEC_GSS, SUCCESS, CALL, \
  from .rpc_type import opaque_auth, authsys_parms
  from .rpc_pack import RPCPacker, RPCUnpacker
  from .gss_pack import GSSPacker, GSSUnpacker
-from xdrlib3 import Packer, Unpacker
  from . import rpclib
  from .gss_const import *
  from . import gss_type
@@ -17,6 +16,11 @@ except ImportError:
  import threading
  import logging
+try:
+    from xdrlib3 import Packer, Unpacker
+except:
+    from xdrlib import Packer, Unpacker
+
  log_gss = logging.getLogger("rpc.sec.gss")
  log_gss.setLevel(logging.INFO)
diff --git a/xdr/xdrgen.py b/xdr/xdrgen.py
index f802ba8..970ae9d 100755
--- a/xdr/xdrgen.py
+++ b/xdr/xdrgen.py
@@ -1357,8 +1357,13 @@ pack_header = """\
  import sys,os
  from . import %s as const
  from . import %s as types
-import xdrlib3 as xdrlib
-from xdrlib3 import Error as XDRError
+
+try:
+    import xdrlib3 as xdrlib
+    from xdrlib3 import Error as XDRError
+except:
+    import xdrlib as xdrlib
+    from xdrlib import Error as XDRError
class nullclass(object):
      pass






[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux