[xy] fail assertion only if existing prefix is being changed (closes #139999)

authorNicolas Chauvat <nicolas.chauvat@logilab.fr>
changesete38902402af5
branchdefault
phasepublic
hiddenno
parent revision#153169d841bd Added tag for version 0.37.0 on changeset 25d0bff4eb9d
child revision#99d6f01f853d [schema] add a warning to avoid a potential silent bug (follows #109207)
files modified by this revision
xy.py
# HG changeset patch
# User Nicolas Chauvat <nicolas.chauvat@logilab.fr>
# Date 1366961649 -7200
# Fri Apr 26 09:34:09 2013 +0200
# Node ID e38902402af59539fc64407186cc2bfcfaae6315
# Parent 153169d841bdeb1e091e58c909c938a93aa5a0e6
[xy] fail assertion only if existing prefix is being changed (closes #139999)

diff --git a/xy.py b/xy.py
@@ -34,12 +34,14 @@
1      def register_prefix(self, prefix, xmlns, overwrite=False):
2          if ':' in prefix:
3              warn('[yams 0.30] register_prefix arguments has been switched to '
4                   '(prefix, xmlns)', DeprecationWarning, stacklevel=2)
5              prefix, xmlns = xmlns, prefix
6 -        if not overwrite:
7 -            assert not prefix in self.prefixes, 'prefix already defined'
8 +        if not overwrite and prefix in self.prefixes \
9 +                and self.prefixes.get(prefix) != xmlns:
10 +                raise Exception('prefix %r already defined with different value'
11 +                                % prefix)
12          self.prefixes[prefix] = xmlns
13 
14      def _norm_yams_key(self, yamssnippet):
15          parts = yamssnippet.split(' ')
16          if len(parts) == 1: