From b58bdd5b07e2525c240369a069dd787ab73b5b62 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 5 Nov 2012 15:55:06 +0100 Subject: [PATCH] Use requests library for the initial WAPI connection. --- pytahoe/__init__.py | 17 ++++++----------- test.py | 3 ++- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pytahoe/__init__.py b/pytahoe/__init__.py index dd69c38..1d5ed5e 100644 --- a/pytahoe/__init__.py +++ b/pytahoe/__init__.py @@ -1,4 +1,4 @@ -import urllib, urllib2, json, time, os, re, requests +import json, time, os, re, requests try: from fs.contrib.tahoelafs import TahoeLAFS @@ -35,17 +35,12 @@ class Filesystem: url = url[:-1] try: - result = urllib.urlopen("%s/statistics?t=json" % url).read() - except urllib.URLError: - raise FilesystemException("The provided WAPI URL is not reachable.") - - try: - data = json.loads(result) - except ValueError: - raise FilesystemException("The provided WAPI URL is either not running Tahoe-LAFS, or running a version that is too old.") + data = requests.get("%s/statistics?t=json" % url).json + except requests.exceptions.RequestException: + raise FilesystemException("The provided WAPI URL is either not reachable, or not running a recent version of Tahoe-LAFS.") - if "node.uptime" not in data['stats']: - raise FilesystemException("The provided WAPI URL is either not running Tahoe-LAFS, or running a version that is too old.") + if data is None: + raise FilesystemException("The provided URL is not running a recent version of Tahoe-LAFS.") self.url = url self.start_date = time.time() - data['stats']['node.uptime'] diff --git a/test.py b/test.py index b3e9d01..a34dd5d 100644 --- a/test.py +++ b/test.py @@ -1,10 +1,11 @@ import pytahoe fs = pytahoe.Filesystem("http://localhost:3456/") +print fs #tdir = fs.Directory("URI:DIR2:jjw572jvowd473fo2n7rw6uiai:hloglrouhwgjpubcpyq5nrb4ezyijdfiboe3hquadgzjrmkdikxa") #print tdir #for name, item in tdir.children.iteritems(): # print "%s: %s" % (name, item) #print fs.create_directory().mount("test") -print fs.upload("test.py") +#print fs.upload("test.py")