Created
April 14, 2017 15:27
-
-
Save apsillers/6fdca29b1827020bdcbd4376fc7c45fd to your computer and use it in GitHub Desktop.
monkey patch example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class STIXPackage: | |
def to_xml(self, include_namespaces=True, include_schemalocs=False, | |
ns_dict=None, schemaloc_dict=None): | |
# do things | |
# monkey patch | |
global __old_to_xml_clobbered_by_stix_edh | |
__old_to_xml_clobbered_by_stix_edh = stix.core.stix_package.STIXPackage.to_xml | |
def new_to_xml(self, ns_dict=None, *args, **kwargs): | |
if ns_dict is None: ns_dict = {} | |
ns_dict.update({ 'urn:edm:edh:cyber:v3': 'edh2' }) | |
return __old_to_xml_clobbered_by_stix_edh(self, ns_dict=ns_dict, *args, **kwargs) | |
stix.core.stix_package.STIXPackage.to_xml = new_to_xml | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment