Changeset 8529


Ignore:
Timestamp:
17/08/12 10:40:10 (7 years ago)
Author:
mnagni
Message:

Incomplete - # 22528: Migration of FAtCat Open Search link for HPFeld
 http://team.ceda.ac.uk/trac/ceda/ticket/22528

If necessary request data to fatcatOS using a proxy (configure in hpfos.HPFos.osImpl.myImpl)

Location:
mauRepo/HPFos/trunk/hpfos/HPFos/osImpl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/HPFos/trunk/hpfos/HPFos/osImpl/commons.py

    r8523 r8529  
    3232''' 
    3333 
    34  
    35 from httplib import HTTPConnection 
    3634from xml.etree.ElementTree import XML 
     35import urllib2 
    3736 
    3837def return_not_none_text(element): 
     
    4140    return element.text 
    4241 
    43 def get_document(host, path, port = 80): 
    44     conn = HTTPConnection(host = host, port = port) 
    45     conn.connect() 
    46     conn.request('GET', path) 
    47     res = conn.getresponse() 
    48     xml_doc = res.read() 
    49     conn.close() 
    50     return xml_doc 
     42def get_document(host, path, port = 80, proxy = None): 
     43    if proxy is not None: 
     44        proxy = urllib2.ProxyHandler({'http': proxy}) 
     45        opener = urllib2.build_opener(proxy) 
     46        urllib2.install_opener(opener) 
     47    connect_to = 'http://%s:%s%s' % (host, port, path) 
     48    response = urllib2.urlopen(connect_to) 
     49    return  response.read() 
    5150 
    5251def get_xml_document(source): 
  • mauRepo/HPFos/trunk/hpfos/HPFos/osImpl/myimpl.py

    r8525 r8529  
    5353from hpfos import __version__, __revision__ 
    5454from ceda_markup.atom.atom import ATOM_NAMESPACE 
    55 from hpfos.HPFos.osImpl.commons import get_document, get_xml_document,\ 
    56     return_not_none_text 
    57 from xml.etree.ElementTree import _ElementInterface, ElementTree 
     55from hpfos.HPFos.osImpl.commons import get_document, get_xml_document 
    5856from ceda_markup.opensearch.os_request import OpenSearchDescription, OS_NAMESPACE 
     57from xml.etree.ElementTree import _ElementInterface 
    5958 
    6059GUID = 'guid' 
     
    6766FATCAT_HOST = 'citest1.jc.rl.ac.uk' 
    6867FATCAT_ROOT_PATH = 'fatcatOS' 
     68PROXY_URL = 'http://wwwcache.rl.ac.uk:8080' 
    6969 
    7070CEDA_TITLE = 'ceda_title' 
     
    287287     
    288288def find_fatcat_atom_entity(host = 'localhost', path = '', port = 80):     
    289     source = get_document(host, path, port) 
     289    source = get_document(host, path, port, proxy = PROXY_URL) 
    290290    return get_xml_document(source) 
Note: See TracChangeset for help on using the changeset viewer.