Пример #1
0
    def index(self):
        if "latitude" in request.params and "longitude" in request.params:
            latitude = float(request.params["latitude"])
            longitude = float(request.params["longitude"])
        if "easting" in request.params:
            easting = float(request.params["easting"])
        if "northing" in request.params:
            northing = float(request.params["northing"])

        queryString = "http://wms.geo.admin.ch/?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&SRS=EPSG:21781"
        queryString = (
            queryString
            + "&BBOX="
            + str(easting - 1.0)
            + ","
            + str(northing - 1.0)
            + ","
            + str(easting + 1.0)
            + ","
            + str(northing + 1.0)
            + ""
        )
        queryString = (
            queryString
            + "&WIDTH=2&HEIGHT=2&QUERY_LAYERS=ch.bfs.gebaeude_wohnungs_register&LAYERS=ch.bfs.gebaeude_wohnungs_register&X=1&Y=1&uuid="
            + str(uuid.uuid1())
        )
        response = urllib2.urlopen(queryString)
        responseText = response.read()
        if responseText.rfind("Search returned no results") == -1:
            responseElements = responseText.split("\n")
            for element in responseElements:
                if element.rfind("strname1") > -1:
                    strname1_s = element.split("=")
                    street = strname1_s[1].lstrip().lstrip("'").rstrip().rstrip("'")
                if element.rfind("plz4") > -1:
                    plz4_s = element.split("=")
                    postcode = plz4_s[1].lstrip().lstrip("'").rstrip().rstrip("'")
                if element.rfind("deinr") > -1:
                    deinr_s = element.split("=")
                    housenumber = deinr_s[1].lstrip().lstrip("'").rstrip().rstrip("'")
                if element.rfind("plzname") > -1:
                    plzname_s = element.split("=")
                    city = plzname_s[1].lstrip().lstrip("'").rstrip().rstrip("'")
            swissBuildingArray = [{"housenumber": housenumber, "street": street, "postcode": postcode, "city": city}]
            if "callback" in request.params:
                response.headers["Content-Type"] = "text/javascript; charset=utf-8"
                return request.params["callback"] + "(" + json_dumps(swissBuildingArray) + ");"
            else:
                response.headers["Content-Type"] = "application/json"
                return json_dumps(swissBuildingArray)
        else:
            if "callback" in request.params:
                response.headers["Content-Type"] = "text/javascript; charset=utf-8"
                return request.params["callback"] + "(" + json_dumps([{"result": "Search returned no results"}]) + ");"
            else:
                response.headers["Content-Type"] = "application/json"
                return json_dumps([{"result": "Search returned no results"}])
Пример #2
0
   def run(self):
      if self.type == 'geonames':
         self.queryString = 'http://ws.geonames.org/searchJSON?maxRows=10&name_startsWith='+self.query.replace(' ','%20')+'&lang=en&charset=UTF8'

      if self.type == 'openaddresses':
         self.queryString = 'http://www.openaddresses.org/addresses/?limit=10&attrs=street,housenumber,city&query='+urllib.quote(self.query.encode('utf8'))

      response = urllib2.urlopen(self.queryString)
      self.json = response.read()
Пример #3
0
def verify_ipn(parameters):
    paraemeters['cmd'] = '_notify-validate'
    try:
        safer = dict([k, v.encode('utf-8')] for k, v in parameters.items())
        params = urllib.urlencode(safer)
    except UnicodeEncodeError:
        g.log.error("problem urlencoding %r" % (parameters,))
        raise
    req = urllib2.Request(g.PAYPAL_URL, params)
    req.add_header("Content-type", "application/x-www-form-urlencoded")

    response = urllib2.urlopen(req)
    status = response.read()

    if status != "VERIFIED":
        raise ValueError("Invalid IPN response: %r" % status)
