From 863fff7042a6ab8f23538d03d3c9faa3beb7a8ca Mon Sep 17 00:00:00 2001 From: hpk Date: Tue, 23 Sep 2008 08:29:17 +0200 Subject: [PATCH] [svn r58360] factor import of xml into one method to deal more gracefully with implementations that don't have expat. --HG-- branch : trunk --- py/path/svn/wccommand.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/py/path/svn/wccommand.py b/py/path/svn/wccommand.py index c0542aa03..016be8cbc 100644 --- a/py/path/svn/wccommand.py +++ b/py/path/svn/wccommand.py @@ -9,8 +9,6 @@ svn-Command based Implementation of a Subversion WorkingCopy Path. """ import os, sys, time, re, calendar -from xml.dom import minidom -from xml.parsers.expat import ExpatError import py from py.__.path import common from py.__.path.svn import cache @@ -481,13 +479,10 @@ if verbose is True, then the LogEntry instances also know which files changed. 'svn log --xml %s %s %s "%s"' % ( rev_opt, verbose_opt, auth_opt, self.strpath)) - from xml.dom import minidom - from xml.parsers.expat import ExpatError + minidom,ExpatError = importxml() try: tree = minidom.parse(stdout) except ExpatError: - # XXX not entirely sure about this exception... shouldn't it be - # some py.error.* something? raise ValueError('no such revision') result = [] for logentry in filter(None, tree.firstChild.childNodes): @@ -645,6 +640,7 @@ class XMLWCStatus(WCStatus): # unchanged ones in the status object so this is far from ideal rootstatus = WCStatus(rootwcpath, rev, modrev, author) update_rev = None + minidom, ExpatError = importxml() try: doc = minidom.parseString(data) except ExpatError, e: @@ -809,3 +805,10 @@ def make_recursive_propdict(wcroot, def error_enhance((cls, error, tb)): raise cls, error, tb +def importxml(cache=[]): + if cache: + return cache + from xml.dom import minidom + from xml.parsers.expat import ExpatError + cache.extend([minidom, ExpatError]) + return cache