comparison mercurial/ui.py @ 43506:9f70512ae2cf

cleanup: remove pointless r-prefixes on single-quoted strings This is the promised second step on single-quoted strings. These had existed because our source transformer didn't turn r'' into b'', so we had tagged some strings as r-strings to get "native" strings on both Pythons. Now that the transformer is gone, we can dispense with this nonsense. Methodology: I ran hg locate 'set:added() or modified() or clean()' | egrep '.*\.py$' | xargs egrep --color=never -n -- \[\^b\]\[\^a-z\]r\'\[\^\'\\\\\]\*\'\[\^\'\ in an emacs grep-mode buffer, and then used a keyboard macro to iterate over the results and remove the r prefix as needed. # skip-blame removing unneeded r prefixes left over from Python 3 migration. Differential Revision: https://phab.mercurial-scm.org/D7306
author Augie Fackler <augie@google.com>
date Fri, 08 Nov 2019 11:19:20 -0800
parents aaa046919043
children be8552f25cab
comparison
equal deleted inserted replaced
43505:47fac1692ede 43506:9f70512ae2cf
426 426
427 def readconfig( 427 def readconfig(
428 self, filename, root=None, trust=False, sections=None, remap=None 428 self, filename, root=None, trust=False, sections=None, remap=None
429 ): 429 ):
430 try: 430 try:
431 fp = open(filename, r'rb') 431 fp = open(filename, 'rb')
432 except IOError: 432 except IOError:
433 if not sections: # ignore unless we were looking for something 433 if not sections: # ignore unless we were looking for something
434 return 434 return
435 raise 435 raise
436 436
1085 ''' 1085 '''
1086 dest = self._fout 1086 dest = self._fout
1087 1087
1088 # inlined _write() for speed 1088 # inlined _write() for speed
1089 if self._buffers: 1089 if self._buffers:
1090 label = opts.get(r'label', b'') 1090 label = opts.get('label', b'')
1091 if label and self._bufferapplylabels: 1091 if label and self._bufferapplylabels:
1092 self._buffers[-1].extend(self.label(a, label) for a in args) 1092 self._buffers[-1].extend(self.label(a, label) for a in args)
1093 else: 1093 else:
1094 self._buffers[-1].extend(args) 1094 self._buffers[-1].extend(args)
1095 return 1095 return
1096 1096
1097 # inlined _writenobuf() for speed 1097 # inlined _writenobuf() for speed
1098 if not opts.get(r'keepprogressbar', False): 1098 if not opts.get('keepprogressbar', False):
1099 self._progclear() 1099 self._progclear()
1100 msg = b''.join(args) 1100 msg = b''.join(args)
1101 1101
1102 # opencode timeblockedsection because this is a critical path 1102 # opencode timeblockedsection because this is a critical path
1103 starttime = util.timer() 1103 starttime = util.timer()
1106 # windows color printing is its own can of crab, defer to 1106 # windows color printing is its own can of crab, defer to
1107 # the color module and that is it. 1107 # the color module and that is it.
1108 color.win32print(self, dest.write, msg, **opts) 1108 color.win32print(self, dest.write, msg, **opts)
1109 else: 1109 else:
1110 if self._colormode is not None: 1110 if self._colormode is not None:
1111 label = opts.get(r'label', b'') 1111 label = opts.get('label', b'')
1112 msg = self.label(msg, label) 1112 msg = self.label(msg, label)
1113 dest.write(msg) 1113 dest.write(msg)
1114 except IOError as err: 1114 except IOError as err:
1115 raise error.StdioError(err) 1115 raise error.StdioError(err)
1116 finally: 1116 finally:
1122 self._write(self._ferr, *args, **opts) 1122 self._write(self._ferr, *args, **opts)
1123 1123
1124 def _write(self, dest, *args, **opts): 1124 def _write(self, dest, *args, **opts):
1125 # update write() as well if you touch this code 1125 # update write() as well if you touch this code
1126 if self._isbuffered(dest): 1126 if self._isbuffered(dest):
1127 label = opts.get(r'label', b'') 1127 label = opts.get('label', b'')
1128 if label and self._bufferapplylabels: 1128 if label and self._bufferapplylabels:
1129 self._buffers[-1].extend(self.label(a, label) for a in args) 1129 self._buffers[-1].extend(self.label(a, label) for a in args)
1130 else: 1130 else:
1131 self._buffers[-1].extend(args) 1131 self._buffers[-1].extend(args)
1132 else: 1132 else:
1133 self._writenobuf(dest, *args, **opts) 1133 self._writenobuf(dest, *args, **opts)
1134 1134
1135 def _writenobuf(self, dest, *args, **opts): 1135 def _writenobuf(self, dest, *args, **opts):
1136 # update write() as well if you touch this code 1136 # update write() as well if you touch this code
1137 if not opts.get(r'keepprogressbar', False): 1137 if not opts.get('keepprogressbar', False):
1138 self._progclear() 1138 self._progclear()
1139 msg = b''.join(args) 1139 msg = b''.join(args)
1140 1140
1141 # opencode timeblockedsection because this is a critical path 1141 # opencode timeblockedsection because this is a critical path
1142 starttime = util.timer() 1142 starttime = util.timer()
1151 # windows color printing is its own can of crab, defer to 1151 # windows color printing is its own can of crab, defer to
1152 # the color module and that is it. 1152 # the color module and that is it.
1153 color.win32print(self, dest.write, msg, **opts) 1153 color.win32print(self, dest.write, msg, **opts)
1154 else: 1154 else:
1155 if self._colormode is not None: 1155 if self._colormode is not None:
1156 label = opts.get(r'label', b'') 1156 label = opts.get('label', b'')
1157 msg = self.label(msg, label) 1157 msg = self.label(msg, label)
1158 dest.write(msg) 1158 dest.write(msg)
1159 # stderr may be buffered under win32 when redirected to files, 1159 # stderr may be buffered under win32 when redirected to files,
1160 # including stdout. 1160 # including stdout.
1161 if dest is self._ferr and not getattr(self._ferr, 'closed', False): 1161 if dest is self._ferr and not getattr(self._ferr, 'closed', False):
1586 If ui is not interactive, the default is returned. 1586 If ui is not interactive, the default is returned.
1587 """ 1587 """
1588 return self._prompt(msg, default=default) 1588 return self._prompt(msg, default=default)
1589 1589
1590 def _prompt(self, msg, **opts): 1590 def _prompt(self, msg, **opts):
1591 default = opts[r'default'] 1591 default = opts['default']
1592 if not self.interactive(): 1592 if not self.interactive():
1593 self._writemsg(self._fmsgout, msg, b' ', type=b'prompt', **opts) 1593 self._writemsg(self._fmsgout, msg, b' ', type=b'prompt', **opts)
1594 self._writemsg( 1594 self._writemsg(
1595 self._fmsgout, default or b'', b"\n", type=b'promptecho' 1595 self._fmsgout, default or b'', b"\n", type=b'promptecho'
1596 ) 1596 )
1672 l = self._fin.readline() 1672 l = self._fin.readline()
1673 if not l: 1673 if not l:
1674 raise EOFError 1674 raise EOFError
1675 return l.rstrip(b'\n') 1675 return l.rstrip(b'\n')
1676 else: 1676 else:
1677 return getpass.getpass(r'') 1677 return getpass.getpass('')
1678 except EOFError: 1678 except EOFError:
1679 raise error.ResponseExpected() 1679 raise error.ResponseExpected()
1680 1680
1681 def status(self, *msg, **opts): 1681 def status(self, *msg, **opts):
1682 '''write status message to output (if ui.quiet is False) 1682 '''write status message to output (if ui.quiet is False)
1763 rdir = repopath 1763 rdir = repopath
1764 (fd, name) = pycompat.mkstemp( 1764 (fd, name) = pycompat.mkstemp(
1765 prefix=b'hg-' + extra[b'prefix'] + b'-', suffix=suffix, dir=rdir 1765 prefix=b'hg-' + extra[b'prefix'] + b'-', suffix=suffix, dir=rdir
1766 ) 1766 )
1767 try: 1767 try:
1768 f = os.fdopen(fd, r'wb') 1768 f = os.fdopen(fd, 'wb')
1769 f.write(util.tonativeeol(text)) 1769 f.write(util.tonativeeol(text))
1770 f.close() 1770 f.close()
1771 1771
1772 environ = {b'HGUSER': user} 1772 environ = {b'HGUSER': user}
1773 if b'transplant_source' in extra: 1773 if b'transplant_source' in extra:
1791 onerr=error.Abort, 1791 onerr=error.Abort,
1792 errprefix=_(b"edit failed"), 1792 errprefix=_(b"edit failed"),
1793 blockedtag=b'editor', 1793 blockedtag=b'editor',
1794 ) 1794 )
1795 1795
1796 f = open(name, r'rb') 1796 f = open(name, 'rb')
1797 t = util.fromnativeeol(f.read()) 1797 t = util.fromnativeeol(f.read())
1798 f.close() 1798 f.close()
1799 finally: 1799 finally:
1800 os.unlink(name) 1800 os.unlink(name)
1801 1801
1862 b''.join(causetb), 1862 b''.join(causetb),
1863 b''.join(exconly), 1863 b''.join(exconly),
1864 ) 1864 )
1865 else: 1865 else:
1866 output = traceback.format_exception(exc[0], exc[1], exc[2]) 1866 output = traceback.format_exception(exc[0], exc[1], exc[2])
1867 self.write_err(encoding.strtolocal(r''.join(output))) 1867 self.write_err(encoding.strtolocal(''.join(output)))
1868 return self.tracebackflag or force 1868 return self.tracebackflag or force
1869 1869
1870 def geteditor(self): 1870 def geteditor(self):
1871 '''return editor to use''' 1871 '''return editor to use'''
1872 if pycompat.sysplatform == b'plan9': 1872 if pycompat.sysplatform == b'plan9':
2303 2303
2304 The specified message type is translated to 'ui.<type>' label if the dest 2304 The specified message type is translated to 'ui.<type>' label if the dest
2305 isn't a structured channel, so that the message will be colorized. 2305 isn't a structured channel, so that the message will be colorized.
2306 """ 2306 """
2307 # TODO: maybe change 'type' to a mandatory option 2307 # TODO: maybe change 'type' to a mandatory option
2308 if r'type' in opts and not getattr(dest, 'structured', False): 2308 if 'type' in opts and not getattr(dest, 'structured', False):
2309 opts[r'label'] = opts.get(r'label', b'') + b' ui.%s' % opts.pop(r'type') 2309 opts['label'] = opts.get('label', b'') + b' ui.%s' % opts.pop('type')
2310 write(dest, *args, **opts) 2310 write(dest, *args, **opts)