Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
functions on platforms where the underlying system calls are available.
diff --git a/Lib/shutil.py b/Lib/shutil.py
index c3ff687..f00f9b7 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -60,13 +60,15 @@
         os.chmod(dst, mode)
 
 def copystat(src, dst):
-    """Copy all stat info (mode bits, atime and mtime) from src to dst"""
+    """Copy all stat info (mode bits, atime, mtime, flags) from src to dst"""
     st = os.stat(src)
     mode = stat.S_IMODE(st.st_mode)
     if hasattr(os, 'utime'):
         os.utime(dst, (st.st_atime, st.st_mtime))
     if hasattr(os, 'chmod'):
         os.chmod(dst, mode)
+    if hasattr(os, 'chflags') and hasattr(st, 'st_flags'):
+        os.chflags(dst, st.st_flags)
 
 
 def copy(src, dst):
diff --git a/Lib/stat.py b/Lib/stat.py
index 70750d8..5f41687 100644
--- a/Lib/stat.py
+++ b/Lib/stat.py
@@ -84,3 +84,16 @@
 S_IROTH = 00004
 S_IWOTH = 00002
 S_IXOTH = 00001
+
+# Names for file flags
+
+UF_NODUMP    = 0x00000001
+UF_IMMUTABLE = 0x00000002
+UF_APPEND    = 0x00000004
+UF_OPAQUE    = 0x00000008
+UF_NOUNLINK  = 0x00000010
+SF_ARCHIVED  = 0x00010000
+SF_IMMUTABLE = 0x00020000
+SF_APPEND    = 0x00040000
+SF_NOUNLINK  = 0x00100000
+SF_SNAPSHOT  = 0x00200000
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index f98c723..7207de5 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -192,6 +192,18 @@
             posix.utime(test_support.TESTFN, (int(now), int(now)))
             posix.utime(test_support.TESTFN, (now, now))
 
+    def test_chflags(self):
+        if hasattr(posix, 'chflags'):
+            st = os.stat(test_support.TESTFN)
+            if hasattr(st, 'st_flags'):
+                posix.chflags(test_support.TESTFN, st.st_flags)
+
+    def test_lchflags(self):
+        if hasattr(posix, 'lchflags'):
+            st = os.stat(test_support.TESTFN)
+            if hasattr(st, 'st_flags'):
+                posix.lchflags(test_support.TESTFN, st.st_flags)
+
 def test_main():
     test_support.run_unittest(PosixTester)