Beispiel #1
0
    def cd(self, resource):
        """
        Change our working dir to RESOURCE.

        Can be used as a contextmanager that returns us to whatever
        state we were previously in on exit.

        Arguments:
        - `resource`: str or Path

        Return: None
        Exceptions: None
        """
        oldwd = self.wd
        self.wd = urlhelp.protocolise(resource)

        class HTTPCd(object):
            """
            Define this class in a closure to implement the contextmanager
            protocol while remaining able to operate on SELF.
            """
            def __enter__(zelf):
                return
            def __exit__(zelf, msg, val, tb):
                self.wd = oldwd
                return

        return HTTPCd()
Beispiel #2
0
    def cd(self, resource):
        """
        Change our working dir to RESOURCE.

        Can be used as a contextmanager that returns us to whatever
        state we were previously in on exit.

        Arguments:
        - `resource`: str or Path

        Return: None
        Exceptions: None
        """
        oldwd = self.wd
        self.wd = urlhelp.protocolise(resource)

        class HTTPCd(object):
            """
            Define this class in a closure to implement the contextmanager
            protocol while remaining able to operate on SELF.
            """
            def __enter__(zelf):
                return

            def __exit__(zelf, msg, val, tb):
                self.wd = oldwd
                return

        return HTTPCd()
Beispiel #3
0
    def abspath(self, resource):
        """
        Return an absolute path for RESOURCE

        Arguments:
        - `resource`: str or Path

        Return: str
        Exceptions: None
        """
        return urlhelp.protocolise(resource)
Beispiel #4
0
    def abspath(self, resource):
        """
        Return an absolute path for RESOURCE

        Arguments:
        - `resource`: str or Path

        Return: str
        Exceptions: None
        """
        return urlhelp.protocolise(resource)
Beispiel #5
0
    def exists(self, resource):
        """
        Predicate method to determine whether RESOURCE exists.

        Arguments:
        - `resource`: str or Path

        Return: bool
        Exceptions: None
        """
        resp = requests.head(urlhelp.protocolise(resource))
        return resp.status_code == 200
Beispiel #6
0
    def exists(self, resource):
        """
        Predicate method to determine whether RESOURCE exists.

        Arguments:
        - `resource`: str or Path

        Return: bool
        Exceptions: None
        """
        resp = requests.head(urlhelp.protocolise(resource))
        return resp.status_code == 200
Beispiel #7
0
    def open(self, resource):
        """
        Return a file-like object that represents the contents of
        a HTTP resource

        Arguments:
        - `resource`: str or Path

        Return: File-Like object
        Exceptions: None
        """
        url = urlhelp.protocolise(resource)
        resp = requests.get(url)
        flike = HTTPFlike(resp.content, url=url, headers=resp.headers)
        return flike
Beispiel #8
0
    def open(self, resource):
        """
        Return a file-like object that represents the contents of
        a HTTP resource

        Arguments:
        - `resource`: str or Path

        Return: File-Like object
        Exceptions: None
        """
        url = urlhelp.protocolise(resource)
        resp = requests.get(url)
        flike = HTTPFlike(resp.content, url=url, headers=resp.headers)
        return flike