28
28
from cStringIO import StringIO
33
from bzrlib.errors import BzrError, BzrCheckError
34
from bzrlib.branch import Branch, BZR_BRANCH_FORMAT
35
from bzrlib.trace import mutter
36
from bzrlib.xml import serializer_v4
39
ENABLE_URLGRABBER = False
41
from bzrlib.errors import BzrError, NoSuchRevision
43
class GetFailed(BzrError):
44
def __init__(self, url, status):
45
BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
31
from errors import BzrError, BzrCheckError
32
from branch import Branch, BZR_BRANCH_FORMAT
33
from trace import mutter
35
# velocitynet.com.au transparently proxies connections and thereby
36
# breaks keep-alive -- sucks!
39
ENABLE_URLGRABBER = True
49
42
if ENABLE_URLGRABBER:
50
import util.urlgrabber
51
import util.urlgrabber.keepalive
52
util.urlgrabber.keepalive.DEBUG = 0
44
import urlgrabber.keepalive
45
urlgrabber.keepalive.DEBUG = 0
53
46
def get_url(path, compressed=False):
58
51
mutter("grab url %s" % url)
59
url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
60
if url_f.status != 200:
61
raise GetFailed(url, url_f.status)
52
url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
98
89
except urllib2.URLError:
101
scheme, host, path = list(urlparse.urlparse(url))[:3]
102
# discard params, query, fragment
104
# strip off one component of the path component
105
idx = path.rfind('/')
106
if idx == -1 or path == '/':
107
raise BzrError('no branch root found for URL %s'
108
' or enclosing directories'
111
url = urlparse.urlunparse((scheme, host, path, '', '', ''))
95
raise BzrError('no branch root found for URL %s' % orig_url)
161
147
def get_revision(self, revision_id):
163
revf = self.revision_store[revision_id]
165
raise NoSuchRevision(self, revision_id)
166
r = serializer_v4.read_revision(revf)
148
from bzrlib.revision import Revision
149
from bzrlib.xml import unpack_xml
150
revf = self.revision_store[revision_id]
151
r = unpack_xml(Revision, revf)
167
152
if r.revision_id != revision_id:
168
153
raise BzrCheckError('revision stored as {%s} actually contains {%s}'
169
154
% (revision_id, r.revision_id))