Skip to content

Instantly share code, notes, and snippets.

@apsillers
Created April 14, 2017 15:27
Show Gist options
  • Save apsillers/6fdca29b1827020bdcbd4376fc7c45fd to your computer and use it in GitHub Desktop.
Save apsillers/6fdca29b1827020bdcbd4376fc7c45fd to your computer and use it in GitHub Desktop.
monkey patch example
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