Пример #1
0
 def get_wadl_application(self, url):
     """GET a WADL representation of the resource at the requested url."""
     wadl_type = 'application/vnd.sun.wadl+xml'
     response, content = self._request(url, media_type=wadl_type)
     url = str(url)
     if not isinstance(content, bytes):
         content = content.encode('utf-8')
     return Application(url, content)
Пример #2
0
def get_application():
    """Get or create a WADL application for testing Launchpad.

    Note that this uses the Launchpad v1.0 WADL bundled with launchpadlib for
    testing purposes.  For your own application, you might want to construct
    an L{Application} object directly, giving it your own WADL.
    """
    global launchpad_testing_application
    if launchpad_testing_application is None:
        markup_url = "https://api.launchpad.net/1.0/"
        markup = resource_string("launchpadlib.testing", "launchpad-wadl.xml")
        launchpad_testing_application = Application(markup_url, markup)
    return launchpad_testing_application
Пример #3
0
    def application_for(filename):
        def path2url(path):
            return urlparse.urljoin('file:', urllib.pathname2url(path))

        def hack_namespace(wadl_string):
            return wadl_string.replace(WADL.WADL_NAMESPACE,
                                       WADL.LEGACY_WADL_NAMESPACE)

        url = path2url(filename)
        wadl_string = open(filename, 'r').read()
        try:
            return Application(url, hack_namespace(wadl_string))
        # except (WADLError, ParseError) as e:
        except Exception as e:
            raise BadWADLError("Could not load WADL file", e, url)
Пример #4
0
def application_for(filename, url="http://localhost/"):
    wadl_stream = pkg_resources.resource_stream('tests.data', filename)
    return Application(url, wadl_stream)
Пример #5
0
import wadllib
import os
import pkg_resources

from wadllib.application import Application

#
# Example from https://pypi.python.org/pypi/wadllib/1.1.5
# Copyright applies as stated.
#

# Application for a wadl object
wadl_string = pkg_resources.resource_string('wadllib.tests.data',
                                            'launchpad-wadl.xml')
wadl = Application("http://api.launchpad.dev/beta/", wadl_string)


def application_for(filename, url="http://localhost/"):
    wadl_stream = pkg_resources.resource_stream('tests.data', filename)
    return Application(url, wadl_stream)


filename = "launchpad-wadl.xml"
wadl = application_for(filename, "http://api.launchpad.dev/beta/")
print "wadl: ", wadl

# Link Navigation

# The preferred technique for finding a resource is to start at one of
# the resources defined in the WADL file, and follow links. This code
Пример #6
0
 def get_wadl_application(self, url):
     """GET a WADL representation of the resource at the requested url."""
     wadl_type = 'application/vnd.sun.wadl+xml'
     response, content = self._request(url, media_type=wadl_type)
     return Application(str(url), content)
Пример #7
0
 def make(self, dependency_resources):
     return FakeLaunchpad(application=Application(
         "https://api.example.com/testing/",
         resource_string("launchpadlib.testing", "testing-wadl.xml")))
Пример #8
0
# Examples from [bazaar.launchpad.net](http://bazaar.launchpad.net/~lazr-developers/wadllib/trunk/view/head:/src/wadllib/README.txt)

import wadllib
import os
import pkg_resources

from wadllib.application import Application

#
# Example from https://pypi.python.org/pypi/wadllib/1.1.5
# Copyright applies as stated.
#

# Application for a wadl object
wadl_string = pkg_resources.resource_string('wadllib.tests.data','launchpad-wadl.xml')
wadl = Application("http://api.launchpad.dev/beta/", wadl_string)

def application_for(filename, url="http://localhost/"):
    wadl_stream = pkg_resources.resource_stream('tests.data',filename)
    return Application(url, wadl_stream)

filename = "launchpad-wadl.xml"
wadl = application_for(filename,"http://api.launchpad.dev/beta/")
print "wadl: ",wadl

# Link Navigation

# The preferred technique for finding a resource is to start at one of
# the resources defined in the WADL file, and follow links. This code
# retrieves the definition of the root resource.
service_root = wadl.get_resource_by_path('')