Skip to content

Commit 6b9b378

Browse files
loolndechesne
authored andcommitted
Fix invalid escape sequence Python warnings
Use raw strings to properly quote regexps; fixes qualcomm-linux#6. Signed-off-by: Loïc Minier <[email protected]>
1 parent 7946754 commit 6b9b378

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

gen_partition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def generate_partition_xml (disk_entry, partition_entries_dict, output_xml):
234234
line = f.readline()
235235
partition_index = 0
236236
while line:
237-
if not re.search("^\s*#", line) and not re.search("^\s*$", line):
237+
if not re.search(r'^\s*#', line) and not re.search(r'^\s*$', line):
238238
line = line.strip()
239239
if re.search("^--disk", line):
240240
if disk_entry == None:

msp.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def HandleNUM_DISK_SECTORS(field):
193193
#print "returning since this is not a string"
194194
return field
195195

196-
m = re.search("NUM_DISK_SECTORS-(\d+)", field)
196+
m = re.search(r'NUM_DISK_SECTORS-(\d+)', field)
197197
if type(m) is not NoneType:
198198
if DiskSizeInBytes > 0 :
199199
field = int((DiskSizeInBytes/SECTOR_SIZE)-int(m.group(1))) # here I know DiskSizeInBytes
@@ -245,15 +245,15 @@ def ReturnParsedValues(element):
245245
MyDict['size_in_bytes'] = int(float(MyDict['size_in_bytes']))
246246

247247
# These only affect patching
248-
m = re.search("CRC32\((\d+).?,(\d+).?\)", MyDict['value'])
248+
m = re.search(r'CRC32\((\d+).?,(\d+).?\)', MyDict['value'])
249249
if type(m) is not NoneType:
250250
MyDict['value'] = 0
251251
MyDict['function'] = "CRC32"
252252
MyDict['arg0'] = int(float(m.group(1))) # start_sector
253253
MyDict['arg1'] = int(float(m.group(2))) # len_in_bytes
254254
else:
255255
## above didn't match, so try this
256-
m = re.search("CRC32\((NUM_DISK_SECTORS-\d+).?,(\d+).?\)", MyDict['value'])
256+
m = re.search(r'CRC32\((NUM_DISK_SECTORS-\d+).?,(\d+).?\)', MyDict['value'])
257257
if type(m) is not NoneType:
258258
MyDict['value'] = 0
259259
MyDict['function'] = "CRC32"
@@ -309,9 +309,9 @@ def ParseXML(xml_filename): ## this function updates all the global arrays
309309

310310

311311
def ReturnArrayFromCommaSeparatedList(sz):
312-
temp = re.sub("\s+|\n"," ",sz)
313-
temp = re.sub("^\s+","",temp)
314-
temp = re.sub("\s+$","",temp)
312+
temp = re.sub(r'\s+|\n'," ",sz)
313+
temp = re.sub(r'^\s+',"",temp)
314+
temp = re.sub(r'\s+$',"",temp)
315315
return temp.split(',')
316316

317317
def find_file(filename, search_paths):
@@ -912,7 +912,7 @@ def GetPartitions():
912912
for line in output:
913913
#print line
914914

915-
m = re.search("(\d+) (sd[a-z])$", line)
915+
m = re.search(r'(\d+) (sd[a-z])$', line)
916916
if type(m) is not NoneType:
917917
Size = int(m.group(1))
918918
Device = "/dev/"+m.group(2)
@@ -943,7 +943,7 @@ def GetPartitions():
943943

944944
response = response.replace('\r', '').strip("\n").split("\n")[1:]
945945
for line in response:
946-
m = re.search("(PHYSICALDRIVE\d+).+ (\d+) ", line)
946+
m = re.search(r'(PHYSICALDRIVE\d+).+ (\d+) ', line)
947947
if type(m) is not NoneType:
948948
Size = int(m.group(2)) # size in bytes
949949
Device = "\\\\.\\"+m.group(1) # \\.\PHYSICALDRIVE1

ptool.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ def ValidGUIDForm(GUID):
190190

191191
print("Testing if GUID=",GUID)
192192