Пример #4
0
def verify_ipn(parameters):
    paraemeters['cmd'] = '_notify-validate'
    try:
        safer = dict([k, v.encode('utf-8')] for k, v in parameters.items())
        params = urllib.urlencode(safer)
    except UnicodeEncodeError:
        g.log.error("problem urlencoding %r" % (parameters, ))
        raise
    req = urllib2.Request(g.PAYPAL_URL, params)
    req.add_header("Content-type", "application/x-www-form-urlencoded")

    response = urllib2.urlopen(req)
    status = response.read()

    if status != "VERIFIED":
        raise ValueError("Invalid IPN response: %r" % status)
Пример #5
0
 def _make_geoserver_rest_request(self, path, data=None):
     url = config['mapclient.geoserver.api_url'] + 'rest/' + path
     username = config['mapclient.geoserver.username']
     password = config['mapclient.geoserver.password']
     
     request = urllib2.Request(url = url)
     
     #TODO Check POST case
     if data:
         request.add_data(data.encode('utf-8'))
     
     request.add_header('Authorization', 
                        'Basic ' + ((username + ':' + password).encode('base64').rstrip()))
     try:
         response = urllib2.urlopen(request)
     except urllib2.HTTPError as ex:
         try:
             detail = ex.read()
         except:
             detail = 'n/a'
         raise RuntimeError('GeoServer REST Request \'%s\' failed with '
                            'exception: \'%s\'. Details: %s' % (path, ex, detail))
     return response.read()   
Пример #6
0
    def _checkUrl(self, checkName, url, checkString, requestHost):

        req = urllib2.Request(url,headers={'Host':requestHost, 'Referer': 'http://admin.ch'})

        httpresponses = {
        100: ('Continue', 'Request received, please continue'),
        101: ('Switching Protocols',
        'Switching to new protocol; obey Upgrade header'),
        200: ('OK', 'Request fulfilled, document follows'),
        201: ('Created', 'Document created, URL follows'),
        202: ('Accepted',
        'Request accepted, processing continues off-line'),
        203: ('Non-Authoritative Information',
        'Request fulfilled from cache'),
        204: ('No response', 'Request fulfilled, nothing follows'),
        205: ('Reset Content', 'Clear input form for further input.'),
        206: ('Partial Content', 'Partial content follows.'),
        300: ('Multiple Choices',
        'Object has several resources -- see URI list'),
        301: ('Moved Permanently',
        'Object moved permanently -- see URI list'),
        302: ('Found', 'Object moved temporarily -- see URI list'),
        303: ('See Other', 'Object moved -- see Method and URL list'),
        304: ('Not modified',
        'Document has not changed since given time'),
        305: ('Use Proxy',
        'You must use proxy specified in Location'
        ' to access this resource.'),
        307: ('Temporary Redirect',
        'Object moved temporarily -- see URI list'),
        400: ('Bad request',
        'Bad request syntax or unsupported method'),
        401: ('Unauthorized',
        'No permission -- see authorization schemes'),
        402: ('Payment required',
        'No payment -- see charging schemes'),
        403: ('Forbidden',
        'Request forbidden -- authorization will not help'),
        404: ('Not Found', 'Nothing matches the given URI'),
        405: ('Method Not Allowed',
        'Specified method is invalid for this server.'),
        406: ('Not Acceptable',
        'URI not available in preferred format.'),
        407: ('Proxy Authentication Required',
        'You must authenticate with '
        'this proxy before proceeding.'),
        408: ('Request Time-out',
        'Request timed out; try again later.'),
        409: ('Conflict', 'Request conflict.'),
        410: ('Gone',
        'URI no longer exists and has been permanently removed.'),
        411: ('Length Required', 'Client must specify Content-Length.'),
        412: ('Precondition Failed',
        'Precondition in headers is false.'),
        413: ('Request Entity Too Large', 'Entity is too large.'),
        414: ('Request-URI Too Long', 'URI is too long.'),
        415: ('Unsupported Media Type',
        'Entity body in unsupported format.'),
        416: ('Requested Range Not Satisfiable',
        'Cannot satisfy request range.'),
        417: ('Expectation Failed',
        'Expect condition could not be satisfied.'),
        500: ('Internal error', 'Server got itself in trouble'),
        501: ('Not Implemented',
        'Server does not support this operation'),
        502: ('Bad Gateway',
        'Invalid responses from another server/proxy.'),
        503: ('Service temporarily overloaded',
        'The server cannot '
        'process the request due to a high load'),
        504: ('Gateway timeout',
        'The gateway server did not receive a timely response'),
        505: ('HTTP Version not supported', 'Cannot fulfill request.'),
        }

        try:
            response = urllib2.urlopen(req)
            responseContent = response.read()
        except URLError, e:
            return 'NOT OK: '+checkName+'<br>Error code: '+str(e.code
                    )+'<br>'+httpresponses[e.code][0]+'<br>'+httpresponses[e.code][1]+'<br>Url: <a href="'+url+'">'+url+'</a>'
