diff hgext/win32text.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 649d3ac37a12
line wrap: on
line diff
--- a/hgext/win32text.py	Sun Oct 06 09:45:02 2019 -0400
+++ b/hgext/win32text.py	Sun Oct 06 09:48:39 2019 -0400
@@ -56,20 +56,20 @@
 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
 # be specifying the version(s) of Mercurial they are tested with, or
 # leave the attribute unspecified.
-testedwith = 'ships-with-hg-core'
+testedwith = b'ships-with-hg-core'
 
 configtable = {}
 configitem = registrar.configitem(configtable)
 
 configitem(
-    'win32text', 'warn', default=True,
+    b'win32text', b'warn', default=True,
 )
 
 # regexp for single LF without CR preceding.
-re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE)
+re_single_lf = re.compile(b'(^|[^\r])\n', re.MULTILINE)
 
-newlinestr = {'\r\n': 'CRLF', '\r': 'CR'}
-filterstr = {'\r\n': 'clever', '\r': 'mac'}
+newlinestr = {b'\r\n': b'CRLF', b'\r': b'CR'}
+filterstr = {b'\r\n': b'clever', b'\r': b'mac'}
 
 
 def checknewline(s, newline, ui=None, repo=None, filename=None):
@@ -80,32 +80,32 @@
     if newline in s and ui and filename and repo:
         ui.warn(
             _(
-                'WARNING: %s already has %s line endings\n'
-                'and does not need EOL conversion by the win32text plugin.\n'
-                'Before your next commit, please reconsider your '
-                'encode/decode settings in \nMercurial.ini or %s.\n'
+                b'WARNING: %s already has %s line endings\n'
+                b'and does not need EOL conversion by the win32text plugin.\n'
+                b'Before your next commit, please reconsider your '
+                b'encode/decode settings in \nMercurial.ini or %s.\n'
             )
-            % (filename, newlinestr[newline], repo.vfs.join('hgrc'))
+            % (filename, newlinestr[newline], repo.vfs.join(b'hgrc'))
         )
 
 
 def dumbdecode(s, cmd, **kwargs):
-    checknewline(s, '\r\n', **kwargs)
+    checknewline(s, b'\r\n', **kwargs)
     # replace single LF to CRLF
-    return re_single_lf.sub('\\1\r\n', s)
+    return re_single_lf.sub(b'\\1\r\n', s)
 
 
 def dumbencode(s, cmd):
-    return s.replace('\r\n', '\n')
+    return s.replace(b'\r\n', b'\n')
 
 
 def macdumbdecode(s, cmd, **kwargs):
-    checknewline(s, '\r', **kwargs)
-    return s.replace('\n', '\r')
+    checknewline(s, b'\r', **kwargs)
+    return s.replace(b'\n', b'\r')
 
 
 def macdumbencode(s, cmd):
-    return s.replace('\r', '\n')
+    return s.replace(b'\r', b'\n')
 
 
 def cleverdecode(s, cmd, **kwargs):
@@ -133,14 +133,14 @@
 
 
 _filters = {
-    'dumbdecode:': dumbdecode,
-    'dumbencode:': dumbencode,
-    'cleverdecode:': cleverdecode,
-    'cleverencode:': cleverencode,
-    'macdumbdecode:': macdumbdecode,
-    'macdumbencode:': macdumbencode,
-    'macdecode:': macdecode,
-    'macencode:': macencode,
+    b'dumbdecode:': dumbdecode,
+    b'dumbencode:': dumbencode,
+    b'cleverdecode:': cleverdecode,
+    b'cleverencode:': cleverencode,
+    b'macdumbdecode:': macdumbdecode,
+    b'macdumbencode:': macdumbencode,
+    b'macdecode:': macdecode,
+    b'macencode:': macencode,
 }
 
 
@@ -152,7 +152,7 @@
     # newest version as canonical. this prevents us from blocking a
     # changegroup that contains an unacceptable commit followed later
     # by a commit that fixes the problem.
-    tip = repo['tip']
+    tip = repo[b'tip']
     for rev in pycompat.xrange(
         repo.changelog.tiprev(), repo[node].rev() - 1, -1
     ):
@@ -166,32 +166,32 @@
                 if not halt:
                     ui.warn(
                         _(
-                            'attempt to commit or push text file(s) '
-                            'using %s line endings\n'
+                            b'attempt to commit or push text file(s) '
+                            b'using %s line endings\n'
                         )
                         % newlinestr[newline]
                     )
-                ui.warn(_('in %s: %s\n') % (short(c.node()), f))
+                ui.warn(_(b'in %s: %s\n') % (short(c.node()), f))
                 halt = True
-    if halt and hooktype == 'pretxnchangegroup':
+    if halt and hooktype == b'pretxnchangegroup':
         crlf = newlinestr[newline].lower()
         filter = filterstr[newline]
         ui.warn(
             _(
-                '\nTo prevent this mistake in your local repository,\n'
-                'add to Mercurial.ini or .hg/hgrc:\n'
-                '\n'
-                '[hooks]\n'
-                'pretxncommit.%s = python:hgext.win32text.forbid%s\n'
-                '\n'
-                'and also consider adding:\n'
-                '\n'
-                '[extensions]\n'
-                'win32text =\n'
-                '[encode]\n'
-                '** = %sencode:\n'
-                '[decode]\n'
-                '** = %sdecode:\n'
+                b'\nTo prevent this mistake in your local repository,\n'
+                b'add to Mercurial.ini or .hg/hgrc:\n'
+                b'\n'
+                b'[hooks]\n'
+                b'pretxncommit.%s = python:hgext.win32text.forbid%s\n'
+                b'\n'
+                b'and also consider adding:\n'
+                b'\n'
+                b'[extensions]\n'
+                b'win32text =\n'
+                b'[encode]\n'
+                b'** = %sencode:\n'
+                b'[decode]\n'
+                b'** = %sdecode:\n'
             )
             % (crlf, crlf, filter, filter)
         )
@@ -199,11 +199,11 @@
 
 
 def forbidcrlf(ui, repo, hooktype, node, **kwargs):
-    return forbidnewline(ui, repo, hooktype, node, '\r\n', **kwargs)
+    return forbidnewline(ui, repo, hooktype, node, b'\r\n', **kwargs)
 
 
 def forbidcr(ui, repo, hooktype, node, **kwargs):
-    return forbidnewline(ui, repo, hooktype, node, '\r', **kwargs)
+    return forbidnewline(ui, repo, hooktype, node, b'\r', **kwargs)
 
 
 def reposetup(ui, repo):
@@ -215,10 +215,10 @@
 
 def extsetup(ui):
     # deprecated config: win32text.warn
-    if ui.configbool('win32text', 'warn'):
+    if ui.configbool(b'win32text', b'warn'):
         ui.warn(
             _(
-                "win32text is deprecated: "
-                "https://mercurial-scm.org/wiki/Win32TextExtension\n"
+                b"win32text is deprecated: "
+                b"https://mercurial-scm.org/wiki/Win32TextExtension\n"
             )
         )