Merge lp:~gz/brz/farewell_98 into lp:brz

Proposed by Martin Packman
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~gz/brz/farewell_98
Merge into: lp:brz
Diff against target: 400 lines (+12/-207)
6 files modified
breezy/lock.py (+3/-15)
breezy/osutils.py (+2/-37)
breezy/tests/test_osutils.py (+0/-29)
breezy/tests/test_urlutils.py (+0/-3)
breezy/tests/test_win32utils.py (+1/-46)
breezy/win32utils.py (+6/-77)
To merge this branch: bzr merge lp:~gz/brz/farewell_98
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+325130@code.launchpad.net

Commit message

Remove old win32 platform code

Description of the change

Remove old and unneeded win32 platform code.

Doesn't go as far as ripping out pywintypes yet, can tackle that later.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/lock.py'
2--- breezy/lock.py 2017-05-22 00:56:52 +0000
3+++ breezy/lock.py 2017-06-05 23:56:54 +0000
4@@ -345,12 +345,7 @@
5
6
7 if have_pywin32 and sys.platform == 'win32':
8- if os.path.supports_unicode_filenames:
9- # for Windows NT/2K/XP/etc
10- win32file_CreateFile = win32file.CreateFileW
11- else:
12- # for Windows 98
13- win32file_CreateFile = win32file.CreateFile
14+ win32file_CreateFile = win32file.CreateFileW
15
16 class _w32c_FileLock(_OSLock):
17
18@@ -423,19 +418,12 @@
19 from ctypes.wintypes import DWORD, LPCSTR, LPCWSTR
20 LPSECURITY_ATTRIBUTES = ctypes.c_void_p # used as NULL no need to declare
21 HANDLE = ctypes.c_int # rather than unsigned as in ctypes.wintypes
22- if os.path.supports_unicode_filenames:
23- _function_name = "CreateFileW"
24- LPTSTR = LPCWSTR
25- else:
26- _function_name = "CreateFileA"
27- class LPTSTR(LPCSTR):
28- def __new__(cls, obj):
29- return LPCSTR.__new__(cls, obj.encode("mbcs"))
30+ _function_name = "CreateFileW"
31
32 # CreateFile <http://msdn.microsoft.com/en-us/library/aa363858.aspx>
33 _CreateFile = ctypes.WINFUNCTYPE(
34 HANDLE, # return value
35- LPTSTR, # lpFileName
36+ LPWSTR, # lpFileName
37 DWORD, # dwDesiredAccess
38 DWORD, # dwShareMode
39 LPSECURITY_ATTRIBUTES, # lpSecurityAttributes
40
41=== modified file 'breezy/osutils.py'
42--- breezy/osutils.py 2017-06-02 23:43:00 +0000
43+++ breezy/osutils.py 2017-06-05 23:56:54 +0000
44@@ -375,33 +375,6 @@
45 return _win32_fixdrive(ntpath.abspath(unicode(path)).replace('\\', '/'))
46
47
48-def _win98_abspath(path):
49- """Return the absolute version of a path.
50- Windows 98 safe implementation (python reimplementation
51- of Win32 API function GetFullPathNameW)
52- """
53- # Corner cases:
54- # C:\path => C:/path
55- # C:/path => C:/path
56- # \\HOST\path => //HOST/path
57- # //HOST/path => //HOST/path
58- # path => C:/cwd/path
59- # /path => C:/path
60- path = unicode(path)
61- # check for absolute path
62- drive = ntpath.splitdrive(path)[0]
63- if drive == '' and path[:2] not in('//','\\\\'):
64- cwd = _getcwd()
65- # we cannot simply os.path.join cwd and path
66- # because os.path.join('C:','/path') produce '/path'
67- # and this is incorrect
68- if path[:1] in ('/','\\'):
69- cwd = ntpath.splitdrive(cwd)[0]
70- path = path[1:]
71- path = cwd + '\\' + path
72- return _win32_fixdrive(ntpath.normpath(path).replace('\\', '/'))
73-
74-
75 def _win32_realpath(path):
76 # Real ntpath.realpath doesn't have a problem with a unicode cwd
77 return _win32_fixdrive(ntpath.realpath(unicode(path)).replace('\\', '/'))
78@@ -503,10 +476,7 @@
79
80
81 if sys.platform == 'win32':
82- if win32utils.winver == 'Windows 98':
83- abspath = _win98_abspath
84- else:
85- abspath = _win32_abspath
86+ abspath = _win32_abspath
87 realpath = _win32_realpath
88 pathjoin = _win32_pathjoin
89 normpath = _win32_normpath
90@@ -1836,12 +1806,7 @@
91 """
92 global _selected_dir_reader
93 if _selected_dir_reader is None:
94- if sys.platform == "win32" and win32utils.winver == 'Windows NT':
95- # Win98 doesn't have unicode apis like FindFirstFileW
96- # TODO: We possibly could support Win98 by falling back to the
97- # original FindFirstFile, and using TCHAR instead of WCHAR,
98- # but that gets a bit tricky, and requires custom compiling
99- # for win98 anyway.
100+ if sys.platform == "win32":
101 try:
102 from ._walkdirs_win32 import Win32ReadDir
103 _selected_dir_reader = Win32ReadDir()
104
105=== modified file 'breezy/tests/test_osutils.py'
106--- breezy/tests/test_osutils.py 2017-05-30 21:00:24 +0000
107+++ breezy/tests/test_osutils.py 2017-06-05 23:56:54 +0000
108@@ -971,23 +971,6 @@
109 self.assertEqual('H:/foo', osutils._win32_fixdrive('H:/foo'))
110 self.assertEqual('C:\\foo', osutils._win32_fixdrive('c:\\foo'))
111
112- def test_win98_abspath(self):
113- self.requireFeature(features.win32_feature)
114- # absolute path
115- self.assertEqual('C:/foo', osutils._win98_abspath('C:\\foo'))
116- self.assertEqual('C:/foo', osutils._win98_abspath('C:/foo'))
117- # UNC path
118- self.assertEqual('//HOST/path', osutils._win98_abspath(r'\\HOST\path'))
119- self.assertEqual('//HOST/path', osutils._win98_abspath('//HOST/path'))
120- # relative path
121- cwd = osutils.getcwd().rstrip('/')
122- drive = osutils.ntpath.splitdrive(cwd)[0]
123- self.assertEqual(cwd+'/path', osutils._win98_abspath('path'))
124- self.assertEqual(drive+'/path', osutils._win98_abspath('/path'))
125- # unicode path
126- u = u'\u1234'
127- self.assertEqual(cwd+'/'+u, osutils._win98_abspath(u))
128-
129
130 class TestWin32FuncsDirs(tests.TestCaseInTempDir):
131 """Test win32 functions that create files."""
132@@ -1230,7 +1213,6 @@
133 self.skipTest("Lack filesystem that preserves arbitrary bytes")
134
135 self._save_platform_info()
136- win32utils.winver = None # Avoid the win32 detection code
137 osutils._fs_enc = 'UTF-8'
138
139 # this should raise on error
140@@ -1295,7 +1277,6 @@
141 dirblock[:] = new_dirblock
142
143 def _save_platform_info(self):
144- self.overrideAttr(win32utils, 'winver')
145 self.overrideAttr(osutils, '_fs_enc')
146 self.overrideAttr(osutils, '_selected_dir_reader')
147
148@@ -1310,7 +1291,6 @@
149 def test_force_walkdirs_utf8_fs_utf8(self):
150 self.requireFeature(UTF8DirReaderFeature)
151 self._save_platform_info()
152- win32utils.winver = None # Avoid the win32 detection code
153 osutils._fs_enc = 'utf-8'
154 self.assertDirReaderIs(
155 UTF8DirReaderFeature.module.UTF8DirReader)
156@@ -1318,14 +1298,12 @@
157 def test_force_walkdirs_utf8_fs_ascii(self):
158 self.requireFeature(UTF8DirReaderFeature)
159 self._save_platform_info()
160- win32utils.winver = None # Avoid the win32 detection code
161 osutils._fs_enc = 'ascii'
162 self.assertDirReaderIs(
163 UTF8DirReaderFeature.module.UTF8DirReader)
164
165 def test_force_walkdirs_utf8_fs_latin1(self):
166 self._save_platform_info()
167- win32utils.winver = None # Avoid the win32 detection code
168 osutils._fs_enc = 'iso-8859-1'
169 self.assertDirReaderIs(osutils.UnicodeDirReader)
170
171@@ -1333,16 +1311,9 @@
172 # Disabled because the thunk of the whole walkdirs api is disabled.
173 self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
174 self._save_platform_info()
175- win32utils.winver = 'Windows NT'
176 from .._walkdirs_win32 import Win32ReadDir
177 self.assertDirReaderIs(Win32ReadDir)
178
179- def test_force_walkdirs_utf8_98(self):
180- self.requireFeature(test__walkdirs_win32.win32_readdir_feature)
181- self._save_platform_info()
182- win32utils.winver = 'Windows 98'
183- self.assertDirReaderIs(osutils.UnicodeDirReader)
184-
185 def test_unicode_walkdirs(self):
186 """Walkdirs should always return unicode paths."""
187 self.requireFeature(features.UnicodeFilenameFeature)
188
189=== modified file 'breezy/tests/test_urlutils.py'
190--- breezy/tests/test_urlutils.py 2017-05-22 00:56:52 +0000
191+++ breezy/tests/test_urlutils.py 2017-06-05 23:56:54 +0000
192@@ -737,9 +737,6 @@
193 self.assertEndsWith(url, '/mytest')
194
195 def test_non_ascii(self):
196- if win32utils.winver == 'Windows 98':
197- raise TestSkipped('Windows 98 cannot handle unicode filenames')
198-
199 try:
200 os.mkdir(u'dod\xe9')
201 except UnicodeError:
202
203=== modified file 'breezy/tests/test_win32utils.py'
204--- breezy/tests/test_win32utils.py 2017-05-22 00:56:52 +0000
205+++ breezy/tests/test_win32utils.py 2017-06-05 23:56:54 +0000
206@@ -188,54 +188,9 @@
207 self.assertEqual('not-existing', p)
208
209
210-class TestLocations(TestCase):
211- """Tests for windows specific path and name retrieving functions"""
212-
213- def test__ensure_unicode_deprecated(self):
214- s = "text"
215- u1 = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
216- win32utils._ensure_unicode, s)
217- self.assertEqual(s, u1)
218- self.assertIsInstance(u1, unicode)
219- u2 = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
220- win32utils._ensure_unicode, u1)
221- self.assertIs(u1, u2)
222-
223- def test_appdata_unicode_deprecated(self):
224- self.overrideEnv("APPDATA", "fakepath")
225- s = win32utils.get_appdata_location()
226- u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
227- win32utils.get_appdata_location_unicode)
228- self.assertEqual(s, u)
229- self.assertIsInstance(s, unicode)
230-
231- def test_home_unicode_deprecated(self):
232- s = win32utils.get_home_location()
233- u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
234- win32utils.get_home_location_unicode)
235- self.assertEqual(s, u)
236- self.assertIsInstance(s, unicode)
237-
238- def test_user_unicode_deprecated(self):
239- self.overrideEnv("USERNAME", "alien")
240- s = win32utils.get_user_name()
241- u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
242- win32utils.get_user_name_unicode)
243- self.assertEqual(s, u)
244- self.assertIsInstance(s, unicode)
245-
246- def test_host_unicode_deprecated(self):
247- self.overrideEnv("COMPUTERNAME", "alienbox")
248- s = win32utils.get_host_name()
249- u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
250- win32utils.get_host_name_unicode)
251- self.assertEqual(s, u)
252- self.assertIsInstance(s, unicode)
253-
254-
255 class TestLocationsCtypes(TestCase):
256
257- _test_needs_features = [CtypesFeature]
258+ _test_needs_features = [CtypesFeature, features.win32_feature]
259
260 def assertPathsEqual(self, p1, p2):
261 # TODO: The env var values in particular might return the "short"
262
263=== modified file 'breezy/win32utils.py'
264--- breezy/win32utils.py 2017-05-22 00:56:52 +0000
265+++ breezy/win32utils.py 2017-06-05 23:56:54 +0000
266@@ -29,37 +29,9 @@
267
268 from breezy import (
269 cmdline,
270- symbol_versioning,
271 )
272 from breezy.i18n import gettext
273
274-# Windows version
275-if sys.platform == 'win32':
276- _major,_minor,_build,_platform,_text = sys.getwindowsversion()
277- # from MSDN:
278- # dwPlatformId
279- # The operating system platform.
280- # This member can be one of the following values.
281- # ========================== ======================================
282- # Value Meaning
283- # -------------------------- --------------------------------------
284- # VER_PLATFORM_WIN32_NT The operating system is Windows Vista,
285- # 2 Windows Server "Longhorn",
286- # Windows Server 2003, Windows XP,
287- # Windows 2000, or Windows NT.
288- #
289- # VER_PLATFORM_WIN32_WINDOWS The operating system is Windows Me,
290- # 1 Windows 98, or Windows 95.
291- # ========================== ======================================
292- if _platform == 2:
293- winver = 'Windows NT'
294- else:
295- # don't care about real Windows name, just to force safe operations
296- winver = 'Windows 98'
297-else:
298- winver = None
299-
300-
301 # We can cope without it; use a separate variable to help pyflakes
302 try:
303 import ctypes
304@@ -67,15 +39,9 @@
305 except ImportError:
306 has_ctypes = False
307 else:
308- if winver == 'Windows 98':
309- create_buffer = ctypes.create_string_buffer
310- def extract_buffer(buf):
311- return buf.value.decode("mbcs")
312- suffix = 'A'
313- else:
314- create_buffer = ctypes.create_unicode_buffer
315- extract_buffer = operator.attrgetter("value")
316- suffix = 'W'
317+ create_buffer = ctypes.create_unicode_buffer
318+ extract_buffer = operator.attrgetter("value")
319+ suffix = 'W'
320 try:
321 import pywintypes
322 has_pywintypes = True
323@@ -372,28 +338,6 @@
324 return get_environ_unicode('COMPUTERNAME')
325
326
327-@symbol_versioning.deprecated_function(
328- symbol_versioning.deprecated_in((2, 5, 0)))
329-def _ensure_unicode(s):
330- if s and not isinstance(s, unicode):
331- from . import osutils
332- s = s.decode(osutils.get_user_encoding())
333- return s
334-
335-
336-get_appdata_location_unicode = symbol_versioning.deprecated_function(
337- symbol_versioning.deprecated_in((2, 5, 0)))(get_appdata_location)
338-
339-get_home_location_unicode = symbol_versioning.deprecated_function(
340- symbol_versioning.deprecated_in((2, 5, 0)))(get_home_location)
341-
342-get_user_name_unicode = symbol_versioning.deprecated_function(
343- symbol_versioning.deprecated_in((2, 5, 0)))(get_user_name)
344-
345-get_host_name_unicode = symbol_versioning.deprecated_function(
346- symbol_versioning.deprecated_in((2, 5, 0)))(get_host_name)
347-
348-
349 def _ensure_with_dir(path):
350 if (not os.path.split(path)[0] or path.startswith(u'*')
351 or path.startswith(u'?')):
352@@ -491,10 +435,7 @@
353 def set_file_attr_hidden(path):
354 """Set file attributes to hidden if possible"""
355 if has_win32file:
356- if winver != 'Windows 98':
357- SetFileAttributes = win32file.SetFileAttributesW
358- else:
359- SetFileAttributes = win32file.SetFileAttributes
360+ SetFileAttributes = win32file.SetFileAttributesW
361 try:
362 SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
363 except pywintypes.error as e:
364@@ -543,7 +484,7 @@
365 return args
366
367
368-if has_ctypes and winver == 'Windows NT':
369+if has_ctypes:
370 def get_unicode_argv():
371 prototype = ctypes.WINFUNCTYPE(ctypes.c_wchar_p)
372 GetCommandLineW = prototype(("GetCommandLineW",
373@@ -554,7 +495,7 @@
374 # Skip the first argument, since we only care about parameters
375 argv = _command_line_to_argv(command_line, sys.argv)[1:]
376 return argv
377-
378+
379
380 def get_environ_unicode(key, default=None):
381 """Get `key` from environment as unicode or `default` if unset
382@@ -587,18 +528,6 @@
383 if buffer_size > length:
384 return buffer[:length]
385 buffer_size = length
386-else:
387- get_unicode_argv = None
388- def get_environ_unicode(key, default=None):
389- """Get `key` from environment as unicode or `default` if unset
390-
391- Fallback version that should basically never be needed.
392- """
393- from breezy import osutils
394- try:
395- return os.environ[key].decode(osutils.get_user_encoding())
396- except KeyError:
397- return default
398
399
400 if has_win32api:

Subscribers

People subscribed via source and target branches