# Path: git_trac/token_transport.py
# class TokenAuthenticatedTransport(SafeTransport, object):
#     def __init__(self, token):
#         super(TokenAuthenticatedTransport, self).__init__()
#         self._token = token
# 
#     def single_request(self, host, handler, request_body, verbose):
#         """
#         Issue an XML-RPC request.
#         """
# 
#         try:
#             return super(TokenAuthenticatedTransport, self).single_request(
#                     host, handler, request_body, verbose)
#         except Fault as e:
#             raise TracInternalError(e)
#         except IOError as e:
#             if hasattr(e, 'code') and e.code == 401:
#                 raise TracAuthenticationError()
#             else:
#                 raise TracConnectionError(e.reason)
# 
#     def get_host_info(self, host):
#         host, extra_headers, x509 = super(TokenAuthenticatedTransport,
#                 self).get_host_info(host)
# 
#         if extra_headers:
#             headers = dict(extra_headers)
#         else:
#             headers = {}
#             extra_headers = []
# 
#         if 'Authorization' not in headers:
#             auth = 'Bearer ' + self._token
#             extra_headers.append(('Authorization', auth.strip()))
# 
#         return host, extra_headers, x509
# 
# Path: git_trac/config.py
# class AuthenticationError(Exception):
#     pass
# 
# Path: git_trac/logger.py
# def make_logger(name, doctest_mode=False):
# def enable_doctest_mode():
# 
# Path: git_trac/trac_ticket.py
# def TracTicket(ticket_number, server_proxy):
#     from xml.parsers.expat import ExpatError
#     ticket_number = int(ticket_number)
#     try:
#         change_log = server_proxy.ticket.changeLog(ticket_number)
#     except ExpatError:
#         print('Failed to parse the trac changelog, malformed XML!')
#         change_log = []
#     data = server_proxy.ticket.get(ticket_number)
#     ticket_changes = [TicketChange(entry) for entry in change_log]
#     return TracTicket_class(data[0], data[1], data[2], data[3], ticket_changes)
# 
# Path: git_trac/cached_property.py
# class cached_property(object):
# 
#     def __init__(self, method, name=None):
#         self.method = method
#         self.name = name or method.__name__
#         self.__doc__ = method.__doc__
# 
#     def __get__(self, instance, cls):
#         if instance is None:
#             return self
#         result = self.method(instance)
#         setattr(instance, self.name, result)
#         return result


import os
        import tempfile
        import subprocess
    from xmlrpc.client import ServerProxy
    from .digest_transport import DigestTransport, AuthenticatedDigestTransport
    from urllib import parse as url_parse
    from xmlrpclib import ServerProxy
    from .digest_transport_py2 import DigestTransport, AuthenticatedDigestTransport
    from urllib2 import urlparse as url_parse
from .token_transport import TokenAuthenticatedTransport
from .config import AuthenticationError
from .logger import logger
from .trac_ticket import TracTicket
from .cached_property import cached_property

    @cached_property
    def url_authenticated(self):
        return url_parse.urljoin(self.config.server_hostname, 
                                 self.config.server_authenticated_xmlrpc)

    @cached_property 
    def anonymous_proxy(self):
        transport = DigestTransport()
        return ServerProxy(
            self.url_anonymous,
            transport=transport,
            verbose=self.config.debug
        )

    @cached_property
    def authenticated_proxy(self):
        try:
            # First try to use token authentication, if provided
            token = self.config.token
        except AuthenticationError:
            # This implies that a token was not configured; fall back
            # to original HTTP digest authenticated transport
            transport = AuthenticatedDigestTransport(
                realm=self.config.server_realm,
                url=self.config.server_hostname,
                username=self.config.username,
                password=self.config.password)
            endpoint_url = self.url_authenticated
        else:

# Path: git_trac/token_transport.py
# class TokenAuthenticatedTransport(SafeTransport, object):
#     def __init__(self, token):
#         super(TokenAuthenticatedTransport, self).__init__()
#         self._token = token
# 
#     def single_request(self, host, handler, request_body, verbose):
#         """
#         Issue an XML-RPC request.
#         """
# 
#         try:
#             return super(TokenAuthenticatedTransport, self).single_request(
#                     host, handler, request_body, verbose)
#         except Fault as e:
#             raise TracInternalError(e)
#         except IOError as e:
#             if hasattr(e, 'code') and e.code == 401:
#                 raise TracAuthenticationError()
#             else:
#                 raise TracConnectionError(e.reason)
# 
#     def get_host_info(self, host):
#         host, extra_headers, x509 = super(TokenAuthenticatedTransport,
#                 self).get_host_info(host)
# 
#         if extra_headers:
#             headers = dict(extra_headers)
#         else:
#             headers = {}
#             extra_headers = []
# 
#         if 'Authorization' not in headers:
#             auth = 'Bearer ' + self._token
#             extra_headers.append(('Authorization', auth.strip()))
# 
#         return host, extra_headers, x509
# 
# Path: git_trac/config.py
# class AuthenticationError(Exception):
#     pass
# 
# Path: git_trac/logger.py
# def make_logger(name, doctest_mode=False):
# def enable_doctest_mode():
# 
# Path: git_trac/trac_ticket.py
# def TracTicket(ticket_number, server_proxy):
#     from xml.parsers.expat import ExpatError
#     ticket_number = int(ticket_number)
#     try:
#         change_log = server_proxy.ticket.changeLog(ticket_number)
#     except ExpatError:
#         print('Failed to parse the trac changelog, malformed XML!')
#         change_log = []
#     data = server_proxy.ticket.get(ticket_number)
#     ticket_changes = [TicketChange(entry) for entry in change_log]
#     return TracTicket_class(data[0], data[1], data[2], data[3], ticket_changes)
# 
# Path: git_trac/cached_property.py
# class cached_property(object):
# 
#     def __init__(self, method, name=None):
#         self.method = method
#         self.name = name or method.__name__
#         self.__doc__ = method.__doc__
# 
#     def __get__(self, instance, cls):
#         if instance is None:
#             return self
#         result = self.method(instance)
#         setattr(instance, self.name, result)
#         return result


# Path: git_trac/trac_server.py
import os
        import tempfile
        import subprocess
    from xmlrpc.client import ServerProxy
    from .digest_transport import DigestTransport, AuthenticatedDigestTransport
    from urllib import parse as url_parse
    from xmlrpclib import ServerProxy
    from .digest_transport_py2 import DigestTransport, AuthenticatedDigestTransport
    from urllib2 import urlparse as url_parse
from .token_transport import TokenAuthenticatedTransport
from .config import AuthenticationError
from .logger import logger
from .trac_ticket import TracTicket
from .cached_property import cached_property


    @cached_property
    def url_authenticated(self):
        return url_parse.urljoin(self.config.server_hostname, 
                                 self.config.server_authenticated_xmlrpc)

    @cached_property 
    def anonymous_proxy(self):
        transport = DigestTransport()
        return ServerProxy(
            self.url_anonymous,
            transport=transport,
            verbose=self.config.debug
        )

    @cached_property
    def authenticated_proxy(self):
        try:
            # First try to use token authentication, if provided
            token = self.config.token
        except AuthenticationError:
            # This implies that a token was not configured; fall back
            # to original HTTP digest authenticated transport
            transport = AuthenticatedDigestTransport(
                realm=self.config.server_realm,
                url=self.config.server_hostname,
                username=self.config.username,
                password=self.config.password)
            endpoint_url = self.url_authenticated
        else:

            transport = TokenAuthenticatedTransport(token=token)