##// END OF EJS Templates
py3: constant-fold some `pycompat.ispy3`
Manuel Jacob -
r50183:ef5f5f1c default
parent child Browse files
Show More
@@ -55,45 +55,25 b' class _shlexpy3proxy:'
55
55
56 def shlexer(data=None, filepath=None, wordchars=None, whitespace=None):
56 def shlexer(data=None, filepath=None, wordchars=None, whitespace=None):
57 if data is None:
57 if data is None:
58 if pycompat.ispy3:
58 data = open(filepath, b'r', encoding='latin1')
59 data = open(filepath, b'r', encoding='latin1')
60 else:
61 data = open(filepath, b'r')
62 else:
59 else:
63 if filepath is not None:
60 if filepath is not None:
64 raise error.ProgrammingError(
61 raise error.ProgrammingError(
65 b'shlexer only accepts data or filepath, not both'
62 b'shlexer only accepts data or filepath, not both'
66 )
63 )
67 if pycompat.ispy3:
64 data = data.decode('latin1')
68 data = data.decode('latin1')
69 l = shlex.shlex(data, infile=filepath, posix=True)
65 l = shlex.shlex(data, infile=filepath, posix=True)
70 if whitespace is not None:
66 if whitespace is not None:
71 l.whitespace_split = True
67 l.whitespace_split = True
72 if pycompat.ispy3:
68 l.whitespace += whitespace.decode('latin1')
73 l.whitespace += whitespace.decode('latin1')
74 else:
75 l.whitespace += whitespace
76 if wordchars is not None:
69 if wordchars is not None:
77 if pycompat.ispy3:
70 l.wordchars += wordchars.decode('latin1')
78 l.wordchars += wordchars.decode('latin1')
71 return _shlexpy3proxy(l)
79 else:
80 l.wordchars += wordchars
81 if pycompat.ispy3:
82 return _shlexpy3proxy(l)
83 return l
84
85
86 if pycompat.ispy3:
87 base64_encodebytes = base64.encodebytes
88 base64_decodebytes = base64.decodebytes
89 else:
90 base64_encodebytes = base64.encodestring
91 base64_decodebytes = base64.decodestring
92
72
93
73
94 def encodeargs(args):
74 def encodeargs(args):
95 def encodearg(s):
75 def encodearg(s):
96 lines = base64_encodebytes(s)
76 lines = base64.encodebytes(s)
97 lines = [l.splitlines()[0] for l in pycompat.iterbytestr(lines)]
77 lines = [l.splitlines()[0] for l in pycompat.iterbytestr(lines)]
98 return b''.join(lines)
78 return b''.join(lines)
99
79
@@ -102,7 +82,7 b' def encodeargs(args):'
102
82
103
83
104 def decodeargs(s):
84 def decodeargs(s):
105 s = base64_decodebytes(s)
85 s = base64.decodebytes(s)
106 return pickle.loads(s)
86 return pickle.loads(s)
107
87
108
88
@@ -534,8 +534,7 b' WHERE filenode = ? AND filename = ?'
534 ).fetchone()[0]
534 ).fetchone()[0]
535 # This filelog is missing some data. Build the
535 # This filelog is missing some data. Build the
536 # filelog, then recurse (which will always find data).
536 # filelog, then recurse (which will always find data).
537 if pycompat.ispy3:
537 commit = commit.decode('ascii')
538 commit = commit.decode('ascii')
539 index.fill_in_filelog(self.gitrepo, self._db, commit, gp, gn)
538 index.fill_in_filelog(self.gitrepo, self._db, commit, gp, gn)
540 return self.parents(node)
539 return self.parents(node)
541 else:
540 else:
@@ -114,7 +114,7 b' def _report_commit(ui, repo, ctx):'
114 msg['From'] = mail.addressencode(ui, sender, n.charsets, n.test)
114 msg['From'] = mail.addressencode(ui, sender, n.charsets, n.test)
115 msg['To'] = ', '.join(sorted(subs))
115 msg['To'] = ', '.join(sorted(subs))
116
116
117 msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
117 msgtext = msg.as_bytes()
118 if ui.configbool(b'notify', b'test'):
118 if ui.configbool(b'notify', b'test'):
119 ui.write(msgtext)
119 ui.write(msgtext)
120 if not msgtext.endswith(b'\n'):
120 if not msgtext.endswith(b'\n'):
@@ -113,7 +113,7 b' def _report_commit(ui, repo, ctx):'
113 msg['From'] = mail.addressencode(ui, sender, n.charsets, n.test)
113 msg['From'] = mail.addressencode(ui, sender, n.charsets, n.test)
114 msg['To'] = ', '.join(sorted(subs))
114 msg['To'] = ', '.join(sorted(subs))
115
115
116 msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
116 msgtext = msg.as_bytes()
117 if ui.configbool(b'notify', b'test'):
117 if ui.configbool(b'notify', b'test'):
118 ui.write(msgtext)
118 ui.write(msgtext)
119 if not msgtext.endswith(b'\n'):
119 if not msgtext.endswith(b'\n'):
@@ -465,7 +465,7 b' class notifier:'
465 # create fresh mime message from scratch
465 # create fresh mime message from scratch
466 # (multipart templates must take care of this themselves)
466 # (multipart templates must take care of this themselves)
467 headers = msg.items()
467 headers = msg.items()
468 payload = msg.get_payload(decode=pycompat.ispy3)
468 payload = msg.get_payload(decode=True)
469 # for notification prefer readability over data precision
469 # for notification prefer readability over data precision
470 msg = mail.mimeencode(self.ui, payload, self.charsets, self.test)
470 msg = mail.mimeencode(self.ui, payload, self.charsets, self.test)
471 # reinstate custom headers
471 # reinstate custom headers
@@ -524,7 +524,7 b' class notifier:'
524 )
524 )
525 msg['To'] = ', '.join(sorted(subs))
525 msg['To'] = ', '.join(sorted(subs))
526
526
527 msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
527 msgtext = msg.as_bytes()
528 if self.test:
528 if self.test:
529 self.ui.write(msgtext)
529 self.ui.write(msgtext)
530 if not msgtext.endswith(b'\n'):
530 if not msgtext.endswith(b'\n'):
General Comments 0
You need to be logged in to leave comments. Login now