Example #1
0
    def _authenticated_server_proxy(self):
        r"""
        Get an XML-RPC proxy object that is authenticated using the users
        username and password.

        EXAMPLES::

            sage: dev.trac._authenticated_server_proxy  # not tested
            Trac username: username
            Trac password:
            Should I store your password in a configuration file for future sessions? (This configuration file might be readable by privileged users on this system.) [yes/No]
            <ServerProxy for trac.sagemath.org/login/xmlrpc>

        TESTS:

        To make sure that doctests do not tamper with the live trac
        server, it is an error to access this property during a
        doctest (The ``dev`` object during doctests is also modified
        to prevent this)::

            sage: from sage.dev.test.config import DoctestConfig
            sage: from sage.dev.test.user_interface import DoctestUserInterface
            sage: from sage.dev.trac_interface import TracInterface
            sage: config = DoctestConfig()
            sage: trac = TracInterface(config['trac'], DoctestUserInterface(config['UI']))
            sage: trac._authenticated_server_proxy
            Traceback (most recent call last):
            ...
            AssertionError: doctest tried to access an authenticated session to trac
        """
        import sage.doctest
        assert not sage.doctest.DOCTEST_MODE, \
            "doctest tried to access an authenticated session to trac"

        self._check_password_timeout()

        if self.__authenticated_server_proxy is None:
            from sage.env import REALM
            realm = self._config.get('realm', REALM)
            from sage.env import TRAC_SERVER_URI
            server = self._config.get('server', TRAC_SERVER_URI)
            import os, urllib, urllib2, urlparse
            url = urlparse.urljoin(server, urllib.pathname2url(os.path.join('login', 'xmlrpc')))
            while True:
                from xmlrpclib import ServerProxy
                from digest_transport import DigestTransport
                from trac_error import TracAuthenticationError
                transport = DigestTransport()
                transport.add_authentication(realm=realm, url=server, username=self._username, password=self._password)
                proxy = ServerProxy(url, transport=transport)
                try:
                    proxy.system.listMethods()
                    break
                except TracAuthenticationError:
                    self._UI.error("Invalid username/password")
                    self.reset_username()
            self.__authenticated_server_proxy = proxy
        self._postpone_password_timeout()
        return self.__authenticated_server_proxy
Example #2
0
    def _authenticated_server_proxy(self):
        r"""
        Get an XML-RPC proxy object that is authenticated using the users
        username and password.

        .. NOTE::

            To make sure that doctests do not tamper with the live trac server,
            it is an error to access this property during a doctest.

        EXAMPLES::

            sage: dev.trac._authenticated_server_proxy # not tested
            Trac username: username
            Trac password:
            Should I store your password in a configuration file for future sessions? (This configuration file might be readable by privileged users on this system.) [yes/No]
            <ServerProxy for trac.sagemath.org/login/xmlrpc>

        TESTS::

            sage: dev.trac._authenticated_server_proxy
            Traceback (most recent call last):
            ...
            AssertionError: doctest tried to access an authenticated session to trac
        """
        import sage.doctest
        assert not sage.doctest.DOCTEST_MODE, "doctest tried to access an authenticated session to trac"

        self._check_password_timeout()

        if self.__authenticated_server_proxy is None:
            from sage.env import REALM
            realm = self._config.get('realm', REALM)
            from sage.env import TRAC_SERVER_URI
            server = self._config.get('server', TRAC_SERVER_URI)
            import os, urllib, urllib2, urlparse
            url = urlparse.urljoin(
                server, urllib.pathname2url(os.path.join('login', 'xmlrpc')))
            while True:
                from xmlrpclib import ServerProxy
                from digest_transport import DigestTransport
                from trac_error import TracAuthenticationError
                transport = DigestTransport()
                transport.add_authentication(realm=realm,
                                             url=server,
                                             username=self._username,
                                             password=self._password)
                proxy = ServerProxy(url, transport=transport)
                try:
                    proxy.system.listMethods()
                    break
                except TracAuthenticationError:
                    self._UI.error("Invalid username/password")
                    self.reset_username()
            self.__authenticated_server_proxy = proxy
        self._postpone_password_timeout()
        return self.__authenticated_server_proxy
Example #3
0
    def _authenticated_server_proxy(self):
        r"""
        Get an XML-RPC proxy object that is authenticated using the users
        username and password.

        .. NOTE::

            To make sure that doctests do not tamper with the live trac server,
            it is an error to access this property during a doctest.

        EXAMPLES::

            sage: dev.trac._authenticated_server_proxy # not tested
            Trac username: username
            Trac password:
            Should I store your password in a configuration file for future sessions? (This configuration file might be readable by privileged users on this system.) [yes/No]
            <ServerProxy for trac.sagemath.org/login/xmlrpc>

        TESTS::

            sage: dev.trac._authenticated_server_proxy
            Traceback (most recent call last):
            ...
            AssertionError: doctest tried to access an authenticated session to trac
        """
        import sage.doctest
        assert not sage.doctest.DOCTEST_MODE, "doctest tried to access an authenticated session to trac"

        self._check_password_timeout()

        if self.__authenticated_server_proxy is None:
            from sage.env import REALM
            realm = self._config.get('realm', REALM)
            from sage.env import TRAC_SERVER_URI
            server = self._config.get('server', TRAC_SERVER_URI)
            import os, urllib, urllib2, urlparse
            url = urlparse.urljoin(server, urllib.pathname2url(os.path.join('login', 'xmlrpc')))
            while True:
                from xmlrpclib import ServerProxy
                from digest_transport import DigestTransport
                transport = DigestTransport()
                transport.add_authentication(realm=realm, url=server, username=self._username, password=self._password)
                proxy = ServerProxy(url, transport=transport)
                try:
                    proxy.system.listMethods()
                    break
                except urllib2.HTTPError as error:
                    if error.code == 401:
                        self._UI.show("Invalid username/password")
                        self.reset_username()
                    else:
                        self._UI.show("Could not verify password, will try to proceed.")
                        break
            self.__authenticated_server_proxy = proxy
        self._postpone_password_timeout()
        return self.__authenticated_server_proxy
    def _anonymous_server_proxy(self):
        """
        Return a non-authenticated XML-RPC interface to trac.

        .. NOTE::

            Unlike the authenticated server proxy, this can be used in
            doctesting. However, all doctests relying on it talking to the
            actual trac server should be marked as ``optional: internet``.

        EXAMPLES::

            sage: from sage.dev.test.config import DoctestConfig
            sage: from sage.dev.test.user_interface import DoctestUserInterface
            sage: from sage.dev.trac_interface import TracInterface
            sage: config = DoctestConfig()
            sage: trac = TracInterface(config['trac'], DoctestUserInterface(config['UI']))
            sage: repr(trac._anonymous_server_proxy)
            '<ServerProxy for trac.sagemath.org/xmlrpc>'
        """
        if self.__anonymous_server_proxy is None:
            from sage.env import TRAC_SERVER_URI
            server = self._config.get('server', TRAC_SERVER_URI)
            import urlparse
            url = urlparse.urljoin(server, 'xmlrpc')
            from digest_transport import DigestTransport
            transport = DigestTransport()
            from xmlrpclib import ServerProxy
            self.__anonymous_server_proxy = ServerProxy(url,
                                                        transport=transport)

        return self.__anonymous_server_proxy