# Buggy code
def Restore(mirror_rp, inc_rpath, target, restore_to_time):
    """Recursively restore mirror and inc_rpath to target at rest_time"""
    MirrorS = mirror_rp.conn.restore.MirrorStruct
    TargetS = target.conn.restore.TargetStruct

    MirrorS.set_mirror_and_rest_times(restore_to_time)
    MirrorS.initialize_rf_cache(mirror_rp, inc_rpath)
    target_iter = TargetS.get_initial_iter(target)
    diff_iter = MirrorS.get_diffs(target_iter)
    TargetS.patch(target, diff_iter)
    MirrorS.close_rf_cache()


# Traceback (TypeError)
$ wget https://git.patrikdufresne.com/pdsl/rdiffweb/raw/master/rdiffweb/tests/testcases.tar.gz
$ tar -zxvf testcases.tar.gz
$ rdiff-backup --version
rdiff-backup 1.9.0b0
$ rdiff-backup --restore-as-of=1414921853 '/testcases/Fichier @ <root>'
Fatal Error: Wrong number of arguments given.
See the rdiff-backup manual page for more information.
root@b94a5e7b3814:/# rdiff-backup --restore-as-of=1414921853 '/testcases/Fichier @ <root>' /tmp
Warning: special_escapes file not found,
will assume need to escape DOS devices and trailing spaces based on file systems.
Exception ''<' not supported between instances of 'QuotedRPath' and 'QuotedRPath'' raised of class '<class 'TypeError'>':
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 390, in error_check_Main
Main(arglist)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 412, in Main
take_action(rps)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 368, in take_action
Restore(rps[0], rps[1], 1)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 713, in Restore
restore_root.new_index(restore_index), inc_rpath, dest_rp, time)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 39, in Restore
TargetS.patch(target, diff_iter)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 331, in patch
for diff in rorpiter.FillInIter(diff_iter, target):
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/rorpiter.py", line 191, in FillInIter
first_rp = next(rpiter)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 279, in get_diffs_from_collated
diff = cls.get_diff(mir_rorp, target_rorp)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 296, in get_diff
file_fp = cls.rf_cache.get_fp(expanded_index, mir_rorp)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 391, in get_fp
self.get_rf(index, mir_rorp), mir_rorp, self.root_rf.mirror_rp)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 371, in get_rf
if not self.add_rfs(index, mir_rorp):
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 417, in add_rfs
new_rfs = list(temp_rf.yield_sub_rfs())
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 589, in yield_sub_rfs
yield self.__class__(mirror_rp, inc_rp, inc_list)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 442, in __init__
self.set_relevant_incs()
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 468, in set_relevant_incs
newer_incs = self.get_newer_incs()
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 494, in get_newer_incs
incpairs.sort()

Traceback (most recent call last):
File "/usr/local/bin/rdiff-backup", line 32, in <module>
rdiff_backup.Main.error_check_Main(sys.argv[1:])
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 390, in error_check_Main
Main(arglist)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 412, in Main
take_action(rps)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 368, in take_action
Restore(rps[0], rps[1], 1)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/Main.py", line 713, in Restore
restore_root.new_index(restore_index), inc_rpath, dest_rp, time)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 39, in Restore
TargetS.patch(target, diff_iter)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 331, in patch
for diff in rorpiter.FillInIter(diff_iter, target):
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/rorpiter.py", line 191, in FillInIter
first_rp = next(rpiter)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 279, in get_diffs_from_collated
diff = cls.get_diff(mir_rorp, target_rorp)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 296, in get_diff
file_fp = cls.rf_cache.get_fp(expanded_index, mir_rorp)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 391, in get_fp
self.get_rf(index, mir_rorp), mir_rorp, self.root_rf.mirror_rp)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 371, in get_rf
if not self.add_rfs(index, mir_rorp):
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 417, in add_rfs
new_rfs = list(temp_rf.yield_sub_rfs())
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 589, in yield_sub_rfs
yield self.__class__(mirror_rp, inc_rp, inc_list)
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 442, in __init__
self.set_relevant_incs()
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 468, in set_relevant_incs
newer_incs = self.get_newer_incs()
File "/usr/local/lib/python3.7/dist-packages/rdiff_backup/restore.py", line 494, in get_newer_incs
incpairs.sort()
TypeError: '<' not supported between instances of 'QuotedRPath' and 'QuotedRPath'

# Fixed code
def Restore(mirror_rp, inc_rpath, target, restore_to_time):
    """Recursively restore mirror and inc_rpath to target at restore_to_time
    in epoch format"""

    # Store references to classes over the connection
    MirrorS = mirror_rp.conn.restore.MirrorStruct
    TargetS = target.conn.restore.TargetStruct

    MirrorS.set_mirror_and_rest_times(restore_to_time)
    MirrorS.initialize_rf_cache(mirror_rp, inc_rpath)
    target_iter = TargetS.get_initial_iter(target)
    diff_iter = MirrorS.get_diffs(target_iter)
    TargetS.patch(target, diff_iter)
    MirrorS.close_rf_cache()