Rev 6328: (gz) Remove deprecated parts of bzrlib.errors and other cleanups (Martin in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Nov 29 18:31:54 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6328 [merge]
revision-id: pqm at pqm.ubuntu.com-20111129183153-u0gz7nl7s0j208kt
parent: pqm at pqm.ubuntu.com-20111129180652-rkie44uu5l0nmp1n
parent: martin.packman at canonical.com-20111128174351-78pjisss4ebnc1z9
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2011-11-29 18:31:53 +0000
message:
(gz) Remove deprecated parts of bzrlib.errors and other cleanups (Martin
Packman)
modified:
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2011-11-24 15:43:18 +0000
+++ b/bzrlib/errors.py 2011-11-28 17:43:51 +0000
@@ -17,15 +17,6 @@
"""Exceptions for bzr, and reporting of them.
"""
-from bzrlib import (
- osutils,
- symbol_versioning,
- i18n,
- trace,
- )
-from bzrlib.i18n import gettext
-
-
# TODO: is there any value in providing the .args field used by standard
# python exceptions? A list of values with no names seems less useful
# to me.
@@ -102,12 +93,15 @@
# __str__() should always return a 'str' object
# never a 'unicode' object.
return s
- except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
- return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
- % (self.__class__.__name__,
- self.__dict__,
- getattr(self, '_fmt', None),
- e)
+ except Exception, e:
+ pass # just bind to 'e' for formatting below
+ else:
+ e = None
+ return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
+ % (self.__class__.__name__,
+ self.__dict__,
+ getattr(self, '_fmt', None),
+ e)
def __unicode__(self):
u = self._format()
@@ -136,22 +130,8 @@
"""Return format string for this exception or None"""
fmt = getattr(self, '_fmt', None)
if fmt is not None:
- i18n.install()
- unicode_fmt = unicode(fmt) #_fmt strings should be ascii
- if type(fmt) == unicode:
- trace.mutter("Unicode strings in error.fmt are deprecated")
- return gettext(unicode_fmt)
- fmt = getattr(self, '__doc__', None)
- if fmt is not None:
- symbol_versioning.warn("%s uses its docstring as a format, "
- "it should use _fmt instead" % self.__class__.__name__,
- DeprecationWarning)
- return fmt
- return 'Unprintable exception %s: dict=%r, fmt=%r' \
- % (self.__class__.__name__,
- self.__dict__,
- getattr(self, '_fmt', None),
- )
+ from bzrlib.i18n import gettext
+ return gettext(unicode(fmt)) # _fmt strings should be ascii
def __eq__(self, other):
if self.__class__ is not other.__class__:
@@ -170,39 +150,6 @@
internal_error = True
-class BzrNewError(BzrError):
- """Deprecated error base class."""
- # base classes should override the docstring with their human-
- # readable explanation
-
- def __init__(self, *args, **kwds):
- # XXX: Use the underlying BzrError to always generate the args
- # attribute if it doesn't exist. We can't use super here, because
- # exceptions are old-style classes in python2.4 (but new in 2.5).
- # --bmc, 20060426
- symbol_versioning.warn('BzrNewError was deprecated in bzr 0.13; '
- 'please convert %s to use BzrError instead'
- % self.__class__.__name__,
- DeprecationWarning,
- stacklevel=2)
- BzrError.__init__(self, *args)
- for key, value in kwds.items():
- setattr(self, key, value)
-
- def __str__(self):
- try:
- # __str__() should always return a 'str' object
- # never a 'unicode' object.
- s = self.__doc__ % self.__dict__
- if isinstance(s, unicode):
- return s.encode('utf8')
- return s
- except (TypeError, NameError, ValueError, KeyError), e:
- return 'Unprintable exception %s(%r): %r' \
- % (self.__class__.__name__,
- self.__dict__, e)
-
-
class AlreadyBuilding(BzrError):
_fmt = "The tree builder is already building a tree."
@@ -790,19 +737,6 @@
self.path = bzrdir.transport.clone('..').base
-class FileInWrongBranch(BzrError):
-
- _fmt = 'File "%(path)s" is not in branch %(branch_base)s.'
-
- # use PathNotChild instead
- @symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 3, 0)))
- def __init__(self, branch, path):
- BzrError.__init__(self)
- self.branch = branch
- self.branch_base = branch.base
- self.path = path
-
-
class UnsupportedFormatError(BzrError):
_fmt = "Unsupported branch format: %(format)s\nPlease run 'bzr upgrade'"
@@ -1296,17 +1230,6 @@
not_ancestor_id=not_ancestor_id)
-class AmbiguousBase(BzrError):
-
- def __init__(self, bases):
- symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
- "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
- msg = ("The correct base is unclear, because %s are all equally close"
- % ", ".join(bases))
- BzrError.__init__(self, msg)
- self.bases = bases
-
-
class NoCommits(BranchError):
_fmt = "Branch %(branch)s has no commits."
@@ -2079,22 +2002,6 @@
BzrMoveFailedError.__init__(self, from_path, to_path, extra)
-class BzrRemoveChangedFilesError(BzrError):
- """Used when user is trying to remove changed files."""
-
- _fmt = ("Can't safely remove modified or unknown files:\n"
- "%(changes_as_text)s"
- "Use --keep to not delete them, or --force to delete them regardless.")
-
- def __init__(self, tree_delta):
- symbol_versioning.warn(symbol_versioning.deprecated_in((2, 3, 0)) %
- "BzrRemoveChangedFilesError", DeprecationWarning, stacklevel=2)
- BzrError.__init__(self)
- self.changes_as_text = tree_delta.get_changes_as_text()
- #self.paths_as_string = '\n'.join(changed_files)
- #self.paths_as_string = '\n'.join([quotefn(p) for p in changed_files])
-
-
class BzrBadParameterNotString(BzrBadParameter):
_fmt = "Parameter %(param)s is not a string or unicode string."
@@ -3034,7 +2941,7 @@
from bzrlib.osutils import get_user_encoding
self.path = path
self.kind = kind
- self.user_encoding = osutils.get_user_encoding()
+ self.user_encoding = get_user_encoding()
class NoSuchConfig(BzrError):
@@ -3101,31 +3008,6 @@
BzrError.__init__(self, unknowns_str=", ".join(unknowns))
-class HookFailed(BzrError):
- """Raised when a pre_change_branch_tip hook function fails anything other
- than TipChangeRejected.
-
- Note that this exception is no longer raised, and the import is only left
- to be nice to code which might catch it in a plugin.
- """
-
- _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
- "%(traceback_text)s%(exc_value)s")
-
- def __init__(self, hook_stage, hook_name, exc_info, warn=True):
- if warn:
- symbol_versioning.warn("BzrError HookFailed has been deprecated "
- "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
- import traceback
- self.hook_stage = hook_stage
- self.hook_name = hook_name
- self.exc_info = exc_info
- self.exc_type = exc_info[0]
- self.exc_value = exc_info[1]
- self.exc_tb = exc_info[2]
- self.traceback_text = ''.join(traceback.format_tb(self.exc_tb))
-
-
class TipChangeRejected(BzrError):
"""A pre_change_branch_tip hook function may raise this to cleanly and
explicitly abort a change to a branch tip.
=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py 2011-11-11 12:08:56 +0000
+++ b/bzrlib/tests/test_errors.py 2011-11-28 17:15:29 +0000
@@ -349,13 +349,6 @@
self.assertEqual("The value 'foo' is not a valid value.",
str(error))
- def test_bzrnewerror_is_deprecated(self):
- class DeprecatedError(errors.BzrNewError):
- pass
- self.callDeprecated(['BzrNewError was deprecated in bzr 0.13; '
- 'please convert DeprecatedError to use BzrError instead'],
- DeprecatedError)
-
def test_bzrerror_from_literal_string(self):
# Some code constructs BzrError from a literal string, in which case
# no further formatting is done. (I'm not sure raising the base class
@@ -572,23 +565,6 @@
err = errors.UnknownRules(['foo', 'bar'])
self.assertEquals("Unknown rules detected: foo, bar.", str(err))
- def test_hook_failed(self):
- # Create an exc_info tuple by raising and catching an exception.
- try:
- 1/0
- except ZeroDivisionError:
- err = errors.HookFailed('hook stage', 'hook name', sys.exc_info(),
- warn=False)
- # GZ 2010-11-08: Should not store exc_info in exception instances, but
- # HookFailed is deprecated anyway and could maybe go.
- try:
- self.assertStartsWith(
- str(err), 'Hook \'hook name\' during hook stage failed:\n')
- self.assertEndsWith(
- str(err), 'integer division or modulo by zero')
- finally:
- del err
-
def test_tip_change_rejected(self):
err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
self.assertEquals(
@@ -759,12 +735,8 @@
def test_missing_format_string(self):
e = ErrorWithNoFormat(param='randomvalue')
- s = self.callDeprecated(
- ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
- lambda x: str(x), e)
- ## s = str(e)
- self.assertEqual(s,
- "This class has a docstring but no format string.")
+ self.assertStartsWith(str(e),
+ "Unprintable exception ErrorWithNoFormat")
def test_mismatched_format_args(self):
# Even though ErrorWithBadFormat's format string does not match the
More information about the bazaar-commits
mailing list