def proto_refactor(proto_filename, namespace, namespace_path):
with open(proto_filename) as f:<EOL><INDENT>data = f.read()<EOL>if not re.search('<STR_LIT>', data):<EOL><INDENT>insert_syntax = '<STR_LIT>'<EOL>data = insert_syntax + data<EOL><DEDENT>substitution = '<STR_LIT>'.format(namespace_path)<EOL>data = re.sub('<STR_LIT>', substitution, data)<EOL>return data<EOL><DEDENT>
This method refactors a Protobuf file to import from a namespace
    that will map to the desired python package structure. It also ensures
    that the syntax is set to "proto2", since protoc complains without it.

    Args:
        proto_filename (str): the protobuf filename to be refactored
        namespace (str): the desired package name (i.e. "dropsonde.py2")
        namespace_path (str): the desired path corresponding to the package
                              name (i.e. "dropsonde/py2")