/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/errors.py

  • Committer: Jelmer Vernooij
  • Date: 2020-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Exceptions for bzr, and reporting of them.
18
18
"""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
 
22
from .sixish import (
 
23
    PY3,
 
24
    )
20
25
 
21
26
# TODO: is there any value in providing the .args field used by standard
22
27
# python exceptions?   A list of values with no names seems less useful
103
108
               getattr(self, '_fmt', None),
104
109
               err)
105
110
 
106
 
    __str__ = _format
 
111
    if PY3:
 
112
        __str__ = _format
 
113
    else:
 
114
        def __str__(self):
 
115
            return self._format().encode('utf-8')
 
116
 
 
117
        __unicode__ = _format
107
118
 
108
119
    def __repr__(self):
109
120
        return '%s(%s)' % (self.__class__.__name__, str(self))
171
182
        self.transport = transport
172
183
 
173
184
 
 
185
class InvalidEntryName(InternalBzrError):
 
186
 
 
187
    _fmt = "Invalid entry name: %(name)s"
 
188
 
 
189
    def __init__(self, name):
 
190
        BzrError.__init__(self)
 
191
        self.name = name
 
192
 
 
193
 
174
194
class InvalidRevisionNumber(BzrError):
175
195
 
176
196
    _fmt = "Invalid revision number %(revno)s"
563
583
        self.format = format
564
584
 
565
585
 
 
586
class LineEndingError(BzrError):
 
587
 
 
588
    _fmt = ("Line ending corrupted for file: %(file)s; "
 
589
            "Maybe your files got corrupted in transport?")
 
590
 
 
591
    def __init__(self, file):
 
592
        self.file = file
 
593
 
 
594
 
566
595
class IncompatibleFormat(BzrError):
567
596
 
568
597
    _fmt = "Format %(format)s is not compatible with .bzr version %(controldir)s."
930
959
        self.revision_id = revision_id
931
960
 
932
961
 
 
962
class InvalidRevisionSpec(BzrError):
 
963
 
 
964
    _fmt = ("Requested revision: '%(spec)s' does not exist in branch:"
 
965
            " %(branch_url)s%(extra)s")
 
966
 
 
967
    def __init__(self, spec, branch, extra=None):
 
968
        BzrError.__init__(self, branch=branch, spec=spec)
 
969
        self.branch_url = getattr(branch, 'user_url', str(branch))
 
970
        if extra:
 
971
            self.extra = '\n' + str(extra)
 
972
        else:
 
973
            self.extra = ''
 
974
 
 
975
 
933
976
class AppendRevisionsOnlyViolation(BzrError):
934
977
 
935
978
    _fmt = ('Operation denied because it would change the main history,'
1280
1323
        TransportError.__init__(self, msg, orig_error=orig_error)
1281
1324
 
1282
1325
 
1283
 
class UnexpectedHttpStatus(InvalidHttpResponse):
1284
 
 
1285
 
    _fmt = "Unexpected HTTP status %(code)d for %(path)s: %(extra)s"
1286
 
 
1287
 
    def __init__(self, path, code, extra=None):
1288
 
        self.path = path
1289
 
        self.code = code
1290
 
        self.extra = extra or ''
1291
 
        full_msg = 'status code %d unexpected' % code
1292
 
        if extra is not None:
1293
 
            full_msg += ': ' + extra
1294
 
        InvalidHttpResponse.__init__(
1295
 
            self, path, full_msg)
1296
 
 
1297
 
 
1298
 
class BadHttpRequest(UnexpectedHttpStatus):
1299
 
 
1300
 
    _fmt = "Bad http request for %(path)s: %(reason)s"
1301
 
 
1302
 
    def __init__(self, path, reason):
1303
 
        self.path = path
1304
 
        self.reason = reason
1305
 
        TransportError.__init__(self, reason)
1306
 
 
1307
 
 
1308
1326
class InvalidHttpRange(InvalidHttpResponse):
1309
1327
 
1310
1328
    _fmt = "Invalid http range %(range)r for %(path)s: %(msg)s"