]> arthur.barton.de Git - bup.git/blobdiff - cmd/ftp-cmd.py
Prevent Python 3 from interfering with argv bytes
[bup.git] / cmd / ftp-cmd.py
index 8bd57b6d81accff181dde968af13f865f3979348..08462d9d4c94c46b503e085475a2a10f51dbdc0c 100755 (executable)
@@ -5,7 +5,7 @@ exec "$bup_python" "$0" ${1+"$@"}
 """
 # end of bup preamble
 
-from __future__ import absolute_import
+from __future__ import absolute_import, print_function
 import sys, os, stat, fnmatch
 
 from bup import options, git, shquote, ls, vfs
@@ -39,7 +39,7 @@ def inputiter():
             try:
                 yield raw_input('bup> ')
             except EOFError:
-                print ''  # Clear the line for the terminal's next prompt
+                print()  # Clear the line for the terminal's next prompt
                 break
     else:
         for line in sys.stdin:
@@ -60,51 +60,12 @@ def _completer_get_subs(repo, line):
     return dir, name, qtype, lastword, subs
 
 
-def find_readline_lib():
-    """Return the name (and possibly the full path) of the readline library
-    linked to the given readline module.
-    """
-    import readline
-    f = open(readline.__file__, "rb")
-    try:
-        data = f.read()
-    finally:
-        f.close()
-    import re
-    m = re.search('\0([^\0]*libreadline[^\0]*)\0', data)
-    if m:
-        return m.group(1)
-    return None
-
-
-def init_readline_vars():
-    """Work around trailing space automatically inserted by readline.
-    See http://bugs.python.org/issue5833"""
-    try:
-        import ctypes
-    except ImportError:
-        # python before 2.5 didn't have the ctypes module; but those
-        # old systems probably also didn't have this readline bug, so
-        # just ignore it.
-        return
-    lib_name = find_readline_lib()
-    if lib_name is not None:
-        lib = ctypes.cdll.LoadLibrary(lib_name)
-        global rl_completion_suppress_append
-        rl_completion_suppress_append = ctypes.c_int.in_dll(lib,
-                                    "rl_completion_suppress_append")
-
-
-rl_completion_suppress_append = None
 _last_line = None
 _last_res = None
 def completer(text, iteration):
     global repo
     global _last_line
     global _last_res
-    global rl_completion_suppress_append
-    if rl_completion_suppress_append is not None:
-        rl_completion_suppress_append.value = 1
     try:
         line = readline.get_line_buffer()[:readline.get_endidx()]
         if _last_line != line:
@@ -162,7 +123,6 @@ else:
             # MacOS uses a slightly incompatible clone of libreadline
             readline.parse_and_bind('bind ^I rl_complete')
         readline.parse_and_bind('tab: complete')
-        init_readline_vars()
     lines = inputiter()
 
 for line in lines:
@@ -190,7 +150,7 @@ for line in lines:
         elif cmd == 'pwd':
             if len(pwd) == 1:
                 sys.stdout.write('/')
-            print '/'.join(name for name, item in pwd)
+            print('/'.join(name for name, item in pwd))
         elif cmd == 'cat':
             for parm in words[1:]:
                 res = vfs.resolve(repo, parm, parent=pwd)