mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Special support for pickling os.stat and os.stat_vfs results portably
(the types come from different modules on different platforms). Added tests for pickling these types. May be a bugfix candidate.
This commit is contained in:
parent
ce358e3015
commit
0e02530a79
2 changed files with 31 additions and 0 deletions
20
Lib/os.py
20
Lib/os.py
|
@ -602,3 +602,23 @@ if _exists("fork"):
|
||||||
stdout, stdin = popen2.popen4(cmd, bufsize)
|
stdout, stdin = popen2.popen4(cmd, bufsize)
|
||||||
return stdin, stdout
|
return stdin, stdout
|
||||||
__all__.append("popen4")
|
__all__.append("popen4")
|
||||||
|
|
||||||
|
import copy_reg as _copy_reg
|
||||||
|
|
||||||
|
def _make_stat_result(tup, dict):
|
||||||
|
return stat_result(tup, dict)
|
||||||
|
|
||||||
|
def _pickle_stat_result(sr):
|
||||||
|
(type, args) = sr.__reduce__()
|
||||||
|
return (_make_stat_result, args)
|
||||||
|
|
||||||
|
_copy_reg.pickle(stat_result, _pickle_stat_result,_make_stat_result)
|
||||||
|
|
||||||
|
def _make_statvfs_result(tup, dict):
|
||||||
|
return statvfs_result(tup, dict)
|
||||||
|
|
||||||
|
def _pickle_statvfs_result(sr):
|
||||||
|
(type, args) = sr.__reduce__()
|
||||||
|
return (_make_statvfs_result, args)
|
||||||
|
|
||||||
|
_copy_reg.pickle(statvfs_result, _pickle_statvfs_result,_make_statvfs_result)
|
||||||
|
|
|
@ -254,6 +254,17 @@ class AbstractPickleTests(unittest.TestCase):
|
||||||
s = self.dumps(t)
|
s = self.dumps(t)
|
||||||
u = self.loads(s)
|
u = self.loads(s)
|
||||||
self.assertEqual(t, u)
|
self.assertEqual(t, u)
|
||||||
|
import os
|
||||||
|
if hasattr(os, "stat"):
|
||||||
|
t = os.stat(os.curdir)
|
||||||
|
s = self.dumps(t)
|
||||||
|
u = self.loads(s)
|
||||||
|
self.assertEqual(t, u)
|
||||||
|
if hasattr(os, "statvfs"):
|
||||||
|
t = os.statvfs(os.curdir)
|
||||||
|
s = self.dumps(t)
|
||||||
|
u = self.loads(s)
|
||||||
|
self.assertEqual(t, u)
|
||||||
|
|
||||||
class AbstractPickleModuleTests(unittest.TestCase):
|
class AbstractPickleModuleTests(unittest.TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue