1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2013 Red Hat, Inc.
# This file is part of python-fedora
#
# python-fedora is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# python-fedora is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with python-fedora; if not, see <http://www.gnu.org/licenses/>
#
'''
fedora.client is used to interact with Fedora Services.
.. versionchanged:: 0.3.21
Deprecate DictContainer in favor of bunch.Bunch
.. versionchanged:: 0.3.35
Add the openid clients
.. moduleauthor:: Ricky Zhou <ricky@fedoraproject.org>
.. moduleauthor:: Luke Macken <lmacken@redhat.com>
.. moduleauthor:: Toshio Kuratomi <tkuratom@redhat.com>
'''
import warnings
from munch import Munch
class FedoraClientError(Exception):
'''Base Exception for problems which originate within the Clients.
This should be the base class for any exceptions that the Client generates
generate. For instance, if the client performs validation before passing
the data on to the Fedora Service.
Problems returned while talking to the Services should be returned via a
`FedoraServiceError` instead.
'''
pass
class FedoraServiceError(Exception):
'''Base Exception for any problem talking with the Service.
When the Client gets an error talking to the server, an exception of this
type is raised. This can be anything in the networking layer up to an
error returned from the server itself.
'''
pass
class ServerError(FedoraServiceError):
'''Unable to talk to the server properly.
This includes network errors and 500 response codes. If the error was
generated from an http response, :attr:`code` is the HTTP response code.
Otherwise, :attr:`code` will be -1.
'''
def __init__(self, url, status, msg):
FedoraServiceError.__init__(self)
self.filename = url
self.code = status
self.msg = msg
def __str__(self):
return 'ServerError(%s, %s, %s)' % (self.filename, self.code, self.msg)
def __repr__(self):
return 'ServerError(%r, %r, %r)' % (self.filename, self.code, self.msg)
class AuthError(FedoraServiceError):
'''Error during authentication. For instance, invalid password.'''
pass
class LoginRequiredError(AuthError):
""" Exception raised when the call requires a logged-in user. """
pass
class AppError(FedoraServiceError):
'''Error condition that the server is passing back to the client.'''
def __init__(self, name, message, extras=None):
FedoraServiceError.__init__(self)
self.name = name
self.message = message
self.extras = extras
def __str__(self):
return 'AppError(%s, %s, extras=%s)' % (
self.name, self.message, self.extras)
def __repr__(self):
return 'AppError(%r, %r, extras=%r)' % (
self.name, self.message, self.extras)
# Backwards compatibility
class DictContainer(Munch):
def __init__(self, *args, **kwargs):
warnings.warn(
'DictContainer is deprecated. Use the Munch class'
' from python-bunch instead.', DeprecationWarning, stacklevel=2)
Munch.__init__(self, *args, **kwargs)
# We want people to be able to import fedora.client.*Client directly
# pylint: disable-msg=W0611
from fedora.client.proxyclient import ProxyClient
from fedora.client.fasproxy import FasProxyClient
from fedora.client.baseclient import BaseClient
from fedora.client.openidproxyclient import OpenIdProxyClient
from fedora.client.openidbaseclient import OpenIdBaseClient
from fedora.client.fas2 import AccountSystem, FASError, CLAError
from fedora.client.bodhi import BodhiClient, BodhiClientException
from fedora.client.wiki import Wiki
# pylint: enable-msg=W0611
__all__ = ('FedoraServiceError', 'ServerError', 'AuthError', 'AppError',
'FedoraClientError', 'LoginRequiredError', 'DictContainer',
'FASError', 'CLAError', 'BodhiClientException',
'ProxyClient', 'FasProxyClient', 'BaseClient', 'OpenIdProxyClient',
'OpenIdBaseClient', 'AccountSystem', 'BodhiClient',
'Wiki')
|