193-
m = re.search("0x([a-fA-F\d]{32})$", GUID) #0xC79926B7B668C0874433B9E5EBD0A0A2
193+
m = re.search(r'0x([a-fA-F\d]{32})$', GUID) #0xC79926B7B668C0874433B9E5EBD0A0A2
194194
if m is not None:
195195
return True
196196

197-
m = re.search("([a-fA-F\d]{8})-([a-fA-F\d]{4})-([a-fA-F\d]{4})-([a-fA-F\d]{2})([a-fA-F\d]{2})-([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})", GUID)
197+
m = re.search(r'([a-fA-F\d]{8})-([a-fA-F\d]{4})-([a-fA-F\d]{4})-([a-fA-F\d]{2})([a-fA-F\d]{2})-([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})', GUID)
198198
if m is not None:
199199
return True
200200

@@ -212,7 +212,7 @@ def ValidateTYPE(Type):
212212
if type(Type) is not str:
213213
Type = str(Type)
214214

215-
m = re.search("^(0x)?([a-fA-F\d][a-fA-F\d]?)$", Type)
215+
m = re.search(r'^(0x)?([a-fA-F\d][a-fA-F\d]?)$', Type)
216216
if m is None:
217217
print("\tWARNING: Type \"%s\" is not in the form 0x4C" % Type)
218218
sys.exit(1)
@@ -229,7 +229,7 @@ def ValidateGUID(GUID):
229229

230230
print("Looking to validate GUID=",GUID)
231231

232-
m = re.search("0x([a-fA-F\d]{32})$", GUID) #0xC79926B7B668C0874433B9E5EBD0A0A2
232+
m = re.search(r'0x([a-fA-F\d]{32})$', GUID) #0xC79926B7B668C0874433B9E5EBD0A0A2
233233
if m is not None:
234234
tempGUID = int(m.group(1),16)
235235
print("\tGUID \"%s\"" % GUID)
@@ -247,7 +247,7 @@ def ValidateGUID(GUID):
247247

248248
else:
249249
#ebd0a0a2-b9e5-4433-87c0-68b6b72699c7 --> #0x C7 99 26 B7 B6 68 C087 4433 B9E5 EBD0A0A2
250-
m = re.search("([a-fA-F\d]{8})-([a-fA-F\d]{4})-([a-fA-F\d]{4})-([a-fA-F\d]{2})([a-fA-F\d]{2})-([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})", GUID)
250+
m = re.search(r'([a-fA-F\d]{8})-([a-fA-F\d]{4})-([a-fA-F\d]{4})-([a-fA-F\d]{2})([a-fA-F\d]{2})-([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})([a-fA-F\d]{2})', GUID)
251251
if m is not None:
252252
print("Found more advanced type")
253253
tempGUID = (int(m.group(4),16)<<64) | (int(m.group(3),16)<<48) | (int(m.group(2),16)<<32) | int(m.group(1),16)
@@ -1080,7 +1080,7 @@ def ParseXML(XMLFile):
10801080

10811081
if 'SECTOR_SIZE_IN_BYTES' in HashInstructions:
10821082
if type(HashInstructions['SECTOR_SIZE_IN_BYTES']) is str:
1083-
m = re.search("^(\d+)$", HashInstructions['SECTOR_SIZE_IN_BYTES'])
1083+
m = re.search(r'^(\d+)$', HashInstructions['SECTOR_SIZE_IN_BYTES'])
10841084
if m is None:
10851085
## we didn't match, so assign deafult
10861086
HashInstructions['SECTOR_SIZE_IN_BYTES'] = 512
@@ -1101,7 +1101,7 @@ def ParseXML(XMLFile):
11011101

11021102
if 'WRITE_PROTECT_BOUNDARY_IN_KB' in HashInstructions:
11031103
if type(HashInstructions['WRITE_PROTECT_BOUNDARY_IN_KB']) is str:
1104-
m = re.search("^(\d+)$", HashInstructions['WRITE_PROTECT_BOUNDARY_IN_KB'])
1104+
m = re.search(r'^(\d+)$', HashInstructions['WRITE_PROTECT_BOUNDARY_IN_KB'])
11051105
if m is None:
11061106
## we didn't match, so assign deafult
11071107
HashInstructions['WRITE_PROTECT_BOUNDARY_IN_KB'] = 0
@@ -1113,7 +1113,7 @@ def ParseXML(XMLFile):
11131113

