Merge pull request #740 from tahoe-lafs/3340-unused-code-in-util

Delete some dead code.

Fixes: ticket:3340
This commit is contained in:
Jean-Paul Calderone 2020-07-15 20:08:41 -04:00 committed by GitHub
commit c493396148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 99 deletions

0
newsfragments/3340.other Normal file
View File

View File

@ -1,6 +1,6 @@
from __future__ import print_function from __future__ import print_function
import os, signal, sys, time import os, signal, time
from random import randrange from random import randrange
from six.moves import StringIO from six.moves import StringIO
@ -8,7 +8,6 @@ from twisted.internet import reactor, defer
from twisted.python import failure from twisted.python import failure
from twisted.trial import unittest from twisted.trial import unittest
from allmydata.util import fileutil, log
from ..util.assertutil import precondition from ..util.assertutil import precondition
from allmydata.util.encodingutil import (unicode_platform, get_filesystem_encoding, from allmydata.util.encodingutil import (unicode_platform, get_filesystem_encoding,
get_io_encoding) get_io_encoding)
@ -89,39 +88,6 @@ class ReallyEqualMixin(object):
self.assertEqual(type(a), type(b), "a :: %r, b :: %r, %r" % (a, b, msg)) self.assertEqual(type(a), type(b), "a :: %r, b :: %r, %r" % (a, b, msg))
class NonASCIIPathMixin(object):
def mkdir_nonascii(self, dirpath):
# Kludge to work around the fact that buildbot can't remove a directory tree that has
# any non-ASCII directory names on Windows. (#1472)
if sys.platform == "win32":
def _cleanup():
try:
fileutil.rm_dir(dirpath)
finally:
if os.path.exists(dirpath):
msg = ("We were unable to delete a non-ASCII directory %r created by the test. "
"This is liable to cause failures on future builds." % (dirpath,))
print(msg)
log.err(msg)
self.addCleanup(_cleanup)
os.mkdir(dirpath)
def unicode_or_fallback(self, unicode_name, fallback_name, io_as_well=False):
if not unicode_platform():
try:
unicode_name.encode(get_filesystem_encoding())
except UnicodeEncodeError:
return fallback_name
if io_as_well:
try:
unicode_name.encode(get_io_encoding())
except UnicodeEncodeError:
return fallback_name
return unicode_name
class SignalMixin(object): class SignalMixin(object):
# This class is necessary for any code which wants to use Processes # This class is necessary for any code which wants to use Processes
# outside the usual reactor.run() environment. It is copied from # outside the usual reactor.run() environment. It is copied from

View File

@ -83,7 +83,7 @@ BASECONFIG_I = ("[client]\n"
"introducer.furl = %s\n" "introducer.furl = %s\n"
) )
class Basic(testutil.ReallyEqualMixin, testutil.NonASCIIPathMixin, unittest.TestCase): class Basic(testutil.ReallyEqualMixin, unittest.TestCase):
def test_loadable(self): def test_loadable(self):
basedir = "test_client.Basic.test_loadable" basedir = "test_client.Basic.test_loadable"
os.mkdir(basedir) os.mkdir(basedir)

View File

@ -12,7 +12,7 @@ from errno import ENOENT
if sys.platform == "win32": if sys.platform == "win32":
from ctypes import WINFUNCTYPE, WinError, windll, POINTER, byref, c_ulonglong, \ from ctypes import WINFUNCTYPE, WinError, windll, POINTER, byref, c_ulonglong, \
create_unicode_buffer, get_last_error create_unicode_buffer, get_last_error
from ctypes.wintypes import BOOL, DWORD, LPCWSTR, LPWSTR, LPVOID, HANDLE from ctypes.wintypes import BOOL, DWORD, LPCWSTR, LPWSTR, LPVOID
from twisted.python import log from twisted.python import log
@ -538,60 +538,6 @@ def get_available_space(whichdir, reserved_space):
return 0 return 0
if sys.platform == "win32":
# <http://msdn.microsoft.com/en-us/library/aa363858%28v=vs.85%29.aspx>
CreateFileW = WINFUNCTYPE(
HANDLE, LPCWSTR, DWORD, DWORD, LPVOID, DWORD, DWORD, HANDLE,
use_last_error=True
)(("CreateFileW", windll.kernel32))
GENERIC_WRITE = 0x40000000
FILE_SHARE_READ = 0x00000001
FILE_SHARE_WRITE = 0x00000002
OPEN_EXISTING = 3
INVALID_HANDLE_VALUE = 0xFFFFFFFF
# <http://msdn.microsoft.com/en-us/library/aa364439%28v=vs.85%29.aspx>
FlushFileBuffers = WINFUNCTYPE(
BOOL, HANDLE,
use_last_error=True
)(("FlushFileBuffers", windll.kernel32))
# <http://msdn.microsoft.com/en-us/library/ms724211%28v=vs.85%29.aspx>
CloseHandle = WINFUNCTYPE(
BOOL, HANDLE,
use_last_error=True
)(("CloseHandle", windll.kernel32))
# <http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/4465cafb-f4ed-434f-89d8-c85ced6ffaa8/>
def flush_volume(path):
abspath = os.path.realpath(path)
if abspath.startswith("\\\\?\\"):
abspath = abspath[4 :]
drive = os.path.splitdrive(abspath)[0]
print("flushing %r" % (drive,))
hVolume = CreateFileW(u"\\\\.\\" + drive,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
None,
OPEN_EXISTING,
0,
None
)
if hVolume == INVALID_HANDLE_VALUE:
raise WinError(get_last_error())
if FlushFileBuffers(hVolume) == 0:
raise WinError(get_last_error())
CloseHandle(hVolume)
else:
def flush_volume(path):
# use sync()?
pass
class ConflictError(Exception): class ConflictError(Exception):
pass pass

View File

@ -1,7 +1,7 @@
from twisted.internet import address from twisted.internet import address
from foolscap.api import Violation, RemoteException, DeadReferenceError, \ from foolscap.api import Violation, RemoteException, SturdyRef
SturdyRef
def add_version_to_remote_reference(rref, default): def add_version_to_remote_reference(rref, default):
"""I try to add a .version attribute to the given RemoteReference. I call """I try to add a .version attribute to the given RemoteReference. I call
@ -19,12 +19,6 @@ def add_version_to_remote_reference(rref, default):
d.addCallbacks(_got_version, _no_get_version) d.addCallbacks(_got_version, _no_get_version)
return d return d
def trap_and_discard(f, *errorTypes):
f.trap(*errorTypes)
def trap_deadref(f):
return trap_and_discard(f, DeadReferenceError)
def connection_hints_for_furl(furl): def connection_hints_for_furl(furl):
hints = [] hints = []