~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remotebranch.py

  • Committer: Aaron Bentley
  • Date: 2005-07-26 14:06:11 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 982.
  • Revision ID: abentley@panoramicfeedback.com-20050726140611-403e366f3c79c1f1
Fixed python invocation

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from cStringIO import StringIO
29
29
import urllib2
30
30
 
31
 
from bzrlib.errors import BzrError, BzrCheckError
32
 
from bzrlib.branch import Branch, BZR_BRANCH_FORMAT_5
33
 
from bzrlib.trace import mutter
34
 
from bzrlib.xml5 import serializer_v5
 
31
from errors import BzrError, BzrCheckError
 
32
from branch import Branch, BZR_BRANCH_FORMAT
 
33
from trace import mutter
35
34
 
36
35
# velocitynet.com.au transparently proxies connections and thereby
37
36
# breaks keep-alive -- sucks!
38
37
 
39
38
 
40
 
ENABLE_URLGRABBER = False
41
 
 
42
 
from bzrlib.errors import BzrError, NoSuchRevision
43
 
 
44
 
class GetFailed(BzrError):
45
 
    def __init__(self, url, status):
46
 
        BzrError.__init__(self, "Get %s failed with status %s" % (url, status))
47
 
        self.url = url
48
 
        self.status = status
 
39
ENABLE_URLGRABBER = True
 
40
 
49
41
 
50
42
if ENABLE_URLGRABBER:
51
 
    import util.urlgrabber
52
 
    import util.urlgrabber.keepalive
53
 
    util.urlgrabber.keepalive.DEBUG = 0
 
43
    import urlgrabber
 
44
    import urlgrabber.keepalive
 
45
    urlgrabber.keepalive.DEBUG = 0
54
46
    def get_url(path, compressed=False):
55
47
        try:
56
48
            url = path
57
49
            if compressed:
58
50
                url += '.gz'
59
51
            mutter("grab url %s" % url)
60
 
            url_f = util.urlgrabber.urlopen(url, keepalive=1, close_connection=0)
61
 
            if url_f.status != 200:
62
 
                raise GetFailed(url, url_f.status)
 
52
            url_f = urlgrabber.urlopen(url, keepalive=1, close_connection=0)
63
53
            if not compressed:
64
54
                return url_f
65
55
            else:
90
80
            fmt = ff.read()
91
81
            ff.close()
92
82
 
93
 
            if fmt != BZR_BRANCH_FORMAT_5:
 
83
            fmt = fmt.rstrip('\r\n')
 
84
            if fmt != BZR_BRANCH_FORMAT.rstrip('\r\n'):
94
85
                raise BzrError("sorry, branch format %r not supported at url %s"
95
86
                               % (fmt, url))
96
87
            
155
146
 
156
147
    def get_revision(self, revision_id):
157
148
        from bzrlib.revision import Revision
158
 
        try:
159
 
            revf = self.revision_store[revision_id]
160
 
        except KeyError:
161
 
            raise NoSuchRevision(self, revision_id)
162
 
        r = serializer_v5.read_revision(revf)
 
149
        from bzrlib.xml import unpack_xml
 
150
        revf = self.revision_store[revision_id]
 
151
        r = unpack_xml(Revision, revf)
163
152
        if r.revision_id != revision_id:
164
153
            raise BzrCheckError('revision stored as {%s} actually contains {%s}'
165
154
                                % (revision_id, r.revision_id))
178
167
        
179
168
    def __getitem__(self, fileid):
180
169
        p = self._path(fileid)
181
 
        try:
182
 
            return get_url(p, compressed=True)
183
 
        except:
184
 
            raise KeyError(fileid)
 
170
        return get_url(p, compressed=True)
185
171
    
186
172
 
187
173