[open-ils-commits] r1032 - in servres/trunk/conifer: integration libsystems syrup (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Oct 2 19:54:43 EDT 2010


Author: gfawcett
Date: 2010-10-02 19:54:42 -0400 (Sat, 02 Oct 2010)
New Revision: 1032

Added:
   servres/trunk/conifer/libsystems/ezproxy.py
Modified:
   servres/trunk/conifer/integration/uwindsor.py
   servres/trunk/conifer/syrup/integration.py
   servres/trunk/conifer/syrup/models.py
Log:
add 'proxify_url' to integration API; provide ezproxy implementation for Leddy.

Modified: servres/trunk/conifer/integration/uwindsor.py
===================================================================
--- servres/trunk/conifer/integration/uwindsor.py	2010-10-02 20:11:59 UTC (rev 1031)
+++ servres/trunk/conifer/integration/uwindsor.py	2010-10-02 23:54:42 UTC (rev 1032)
@@ -2,6 +2,7 @@
 
 from datetime import date
 from django.conf import settings
+from conifer.libsystems import ezproxy
 from conifer.libsystems.evergreen.support import initialize, E1
 from conifer.libsystems import marcxml as M
 from conifer.libsystems.evergreen import item_status as I
@@ -169,3 +170,18 @@
     for m in memberships:
         m['role'] = decode_role(m['role'])
     return memberships
+
+#--------------------------------------------------
+# proxy server integration
+
+ezproxy_service = ezproxy.EZProxyService(
+    settings.UWINDSOR_EZPROXY_HOST,
+    settings.UWINDSOR_EZPROXY_PASSWORD)
+
+def proxify_url(url):
+    """
+    Given a URL, determine whether the URL needs to be passed through
+    a reverse-proxy, and if so, return a modified URL that includes
+    the proxy. If not, return None.
+    """
+    return ezproxy_service.proxify(url)

Added: servres/trunk/conifer/libsystems/ezproxy.py
===================================================================
--- servres/trunk/conifer/libsystems/ezproxy.py	                        (rev 0)
+++ servres/trunk/conifer/libsystems/ezproxy.py	2010-10-02 23:54:42 UTC (rev 1032)
@@ -0,0 +1,48 @@
+import re
+from xml.etree import ElementTree
+from urllib    import urlencode
+from urllib2   import *
+
+
+class EZProxyService(object):
+
+    def __init__(self, host, password, strict=False):
+        self.host = host
+        self.password = password
+        self.query_url = 'http://%s/proxy_url' % host
+        self.strict = strict
+
+    def proxify(self, url):
+        if not url:             # empty or blank
+            return None
+        if not self.strict:
+            # If the hostname is in the URL, assume it has already
+            # been proxified.
+            if self.host in url:
+                return None
+        xml = ('<proxy_url_request password="%s">'
+               '<urls><url>%s</url>'
+               '</urls></proxy_url_request>') % (
+            self.password, url)
+        data = urlencode({'xml':xml})
+        resp = urlopen(self.query_url, data).read()
+        root = ElementTree.fromstring(resp)
+        node = root.find('proxy_urls/url')
+        needs_proxy = (node.attrib.get('proxy') == 'true')
+        if needs_proxy:
+            return self.translate(url, **node.attrib)
+
+    pat = re.compile(r'(.*://[^/]+)(.*)$')
+
+    def translate(self, url, **kwargs):
+        prefix, suffix = self.pat.match(url).groups()
+        return ''.join((prefix, '.', self.host, suffix))
+    
+
+
+host = 'ezproxy.uwindsor.ca'
+pwd = 'leddy'
+s = EZProxyService(host, pwd)
+
+print s.proxify('http://jstor.org/')
+print s.proxify('http://jstor.org.ezproxy.uwindsor.ca/')

Modified: servres/trunk/conifer/syrup/integration.py
===================================================================
--- servres/trunk/conifer/syrup/integration.py	2010-10-02 20:11:59 UTC (rev 1031)
+++ servres/trunk/conifer/syrup/integration.py	2010-10-02 23:54:42 UTC (rev 1032)
@@ -120,3 +120,13 @@
     'external_person_lookup,' is used by Syrup to fetch the personal
     information when needed.
     """
+
+ at disable
+def proxify_url(url):
+    """
+    Given a URL, determine whether the URL needs to be passed through
+    a reverse-proxy, and if so, return a modified URL that includes
+    the proxy. If not, return None.
+    """
+
+                  

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2010-10-02 20:11:59 UTC (rev 1031)
+++ servres/trunk/conifer/syrup/models.py	2010-10-02 23:54:42 UTC (rev 1032)
@@ -565,6 +565,8 @@
             maybe_bib = callhook('marc_to_bib_id', self.marcxml)
             if maybe_bib:
                 self.bib_id = maybe_bib
+        # proxify the item's URL if necessary
+        self.url = callhook('proxify_url', self.url) or self.url
         super(Item, self).save(*args, **kwargs)
 
     #--------------------------------------------------



More information about the open-ils-commits mailing list