11141114
if 'PERFORMANCE_BOUNDARY_IN_KB' in HashInstructions:
11151115
if type(HashInstructions['PERFORMANCE_BOUNDARY_IN_KB']) is str:
1116-
m = re.search("^(\d+)$", HashInstructions['PERFORMANCE_BOUNDARY_IN_KB'])
1116+
m = re.search(r'^(\d+)$', HashInstructions['PERFORMANCE_BOUNDARY_IN_KB'])
11171117
if m is None:
11181118
## we didn't match, so assign deafult
11191119
HashInstructions['PERFORMANCE_BOUNDARY_IN_KB'] = 0
@@ -1178,7 +1178,7 @@ def ParseXML(XMLFile):
11781178

11791179
if 'DISK_SIGNATURE' in HashInstructions:
11801180
if type(HashInstructions['DISK_SIGNATURE']) is str:
1181-
m = re.search("^0x([\da-fA-F]+)$", HashInstructions['DISK_SIGNATURE'])
1181+
m = re.search(r'^0x([\da-fA-F]+)$', HashInstructions['DISK_SIGNATURE'])
11821182
if m is None:
11831183
print("WARNING: DISK_SIGNATURE is not formed correctly, expected format is 0x12345678\n")
11841184
HashInstructions['DISK_SIGNATURE'] = 0x00000000
@@ -1190,7 +1190,7 @@ def ParseXML(XMLFile):
11901190

11911191
if 'ALIGN_BOUNDARY_IN_KB' in HashInstructions:
11921192
if type(HashInstructions['ALIGN_BOUNDARY_IN_KB']) is str:
1193-
m = re.search("^(\d+)$", HashInstructions['ALIGN_BOUNDARY_IN_KB'])
1193+
m = re.search(r'^(\d+)$', HashInstructions['ALIGN_BOUNDARY_IN_KB'])
11941194
if m is None:
11951195
## we didn't match, so assign deafult
11961196
HashInstructions['ALIGN_BOUNDARY_IN_KB'] = HashInstructions['WRITE_PROTECT_BOUNDARY_IN_KB']
@@ -1541,7 +1541,7 @@ def ParseCommandLine():
15411541
print("\nWill AUTO-DETECT from file")
15421542

15431543
if len(sys.argv) >= 4: # Should mean PHY partition was specified
1544-
m = re.search("^\d+$", sys.argv[3] )
1544+
m = re.search(r'^\d+$', sys.argv[3] )
15451545
if m is not None:
15461546
PhysicalPartitionNumber = int(sys.argv[3])
15471547
print("PhysicalPartitionNumber specified as %d" % PhysicalPartitionNumber)
@@ -2387,7 +2387,7 @@ def find_file(filename, search_paths):
23872387

23882388
elif o in ("-k", "--use128partitions"):
23892389
## Force there to be 128 partitions in the partition table
2390-
m = re.search("\d", a) #mbr|gpt
2390+
m = re.search(r'\d', a) #mbr|gpt
23912391
if m is None:
23922392
force128partitions = 0
23932393
else:
@@ -2401,7 +2401,7 @@ def find_file(filename, search_paths):
24012401

24022402
elif o in ("-g", "--sequentialguid"):
24032403
## also allow seperating commas
2404-
m = re.search("\d", a) #mbr|gpt
2404+
m = re.search(r'\d', a) #mbr|gpt
24052405
if m is None:
24062406
sequentialguid = 0
24072407
else:
@@ -2410,7 +2410,7 @@ def find_file(filename, search_paths):
24102410
elif o in ("-p", "--partition"):
24112411
UsingGetOpts = True
24122412
PhysicalPartitionNumber = a
2413-
m = re.search("^(\d)$", a) #0|1|2
2413+
m = re.search(r'^(\d)$', a) #0|1|2
24142414
if m is None:
24152415
PrintBigError("ERROR: PhysicalPartitionNumber (-p) must be a number, you supplied *",a,"*")
24162416
else:

0 commit comments

Comments
 (0)