Skip to content

Commit 3d08581

Browse files
committed
bug 1463425 - autopep8 on config/ r=gps
MozReview-Commit-ID: EaTAhH2CAee --HG-- extra : rebase_source : f278cd9fc6e8f9db720c1430121ba91e0417c9b9
1 parent dcfef84 commit 3d08581

20 files changed

+851
-757
lines changed

config/MozZipFile.py

Lines changed: 124 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -10,128 +10,129 @@
1010

1111

1212
class ZipFile(zipfile.ZipFile):
13-
""" Class with methods to open, read, write, close, list zip files.
14-
15-
Subclassing zipfile.ZipFile to allow for overwriting of existing
16-
entries, though only for writestr, not for write.
17-
"""
18-
def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED,
19-
lock = False):
20-
if lock:
21-
assert isinstance(file, basestring)
22-
self.lockfile = lock_file(file + '.lck')
23-
else:
24-
self.lockfile = None
25-
26-
if mode == 'a' and lock:
27-
# appending to a file which doesn't exist fails, but we can't check
28-
# existence util we hold the lock
29-
if (not os.path.isfile(file)) or os.path.getsize(file) == 0:
30-
mode = 'w'
31-
32-
zipfile.ZipFile.__init__(self, file, mode, compression)
33-
self._remove = []
34-
self.end = self.fp.tell()
35-
self.debug = 0
36-
37-
def writestr(self, zinfo_or_arcname, bytes):
38-
"""Write contents into the archive.
39-
40-
The contents is the argument 'bytes', 'zinfo_or_arcname' is either
41-
a ZipInfo instance or the name of the file in the archive.
42-
This method is overloaded to allow overwriting existing entries.
13+
""" Class with methods to open, read, write, close, list zip files.
14+
15+
Subclassing zipfile.ZipFile to allow for overwriting of existing
16+
entries, though only for writestr, not for write.
4317
"""
44-
if not isinstance(zinfo_or_arcname, zipfile.ZipInfo):
45-
zinfo = zipfile.ZipInfo(filename=zinfo_or_arcname,
46-
date_time=time.localtime(time.time()))
47-
zinfo.compress_type = self.compression
48-
# Add some standard UNIX file access permissions (-rw-r--r--).
49-
zinfo.external_attr = (0x81a4 & 0xFFFF) << 16L
50-
else:
51-
zinfo = zinfo_or_arcname
52-
53-
# Now to the point why we overwrote this in the first place,
54-
# remember the entry numbers if we already had this entry.
55-
# Optimizations:
56-
# If the entry to overwrite is the last one, just reuse that.
57-
# If we store uncompressed and the new content has the same size
58-
# as the old, reuse the existing entry.
59-
60-
doSeek = False # store if we need to seek to the eof after overwriting
61-
if self.NameToInfo.has_key(zinfo.filename):
62-
# Find the last ZipInfo with our name.
63-
# Last, because that's catching multiple overwrites
64-
i = len(self.filelist)
65-
while i > 0:
66-
i -= 1
67-
if self.filelist[i].filename == zinfo.filename:
68-
break
69-
zi = self.filelist[i]
70-
if ((zinfo.compress_type == zipfile.ZIP_STORED
71-
and zi.compress_size == len(bytes))
72-
or (i + 1) == len(self.filelist)):
73-
# make sure we're allowed to write, otherwise done by writestr below
74-
self._writecheck(zi)
75-
# overwrite existing entry
76-
self.fp.seek(zi.header_offset)
77-
if (i + 1) == len(self.filelist):
78-
# this is the last item in the file, just truncate
79-
self.fp.truncate()
18+
19+
def __init__(self, file, mode="r", compression=zipfile.ZIP_STORED,
20+
lock=False):
21+
if lock:
22+
assert isinstance(file, basestring)
23+
self.lockfile = lock_file(file + '.lck')
8024
else:
81-
# we need to move to the end of the file afterwards again
82-
doSeek = True
83-
# unhook the current zipinfo, the writestr of our superclass
84-
# will add a new one
85-
self.filelist.pop(i)
86-
self.NameToInfo.pop(zinfo.filename)
87-
else:
88-
# Couldn't optimize, sadly, just remember the old entry for removal
89-
self._remove.append(self.filelist.pop(i))
90-
zipfile.ZipFile.writestr(self, zinfo, bytes)
91-
self.filelist.sort(lambda l, r: cmp(l.header_offset, r.header_offset))
92-
if doSeek:
93-
self.fp.seek(self.end)
94-
self.end = self.fp.tell()
95-
96-
def close(self):
97-
"""Close the file, and for mode "w" and "a" write the ending
98-
records.
99-
100-
Overwritten to compact overwritten entries.
101-
"""
102-
if not self._remove:
103-
# we don't have anything special to do, let's just call base
104-
r = zipfile.ZipFile.close(self)
105-
self.lockfile = None
106-
return r
107-
108-
if self.fp.mode != 'r+b':
109-
# adjust file mode if we originally just wrote, now we rewrite
110-
self.fp.close()
111-
self.fp = open(self.filename, 'r+b')
112-
all = map(lambda zi: (zi, True), self.filelist) + \
113-
map(lambda zi: (zi, False), self._remove)
114-
all.sort(lambda l, r: cmp(l[0].header_offset, r[0].header_offset))
115-
# empty _remove for multiple closes
116-
self._remove = []
117-
118-
lengths = [all[i+1][0].header_offset - all[i][0].header_offset
119-
for i in xrange(len(all)-1)]
120-
lengths.append(self.end - all[-1][0].header_offset)
121-
to_pos = 0
122-
for (zi, keep), length in zip(all, lengths):
123-
if not keep:
124-
continue
125-
oldoff = zi.header_offset
126-
# python <= 2.4 has file_offset
127-
if hasattr(zi, 'file_offset'):
128-
zi.file_offset = zi.file_offset + to_pos - oldoff
129-
zi.header_offset = to_pos
130-
self.fp.seek(oldoff)
131-
content = self.fp.read(length)
132-
self.fp.seek(to_pos)
133-
self.fp.write(content)
134-
to_pos += length
135-
self.fp.truncate()
136-
zipfile.ZipFile.close(self)
137-
self.lockfile = None
25+
self.lockfile = None
26+
27+
if mode == 'a' and lock:
28+
# appending to a file which doesn't exist fails, but we can't check
29+
# existence util we hold the lock
30+
if (not os.path.isfile(file)) or os.path.getsize(file) == 0:
31+
mode = 'w'
32+
33+
zipfile.ZipFile.__init__(self, file, mode, compression)
34+
self._remove = []
35+
self.end = self.fp.tell()
36+
self.debug = 0
37+
38+
def writestr(self, zinfo_or_arcname, bytes):
39+
"""Write contents into the archive.
40+
41+
The contents is the argument 'bytes', 'zinfo_or_arcname' is either
42+
a ZipInfo instance or the name of the file in the archive.
43+
This method is overloaded to allow overwriting existing entries.
44+
"""
45+
if not isinstance(zinfo_or_arcname, zipfile.ZipInfo):
46+
zinfo = zipfile.ZipInfo(filename=zinfo_or_arcname,
47+
date_time=time.localtime(time.time()))
48+
zinfo.compress_type = self.compression
49+
# Add some standard UNIX file access permissions (-rw-r--r--).
50+
zinfo.external_attr = (0x81a4 & 0xFFFF) << 16L
51+
else:
52+
zinfo = zinfo_or_arcname
53+
54+
# Now to the point why we overwrote this in the first place,
55+
# remember the entry numbers if we already had this entry.
56+
# Optimizations:
57+
# If the entry to overwrite is the last one, just reuse that.
58+
# If we store uncompressed and the new content has the same size
59+
# as the old, reuse the existing entry.
60+
61+
doSeek = False # store if we need to seek to the eof after overwriting
62+
if self.NameToInfo.has_key(zinfo.filename):
63+
# Find the last ZipInfo with our name.
64+
# Last, because that's catching multiple overwrites
65+
i = len(self.filelist)
66+
while i > 0:
67+
i -= 1
68+
if self.filelist[i].filename == zinfo.filename:
69+
break
70+
zi = self.filelist[i]
71+
if ((zinfo.compress_type == zipfile.ZIP_STORED
72+
and zi.compress_size == len(bytes))
73+
or (i + 1) == len(self.filelist)):
74+
# make sure we're allowed to write, otherwise done by writestr below
75+
self._writecheck(zi)
76+
# overwrite existing entry
77+
self.fp.seek(zi.header_offset)
78+
if (i + 1) == len(self.filelist):
79+
# this is the last item in the file, just truncate
80+
self.fp.truncate()
81+
else:
82+
# we need to move to the end of the file afterwards again
83+
doSeek = True
84+
# unhook the current zipinfo, the writestr of our superclass
85+
# will add a new one
86+
self.filelist.pop(i)
87+
self.NameToInfo.pop(zinfo.filename)
88+
else:
89+
# Couldn't optimize, sadly, just remember the old entry for removal
90+
self._remove.append(self.filelist.pop(i))
91+
zipfile.ZipFile.writestr(self, zinfo, bytes)
92+
self.filelist.sort(lambda l, r: cmp(l.header_offset, r.header_offset))
93+
if doSeek:
94+
self.fp.seek(self.end)
95+
self.end = self.fp.tell()
96+
97+
def close(self):
98+
"""Close the file, and for mode "w" and "a" write the ending
99+
records.
100+
101+
Overwritten to compact overwritten entries.
102+
"""
103+
if not self._remove:
104+
# we don't have anything special to do, let's just call base
105+
r = zipfile.ZipFile.close(self)
106+
self.lockfile = None
107+
return r
108+
109+
if self.fp.mode != 'r+b':
110+
# adjust file mode if we originally just wrote, now we rewrite
111+
self.fp.close()
112+
self.fp = open(self.filename, 'r+b')
113+
all = map(lambda zi: (zi, True), self.filelist) + \
114+
map(lambda zi: (zi, False), self._remove)
115+
all.sort(lambda l, r: cmp(l[0].header_offset, r[0].header_offset))
116+
# empty _remove for multiple closes
117+
self._remove = []
118+
119+
lengths = [all[i+1][0].header_offset - all[i][0].header_offset
120+
for i in xrange(len(all)-1)]
121+
lengths.append(self.end - all[-1][0].header_offset)
122+
to_pos = 0
123+
for (zi, keep), length in zip(all, lengths):
124+
if not keep:
125+
continue
126+
oldoff = zi.header_offset
127+
# python <= 2.4 has file_offset
128+
if hasattr(zi, 'file_offset'):
129+
zi.file_offset = zi.file_offset + to_pos - oldoff
130+
zi.header_offset = to_pos
131+
self.fp.seek(oldoff)
132+
content = self.fp.read(length)
133+
self.fp.seek(to_pos)
134+
self.fp.write(content)
135+
to_pos += length
136+
self.fp.truncate()
137+
zipfile.ZipFile.close(self)
138+
self.lockfile = None

config/check_js_msg_encoding.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from mozversioncontrol import get_repository_from_env
1818

1919

20-
scriptname = os.path.basename(__file__);
20+
scriptname = os.path.basename(__file__)
2121
expected_encoding = 'ascii'
2222

2323
# The following files don't define JSErrorFormatString.
@@ -26,13 +26,16 @@
2626
'js/xpconnect/src/xpc.msg',
2727
]
2828

29+
2930
def log_pass(filename, text):
3031
print('TEST-PASS | {} | {} | {}'.format(scriptname, filename, text))
3132

33+
3234
def log_fail(filename, text):
3335
print('TEST-UNEXPECTED-FAIL | {} | {} | {}'.format(scriptname, filename,
3436
text))
3537

38+
3639
def check_single_file(filename):
3740
with open(filename, 'rb') as f:
3841
data = f.read()
@@ -44,6 +47,7 @@ def check_single_file(filename):
4447
log_pass(filename, 'ok')
4548
return True
4649

50+
4751
def check_files():
4852
result = True
4953

@@ -58,11 +62,13 @@ def check_files():
5862

5963
return result
6064

65+
6166
def main():
6267
if not check_files():
6368
sys.exit(1)
6469

6570
sys.exit(0)
6671

72+
6773
if __name__ == '__main__':
6874
main()

config/check_js_opcode.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
import os
1313
import sys
1414

15-
scriptname = os.path.basename(__file__);
15+
scriptname = os.path.basename(__file__)
1616
topsrcdir = os.path.dirname(os.path.dirname(__file__))
1717

18+
1819
def log_pass(text):
1920
print('TEST-PASS | {} | {}'.format(scriptname, text))
2021

22+
2123
def log_fail(text):
2224
print('TEST-UNEXPECTED-FAIL | {} | {}'.format(scriptname, text))
2325

26+
2427
def check_opcode():
2528
sys.path.insert(0, os.path.join(topsrcdir, 'js', 'src', 'vm'))
2629
import opcode
@@ -33,11 +36,13 @@ def check_opcode():
3336
log_pass('ok')
3437
return True
3538

39+
3640
def main():
3741
if not check_opcode():
3842
sys.exit(1)
3943

4044
sys.exit(0)
4145

46+
4247
if __name__ == '__main__':
4348
main()

config/check_macroassembler_style.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
reArgName = "(?P<name>\s\w+)"
3838
reArgDefault = "(?P<default>(?:\s=[^,)]+)?)"
3939
reAfterArg = "(?=[,)])"
40-
reMatchArg = re.compile(reBeforeArg + reArgType + reArgName + reArgDefault + reAfterArg)
40+
reMatchArg = re.compile(reBeforeArg + reArgType +
41+
reArgName + reArgDefault + reAfterArg)
4142

4243

4344
def get_normalized_signatures(signature, fileAnnot=None):
@@ -58,7 +59,8 @@ def get_normalized_signatures(signature, fileAnnot=None):
5859
archs = [fileAnnot['arch']]
5960

6061
if 'DEFINED_ON(' in signature:
61-
archs = re.sub(r'.*DEFINED_ON\((?P<archs>[^()]*)\).*', '\g<archs>', signature).split(',')
62+
archs = re.sub(
63+
r'.*DEFINED_ON\((?P<archs>[^()]*)\).*', '\g<archs>', signature).split(',')
6264
archs = [a.strip() for a in archs]
6365
signature = re.sub(r'\s+DEFINED_ON\([^()]*\)', '', signature)
6466

@@ -157,7 +159,8 @@ def get_macroassembler_definitions(filename):
157159
line = re.sub(r'//.*', '', line)
158160
if line.startswith('{') or line.strip() == "{}":
159161
if 'MacroAssembler::' in lines:
160-
signatures.extend(get_normalized_signatures(lines, fileAnnot))
162+
signatures.extend(
163+
get_normalized_signatures(lines, fileAnnot))
161164
if line.strip() != "{}": # Empty declaration, no need to declare
162165
# a new code section
163166
code_section = True
@@ -244,7 +247,8 @@ def generate_file_content(signatures):
244247
elif len(archs.symmetric_difference(all_shared_architecture_names)) == 0:
245248
output.append(s + ' PER_SHARED_ARCH;\n')
246249
else:
247-
output.append(s + ' DEFINED_ON(' + ', '.join(sorted(archs)) + ');\n')
250+
output.append(
251+
s + ' DEFINED_ON(' + ', '.join(sorted(archs)) + ');\n')
248252
for a in sorted(archs):
249253
a = a.replace('_', '-')
250254
masm = '%s/MacroAssembler-%s' % (a, a)
@@ -271,8 +275,10 @@ def check_style():
271275
filepath = os.path.join(dirpath, filename).replace('\\', '/')
272276

273277
if filepath.endswith('MacroAssembler.h'):
274-
decls = append_signatures(decls, get_macroassembler_declaration(filepath))
275-
defs = append_signatures(defs, get_macroassembler_definitions(filepath))
278+
decls = append_signatures(
279+
decls, get_macroassembler_declaration(filepath))
280+
defs = append_signatures(
281+
defs, get_macroassembler_definitions(filepath))
276282

277283
if not decls or not defs:
278284
raise Exception("Did not find any definitions or declarations")

0 commit comments

Comments
 (0)