

def patch_sourcelines(fname, in_line_start, out_line, endline='\n', silent_mode=False):
    'Replace the middle of lines between in_line_start and endline '
    import io
    import os.path as osp
    if osp.isfile(fname):
        with io.open(fname, 'r') as fh:
            contents = fh.readlines()
            content = ''.join(contents)
            for l in range(len(contents)):
                if contents[l].startswith(in_line_start):
                    (begining, middle) = (in_line_start, contents[l][len(in_line_start):])
                    ending = ''
                    if (middle.find(endline) > 0):
                        ending = (endline + endline.join(middle.split(endline)[1:]))
                        middle = middle.split(endline)[0]
                    middle = out_line
                    new_line = ((begining + middle) + ending)
                    if (not (new_line == contents[l])):
                        if (not silent_mode):
                            print('patching ', fname, ' from\n', contents[l], '\nto\n', endline)
                    contents[l] = new_line
            new_content = ''.join(contents)
        if (not (new_content == content)):
            with io.open(fname, 'wt') as fh:
                try:
                    fh.write(new_content)
                except:
                    print('impossible to patch', fname, 'from', content, 'to', new_content)

dataset/ETHPy150Open winpython/winpython/winpython/utils.py patch_sourcelines/VarMisuse@230/325 `new_line`->`endline`