# Path: jmbase/jmbase/support.py
# def wrapped_urlparse(url):
#     """ This wrapper is unfortunately necessary as there appears
#     to be a bug in the urlparse handling of *.onion strings:
#     If http:// is prepended, the url parses correctly, but if it
#     is not, the .hostname property is erroneously None.
#     """
#     if isinstance(url, str):
#         a, b = (".onion", "http://")
#     else:
#         a, b = (b".onion", b"http://")
#     if url.endswith(a) and not url.startswith(b):
#         url = b + url
#     return urlparse.urlparse(url)


from zope.interface import implementer
from twisted.internet.error import ReactorNotRunning
from twisted.internet import reactor, defer
from twisted.internet.endpoints import (TCP4ClientEndpoint,
                        UNIXClientEndpoint, serverFromString)
from twisted.web.client import Agent, BrowserLikePolicyForHTTPS
from txtorcon.web import tor_agent
from txtorcon import TorControlProtocol, TorConfig
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.web.iweb import IPolicyForHTTPS
from twisted.internet.ssl import CertificateOptions
from .support import wrapped_urlparse
import txtorcon
import warnings


_custom_stop_reactor_is_set = False
custom_stop_reactor = None

# This removes `CONF_CHANGED` requests
# over the Tor control port, which aren't needed for our use case.
def patch_add_event_listener(self, evt, callback):

# Path: jmbase/jmbase/support.py
# def wrapped_urlparse(url):
#     """ This wrapper is unfortunately necessary as there appears
#     to be a bug in the urlparse handling of *.onion strings:
#     If http:// is prepended, the url parses correctly, but if it
#     is not, the .hostname property is erroneously None.
#     """
#     if isinstance(url, str):
#         a, b = (".onion", "http://")
#     else:
#         a, b = (b".onion", b"http://")
#     if url.endswith(a) and not url.startswith(b):
#         url = b + url
#     return urlparse.urlparse(url)


# Path: jmbase/jmbase/twisted_utils.py
from zope.interface import implementer
from twisted.internet.error import ReactorNotRunning
from twisted.internet import reactor, defer
from twisted.internet.endpoints import (TCP4ClientEndpoint,
                        UNIXClientEndpoint, serverFromString)
from twisted.web.client import Agent, BrowserLikePolicyForHTTPS
from txtorcon.web import tor_agent
from txtorcon import TorControlProtocol, TorConfig
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.web.iweb import IPolicyForHTTPS
from twisted.internet.ssl import CertificateOptions
from .support import wrapped_urlparse
import txtorcon
import warnings



_custom_stop_reactor_is_set = False
custom_stop_reactor = None

# This removes `CONF_CHANGED` requests
# over the Tor control port, which aren't needed for our use case.
def patch_add_event_listener(self, evt, callback):

    if evt not in self.valid_events.values():