[svn r57228] fix always-true assertion
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									4549e188da
								
							
						
					
					
						commit
						9ceb61056e
					
				| 
						 | 
					@ -30,7 +30,7 @@ class Linker(object):
 | 
				
			||||||
        return LazyHref(self, linkid)
 | 
					        return LazyHref(self, linkid)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def set_link(self, linkid, target):
 | 
					    def set_link(self, linkid, target):
 | 
				
			||||||
        assert (linkid not in self._linkid2target,
 | 
					        assert linkid not in self._linkid2target, (
 | 
				
			||||||
                'linkid %r already used' % (linkid,))
 | 
					                'linkid %r already used' % (linkid,))
 | 
				
			||||||
        self._linkid2target[linkid] = target
 | 
					        self._linkid2target[linkid] = target
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,11 +63,8 @@ class TempLinker(object):
 | 
				
			||||||
    def __init__(self):
 | 
					    def __init__(self):
 | 
				
			||||||
        self._linkid2target = {}
 | 
					        self._linkid2target = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_lazyhref(self, linkid, anchor=None):
 | 
					    def get_lazyhref(self, linkid):
 | 
				
			||||||
        href = '%s://%s' % (TEMPLINK_PROTO, linkid)
 | 
					        return '%s://%s' % (TEMPLINK_PROTO, linkid)
 | 
				
			||||||
        if anchor:
 | 
					 | 
				
			||||||
            href += '#' + anchor
 | 
					 | 
				
			||||||
        return href
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def set_link(self, linkid, target):
 | 
					    def set_link(self, linkid, target):
 | 
				
			||||||
        assert linkid not in self._linkid2target
 | 
					        assert linkid not in self._linkid2target
 | 
				
			||||||
| 
						 | 
					@ -75,18 +72,13 @@ class TempLinker(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_target(self, tempurl, fromlocation=None):
 | 
					    def get_target(self, tempurl, fromlocation=None):
 | 
				
			||||||
        assert tempurl.startswith('%s://' % (TEMPLINK_PROTO,))
 | 
					        assert tempurl.startswith('%s://' % (TEMPLINK_PROTO,))
 | 
				
			||||||
        anchor = None
 | 
					        linkid = '://'.join(tempurl.split('://')[1:])
 | 
				
			||||||
        if '#' in tempurl:
 | 
					 | 
				
			||||||
            tempurl, anchor = tempurl.split('#', 1)
 | 
					 | 
				
			||||||
        linkid = tempurl.split('://', 1)[1]
 | 
					 | 
				
			||||||
        linktarget = self._linkid2target[linkid]
 | 
					        linktarget = self._linkid2target[linkid]
 | 
				
			||||||
        if fromlocation is not None:
 | 
					        if fromlocation is not None:
 | 
				
			||||||
            linktarget = relpath(fromlocation, linktarget)
 | 
					            linktarget = relpath(fromlocation, linktarget)
 | 
				
			||||||
        if anchor is not None:
 | 
					 | 
				
			||||||
            linktarget += '#' + anchor
 | 
					 | 
				
			||||||
        return linktarget
 | 
					        return linktarget
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    _reg_tempurl = py.std.re.compile('(["\'])(%s:\/\/[^"\'\s#]*)(["\'#])' % (
 | 
					    _reg_tempurl = py.std.re.compile('["\'](%s:\/\/[^"\s]*)["\']' % (
 | 
				
			||||||
                                      TEMPLINK_PROTO,))
 | 
					                                      TEMPLINK_PROTO,))
 | 
				
			||||||
    def replace_dirpath(self, dirpath, stoponerrors=True):
 | 
					    def replace_dirpath(self, dirpath, stoponerrors=True):
 | 
				
			||||||
        """ replace temporary links in all html files in dirpath and below """
 | 
					        """ replace temporary links in all html files in dirpath and below """
 | 
				
			||||||
| 
						 | 
					@ -96,19 +88,16 @@ class TempLinker(object):
 | 
				
			||||||
                match = self._reg_tempurl.search(html)
 | 
					                match = self._reg_tempurl.search(html)
 | 
				
			||||||
                if not match:
 | 
					                if not match:
 | 
				
			||||||
                    break
 | 
					                    break
 | 
				
			||||||
                tempurl = match.group(2)
 | 
					                tempurl = match.group(1)
 | 
				
			||||||
                pre = match.group(1)
 | 
					 | 
				
			||||||
                post = match.group(3)
 | 
					 | 
				
			||||||
                try:
 | 
					                try:
 | 
				
			||||||
                    html = html.replace(match.group(0), pre +
 | 
					                    html = html.replace('"' + tempurl + '"',
 | 
				
			||||||
                                        self.get_target(tempurl,
 | 
					                                        '"' + self.get_target(tempurl,
 | 
				
			||||||
                                              fpath.relto(dirpath)) + post)
 | 
					                                                fpath.relto(dirpath)) + '"')
 | 
				
			||||||
                except KeyError:
 | 
					                except KeyError:
 | 
				
			||||||
                    if stoponerrors:
 | 
					                    if stoponerrors:
 | 
				
			||||||
                        raise
 | 
					                        raise
 | 
				
			||||||
                    html = html.replace(match.group(0), pre +
 | 
					                    html = html.replace('"' + tempurl + '"',
 | 
				
			||||||
                                        'apigen.notfound://%s' % (tempurl,) +
 | 
					                                        '"apigen.notfound://%s"' % (tempurl,))
 | 
				
			||||||
                                        post)
 | 
					 | 
				
			||||||
            fpath.write(html)
 | 
					            fpath.write(html)
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue