summaryrefslogtreecommitdiff
path: root/qpid/python
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2008-05-06 18:31:11 +0000
committerRafael H. Schloming <rhs@apache.org>2008-05-06 18:31:11 +0000
commit495e58750c29364c6b7f48210a55eca32e3340c8 (patch)
treedbf670220b39fc61da172914dc2346ee4900497a /qpid/python
parente1d873e3b4528141b9401bad9070bc205de40504 (diff)
downloadqpid-python-495e58750c29364c6b7f48210a55eca32e3340c8.tar.gz
QPID-1033: made loading of the spec file not fail if the results cannot be cached, e.g. due to an unwritable directory
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@653875 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/python')
-rw-r--r--qpid/python/qpid/spec010.py14
-rw-r--r--qpid/python/tests/spec010.py12
2 files changed, 23 insertions, 3 deletions
diff --git a/qpid/python/qpid/spec010.py b/qpid/python/qpid/spec010.py
index 03f60edc4e..1668729876 100644
--- a/qpid/python/qpid/spec010.py
+++ b/qpid/python/qpid/spec010.py
@@ -621,6 +621,7 @@ class Loader:
def load(xml):
fname = xml + ".pcl"
+
if os.path.exists(fname) and mtime(fname) > mtime(__file__):
file = open(fname, "r")
s = cPickle.load(file)
@@ -630,7 +631,14 @@ def load(xml):
s = doc["amqp"].dispatch(Loader())
s.register()
s.resolve()
- file = open(fname, "w")
- cPickle.dump(s, file)
- file.close()
+
+ try:
+ file = open(fname, "w")
+ except IOError:
+ file = None
+
+ if file:
+ cPickle.dump(s, file)
+ file.close()
+
return s
diff --git a/qpid/python/tests/spec010.py b/qpid/python/tests/spec010.py
index ff29bd8cea..b08ad5e925 100644
--- a/qpid/python/tests/spec010.py
+++ b/qpid/python/tests/spec010.py
@@ -17,6 +17,7 @@
# under the License.
#
+import os, tempfile, shutil, stat
from unittest import TestCase
from qpid.spec010 import load
from qpid.codec010 import Codec, StringCodec
@@ -70,3 +71,14 @@ class SpecTest(TestCase):
xid.encode(sc, st)
assert sc.encoded == '\x00\x00\x00\x10\x06\x04\x07\x00\x00\x00\x00\x00\x03gid\x03bid'
assert xid.decode(sc).__dict__ == st.__dict__
+
+ def testLoadReadOnly(self):
+ spec = "amqp.0-10-qpid-errata.xml"
+ f = testrunner.get_spec_file(spec)
+ dest = tempfile.mkdtemp()
+ shutil.copy(f, dest)
+ shutil.copy(os.path.join(os.path.dirname(f), "amqp.0-10.dtd"), dest)
+ os.chmod(dest, stat.S_IRUSR | stat.S_IXUSR)
+ fname = os.path.join(dest, spec)
+ load(fname)
+ assert not os.path.exists("%s.pcl" % fname)