Пример #7
0
 def index(self, format="html"):
     """GET /obtain: All items in the collection"""
     url = "http://localhost:5984/resource_data/_all_docs"
     response = urllib2.urlopen(url)
     return response.read()
Пример #8
0
    def index(self):
        if 'latitude' in request.params and 'longitude' in request.params:
            latitude = float(request.params['latitude'])
            longitude = float(request.params['longitude'])
        if 'easting' in request.params:
            easting = float(request.params['easting'])
        if 'northing' in request.params:
            northing = float(request.params['northing'])

        queryString = 'http://wms.geo.admin.ch/?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&SRS=EPSG:21781'
        queryString = queryString + '&BBOX=' + str(easting - 1.0) + ',' + str(
            northing - 1.0) + ',' + str(easting + 1.0) + ',' + str(northing +
                                                                   1.0) + ''
        queryString = queryString + '&WIDTH=2&HEIGHT=2&QUERY_LAYERS=ch.bfs.gebaeude_wohnungs_register&LAYERS=ch.bfs.gebaeude_wohnungs_register&X=1&Y=1&uuid=' + str(
            uuid.uuid1())
        response = urllib2.urlopen(queryString)
        responseText = response.read()
        if responseText.rfind('Search returned no results') == -1:
            responseElements = responseText.split('\n')
            for element in responseElements:
                if element.rfind('strname1') > -1:
                    strname1_s = element.split('=')
                    street = strname1_s[1].lstrip().lstrip(
                        '\'').rstrip().rstrip('\'')
                if element.rfind('plz4') > -1:
                    plz4_s = element.split('=')
                    postcode = plz4_s[1].lstrip().lstrip('\'').rstrip().rstrip(
                        '\'')
                if element.rfind('deinr') > -1:
                    deinr_s = element.split('=')
                    housenumber = deinr_s[1].lstrip().lstrip(
                        '\'').rstrip().rstrip('\'')
                if element.rfind('plzname') > -1:
                    plzname_s = element.split('=')
                    city = plzname_s[1].lstrip().lstrip('\'').rstrip().rstrip(
                        '\'')
            swissBuildingArray = [{
                'housenumber': housenumber,
                'street': street,
                'postcode': postcode,
                'city': city
            }]
            if 'callback' in request.params:
                response.headers[
                    'Content-Type'] = 'text/javascript; charset=utf-8'
                return request.params['callback'] + '(' + json_dumps(
                    swissBuildingArray) + ');'
            else:
                response.headers['Content-Type'] = 'application/json'
                return json_dumps(swissBuildingArray)
        else:
            if 'callback' in request.params:
                response.headers[
                    'Content-Type'] = 'text/javascript; charset=utf-8'
                return request.params['callback'] + '(' + json_dumps([{
                    'result':
                    'Search returned no results'
                }]) + ');'
            else:
                response.headers['Content-Type'] = 'application/json'
                return json_dumps([{'result': 'Search returned no results'}])
Пример #9
0
 def index(self, format='html'):
     """GET /obtain: All items in the collection"""
     url = 'http://localhost:5984/resource_data/_all_docs'
     response = urllib2.urlopen(url)
     return response.read()