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)
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)
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)
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)
def test_missing_hostname(): with pytest.raises(TransportError): determine_transport('http://')
def test_missing_scheme(): with pytest.raises(TransportError): determine_transport('example.org')
def test_unknown_scheme(): with pytest.raises(TransportError): determine_transport('ftp://example.org')