MCPcopy Index your code
hub / github.com/python/cpython / replace_paths_in_code

Method replace_paths_in_code

Lib/modulefinder.py:593–614  ·  view source on GitHub ↗
(self, co)

Source from the content-addressed store, hash-verified

591 return missing, maybe
592
593 def replace_paths_in_code(self, co):
594 new_filename = original_filename = os.path.normpath(co.co_filename)
595 for f, r in self.replace_paths:
596 if original_filename.startswith(f):
597 new_filename = r + original_filename[len(f):]
598 break
599
600 if self.debug and original_filename not in self.processed_paths:
601 if new_filename != original_filename:
602 self.msgout(2, "co_filename %r changed to %r" \
603 % (original_filename,new_filename,))
604 else:
605 self.msgout(2, "co_filename %r remains unchanged" \
606 % (original_filename,))
607 self.processed_paths.append(original_filename)
608
609 consts = list(co.co_consts)
610 for i in range(len(consts)):
611 if isinstance(consts[i], type(co)):
612 consts[i] = self.replace_paths_in_code(consts[i])
613
614 return co.replace(co_consts=tuple(consts), co_filename=new_filename)
615
616
617def test():

Callers 1

load_moduleMethod · 0.95

Calls 5

msgoutMethod · 0.95
listClass · 0.85
startswithMethod · 0.45
appendMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected