Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Created May 18, 2010 18:10
Show Gist options
  • Save atifaziz/405314 to your computer and use it in GitHub Desktop.
Save atifaziz/405314 to your computer and use it in GitHub Desktop.
IronPython 2.6.1 (2.6.10920.0) on .NET 4.0.30319.1
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>>
>>> clr.AddReference('Elmah')
>>> from Elmah.Assertions import AssertionFactory
>>> from Elmah import ErrorMailModule, ErrorLogModule
>>> from Elmah.ErrorFilterModule import AssertionHelperContext
>>>
>>> clr.AddReference('System.Web')
>>> from System.Web import HttpException
>>>
>>> clr.AddReference('System.Xml')
>>> from System.Xml import XmlDocument
>>>
>>> xml = """
... <or>
... <and>
... <equal binding="HttpStatusCode"
... value="404" type="Int32" />
... <regex binding="FilterSourceType.Name"
... pattern="mail" />
... </and>
... <and>
... <equal binding="Exception.Message"
... value="Padding is invalid and cannot be removed."
... type="String" />
... <regex binding="FilterSourceType.Name"
... pattern="mail" />
... </and>
... </or>
... """
>>>
>>> config = XmlDocument()
>>> config.LoadXml(xml)
>>>
>>> assertion = AssertionFactory.Create(config.DocumentElement)
>>>
>>> mailmod = ErrorMailModule()
>>> logmod = ErrorLogModule()
>>>
>>> error = HttpException(404, None)
>>> context = AssertionHelperContext(mailmod, error, None)
>>> print assertion.Test(context)
True
>>>
>>> error = HttpException(500, None)
>>> context = AssertionHelperContext(mailmod, error, None)
>>> print assertion.Test(context)
False
>>>
>>> error = HttpException('Padding is invalid and cannot be removed.')
>>> context = AssertionHelperContext(mailmod, error, None)
>>> print assertion.Test(context)
True
>>>
>>> context = AssertionHelperContext(logmod, error, None)
>>> print assertion.Test(context)
False
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment