Exemplo n.º 1
0
    def action(self,
               document,
               keys,
               params=None,
               action=None,
               encoding=None,
               transform=None):
        if isinstance(keys, string_types):
            keys = [keys]

        # Validate the keys and link parameters.
        link, link_ancestors = _lookup_link(document, keys)
        url = _make_absolute(link.url)

        if (action is not None) or (encoding is not None) or (transform
                                                              is not None):
            # Handle any explicit overrides.
            action = link.action if (action is None) else action
            encoding = link.encoding if (encoding is None) else encoding
            transform = link.transform if (transform is None) else transform
            link = Link(url,
                        action=action,
                        encoding=encoding,
                        transform=transform,
                        fields=link.fields)

        # Perform the action, and return a new document.
        transport = determine_transport(url, transports=self.transports)
        return transport.transition(link,
                                    params,
                                    decoders=self.decoders,
                                    link_ancestors=link_ancestors)
Exemplo n.º 2
0
    def reload(self, document):
        url = _make_absolute(document.url)
        link = Link(url, action='get')

        # Perform the action, and return a new document.
        transport = determine_transport(link.url, transports=self.transports)
        return transport.transition(link, decoders=self.decoders)
Exemplo n.º 3
0
    def reload(self, document):
        url = _make_absolute(document.url)
        link = Link(url, action='get')

        # Perform the action, and return a new document.
        transport = determine_transport(link.url, transports=self.transports)
        return transport.transition(link, decoders=self.decoders)
Exemplo n.º 4
0
    def action(self, document, keys, params=None, action=None, inplace=None):
        if isinstance(keys, string_types):
            keys = [keys]

        # Validate the keys and link parameters.
        link, link_ancestors = _lookup_link(document, keys)

        if (action is not None) or (inplace is not None):
            # Handle any explicit overrides.
            action = link.action if (action is None) else action
            inplace = link.inplace if (inplace is None) else inplace
            link = Link(link.url, action, inplace, link.fields)

        # Perform the action, and return a new document.
        transport = determine_transport(link.url, transports=self.transports)
        return transport.transition(link, params, decoders=self.decoders, link_ancestors=link_ancestors)
Exemplo n.º 5
0
    def action(self, document, keys, params=None, action=None, encoding=None, transform=None):
        if isinstance(keys, string_types):
            keys = [keys]

        # Validate the keys and link parameters.
        link, link_ancestors = _lookup_link(document, keys)
        url = _make_absolute(link.url)

        if (action is not None) or (encoding is not None) or (transform is not None):
            # Handle any explicit overrides.
            action = link.action if (action is None) else action
            encoding = link.encoding if (encoding is None) else encoding
            transform = link.transform if (transform is None) else transform
            link = Link(url, action=action, encoding=encoding, transform=transform, fields=link.fields)

        # Perform the action, and return a new document.
        transport = determine_transport(url, transports=self.transports)
        return transport.transition(link, params, decoders=self.decoders, link_ancestors=link_ancestors)
Exemplo n.º 6
0
    def get(self, url):
        link = Link(url, action='get')

        # Perform the action, and return a new document.
        transport = determine_transport(link.url, transports=self.transports)
        return transport.transition(link, decoders=self.decoders)
Exemplo n.º 7
0
def test_missing_hostname():
    with pytest.raises(TransportError):
        determine_transport('http://')
Exemplo n.º 8
0
def test_missing_scheme():
    with pytest.raises(TransportError):
        determine_transport('example.org')
Exemplo n.º 9
0
def test_unknown_scheme():
    with pytest.raises(TransportError):
        determine_transport('ftp://example.org')