marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I am going to use unnamed temporary files to pass arbitrarily large input data
  to worker creating bundles. To do so, I need a unified API that work on py2 
and
  py3.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9211

AFFECTED FILES
  mercurial/pycompat.py

CHANGE DETAILS

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -506,6 +506,17 @@
     return tempfile.mkstemp(suffix, prefix, dir)
 
 
+# TemporaryFile does not support an "encoding=" argument on python2.
+# This wrapper file are always open in byte mode.
+def unnamedtempfile(mode=None, *args, **kwargs):
+    if mode is None:
+        mode = b'w+b'
+    else:
+        mode = sysstr(mode)
+    assert 'b' in mode
+    return tempfile.TemporaryFile(mode, *args, **kwargs)
+
+
 # NamedTemporaryFile does not support an "encoding=" argument on python2.
 # This wrapper file are always open in byte mode.
 def namedtempfile(



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to