Changeset 404:96838d29a13a
- Timestamp:
- 06/04/08 12:16:11
(2 years ago)
- Author:
- Brian Warner <warner@allmydata.com>
- branch:
- default
- Message:
fix registerReference() with both name= and furlFile= when the file already exists, closes #64
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r402 |
r404 |
|
| 1 | 1 | 2008-06-04 Brian Warner <warner@allmydata.com> |
|---|
| | 2 | |
|---|
| | 3 | * foolscap/pb.py (Tub.registerReference): fix an exception that |
|---|
| | 4 | occurs if you call this with both name= and furlFile= and the |
|---|
| | 5 | furlFile already exists. Also prohibit attempts to change the name |
|---|
| | 6 | to something other than what is in the furlFile. Thanks to Brian |
|---|
| | 7 | Granger for the patch. Closes #64. |
|---|
| 2 | 8 | |
|---|
| 3 | 9 | * foolscap/_version.py (verstr): bump revision to 0.2.7+ while |
|---|
| r403 |
r404 |
|
| 10 | 10 | from foolscap import util |
|---|
| 11 | 11 | from foolscap.referenceable import SturdyRef |
|---|
| 12 | | from foolscap.tokens import PBError, BananaError, WrongTubIdError |
|---|
| | 12 | from foolscap.tokens import PBError, BananaError, WrongTubIdError, \ |
|---|
| | 13 | WrongNameError |
|---|
| 13 | 14 | from foolscap.reconnector import Reconnector |
|---|
| 14 | 15 | from foolscap.logging import log as flog |
|---|
| … | … | |
| 668 | 669 | pass |
|---|
| 669 | 670 | if oldfurl: |
|---|
| | 671 | sr = SturdyRef(oldfurl) |
|---|
| 670 | 672 | if name is None: |
|---|
| 671 | | sr = SturdyRef(oldfurl) |
|---|
| 672 | 673 | name = sr.name |
|---|
| 673 | 674 | if self.tubID != sr.tubID: |
|---|
| 674 | | raise WrongTubIdError("I cannot keep using the old FURL (%s)" |
|---|
| | 675 | raise WrongTubIdError("I cannot keep using the old FURL from %s" |
|---|
| 675 | 676 | " because it does not have the same" |
|---|
| 676 | 677 | " TubID as I do (%s)" % |
|---|
| 677 | | (oldfurl, self.tubID)) |
|---|
| | 678 | (furlFile, self.tubID)) |
|---|
| | 679 | if name != sr.name: |
|---|
| | 680 | raise WrongNameError("I cannot keep using the old FURL from %s" |
|---|
| | 681 | " because you called registerReference" |
|---|
| | 682 | " with a new name (%s)" % |
|---|
| | 683 | (furlFile, name)) |
|---|
| 678 | 684 | name = self._assignName(ref, name) |
|---|
| 679 | 685 | assert name |
|---|
| r71 |
r404 |
|
| 3 | 3 | from twisted.trial import unittest |
|---|
| 4 | 4 | |
|---|
| 5 | | import weakref, gc |
|---|
| | 5 | import os, weakref, gc |
|---|
| 6 | 6 | from foolscap import UnauthenticatedTub |
|---|
| 7 | 7 | from foolscap.test.common import HelperTarget |
|---|
| | 8 | from foolscap.tokens import WrongNameError |
|---|
| 8 | 9 | |
|---|
| 9 | 10 | class Registration(unittest.TestCase): |
|---|
| … | … | |
| 51 | 52 | url = tub.registerReference(target) |
|---|
| 52 | 53 | |
|---|
| | 54 | def test_duplicate(self): |
|---|
| | 55 | basedir = "test_registration" |
|---|
| | 56 | os.makedirs(basedir) |
|---|
| | 57 | ff = os.path.join(basedir, "duplicate.furl") |
|---|
| | 58 | t1 = HelperTarget() |
|---|
| | 59 | tub = UnauthenticatedTub() |
|---|
| | 60 | tub.setLocation("bogus:1234567") |
|---|
| | 61 | u1 = tub.registerReference(t1, "name", furlFile=ff) |
|---|
| | 62 | u2 = tub.registerReference(t1, "name", furlFile=ff) |
|---|
| | 63 | self.failUnlessEqual(u1, u2) |
|---|
| | 64 | self.failUnlessRaises(WrongNameError, |
|---|
| | 65 | tub.registerReference, t1, "newname", furlFile=ff) |
|---|
| | 66 | |
|---|
| | 67 | |
|---|
| | 68 | |
|---|
| r261 |
r404 |
|
| 116 | 116 | class WrongTubIdError(Exception): |
|---|
| 117 | 117 | """getReference(furlFile=) used a FURL with a different TubID""" |
|---|
| | 118 | class WrongNameError(Exception): |
|---|
| | 119 | """getReference(furlFule=) used a FURL with a different name""" |
|---|
| 118 | 120 | |
|---|
| 119 | 121 | |
|---|