当前位置: 首页>>代码示例>>Python>>正文


Python urn.Urn类代码示例

本文整理汇总了Python中webdav.urn.Urn的典型用法代码示例。如果您正苦于以下问题:Python Urn类的具体用法?Python Urn怎么用?Python Urn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Urn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_to

    def download_to(self, buff, remote_path):

        try:
            urn = Urn(remote_path)

            if self.is_dir(urn.path()):
                raise OptionNotValid(name="remote_path", value=remote_path)

            if not self.check(urn.path()):
                raise RemoteResourceNotFound(urn.path())

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'WRITEFUNCTION': buff.write,
                'HTTPHEADER': self.get_header('download_to'),
                'NOBODY': 0
            }

            request = self.Request(options=options)

            request.perform()
            request.close()

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:26,代码来源:client.py

示例2: download

    def download(self, remote_path, local_path, progress=None):

        urn = Urn(remote_path)
        if self.is_dir(urn.path()):
            self.download_directory(local_path=local_path, remote_path=remote_path, progress=progress)
        else:
            self.download_file(local_path=local_path, remote_path=remote_path, progress=progress)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:7,代码来源:client.py

示例3: push

    def push(self, remote_directory, local_directory):

        def prune(src, exp):
            return [sub(exp, "", item) for item in src]

        urn = Urn(remote_directory, directory=True)

        if not self.is_dir(urn.path()):
            raise OptionNotValid(name="remote_path", value=remote_directory)

        if not os.path.isdir(local_directory):
            raise OptionNotValid(name="local_path", value=local_directory)

        if not os.path.exists(local_directory):
            raise LocalResourceNotFound(local_directory)

        paths = self.list(urn.path())
        expression = "{begin}{end}".format(begin="^", end=urn.path())
        remote_resource_names = prune(paths, expression)

        for local_resource_name in listdir(local_directory):

            local_path = os.path.join(local_directory, local_resource_name)
            remote_path = "{remote_directory}{resource_name}".format(remote_directory=urn.path(), resource_name=local_resource_name)

            if os.path.isdir(local_path):
                if not self.check(remote_path=remote_path):
                    self.mkdir(remote_path=remote_path)
                self.push(remote_directory=remote_path, local_directory=local_path)
            else:
                if local_resource_name in remote_resource_names:
                    continue
                self.upload_file(remote_path=remote_path, local_path=local_path)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:33,代码来源:client.py

示例4: upload_from

    def upload_from(self, buff, remote_path):

        try:
            urn = Urn(remote_path)

            if urn.is_dir():
                raise OptionNotValid(name="remote_path", value=remote_path)

            if not self.check(urn.parent()):
                raise RemoteParentNotFound(urn.path())

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'HTTPHEADER': self.get_header('upload_from'),
                'UPLOAD': 1,
                'READFUNCTION': buff.read,
            }

            request = self.Request(options=options)

            request.perform()
            code = request.getinfo(pycurl.HTTP_CODE)
            if code == "507":
                raise NotEnoughSpace()

            request.close()

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:30,代码来源:client.py

示例5: download_file

    def download_file(self, remote_path, local_path, progress=None):

        try:
            urn = Urn(remote_path)

            if self.is_dir(urn.path()):
                raise OptionNotValid(name="remote_path", value=remote_path)

            if os.path.isdir(local_path):
                raise OptionNotValid(name="local_path", value=local_path)

            if not self.check(urn.path()):
                raise RemoteResourceNotFound(urn.path())

            with open(local_path, 'wb') as local_file:

                url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
                options = {
                    'URL': "{hostname}{root}{path}".format(**url),
                    'HTTPHEADER': self.get_header('download_file'),
                    'WRITEDATA': local_file,
                    'NOPROGRESS': 0 if progress else 1,
                    'NOBODY': 0
                }

                if progress:
                   options["PROGRESSFUNCTION"] = progress

                request = self.Request(options=options)

                request.perform()
                request.close()

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:35,代码来源:client.py

示例6: publish

    def publish(self, remote_path):

        def parse(response):

            try:
                response_str = response.getvalue()
                tree = etree.fromstring(response_str)
                result = tree.xpath("//*[local-name() = 'public_url']")
                public_url = result[0]
                return public_url.text
            except IndexError:
                raise MethodNotSupported(name="publish", server=self.webdav.hostname)
            except etree.XMLSyntaxError:
                return ""

        def data(for_server):

            root_node = etree.Element("propertyupdate", xmlns="DAV:")
            set_node = etree.SubElement(root_node, "set")
            prop_node = etree.SubElement(set_node, "prop")
            xmlns = Client.meta_xmlns.get(for_server, "")
            public_url = etree.SubElement(prop_node, "public_url", xmlns=xmlns)
            public_url.text = "true"
            tree = etree.ElementTree(root_node)

            buff = BytesIO()
            tree.write(buff)

            return buff.getvalue()

        try:
            urn = Urn(remote_path)

            if not self.check(urn.path()):
                raise RemoteResourceNotFound(urn.path())

            response = BytesIO()

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'CUSTOMREQUEST': Client.requests['publish'],
                'HTTPHEADER': self.get_header('publish'),
                'POSTFIELDS': data(for_server=self.webdav.hostname),
                'WRITEDATA': response,
                'NOBODY': 0
            }

            request = self.Request(options=options)

            request.perform()
            request.close()

            return parse(response)

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:57,代码来源:client.py

示例7: check

    def check(self, remote_path=root):

        def parse(response, path):

            try:
                response_str = response.getvalue()
                tree = etree.fromstring(response_str)

                resps = tree.findall("{DAV:}response")

                for resp in resps:
                    href = resp.findtext("{DAV:}href")
                    urn = unquote(href)

                    if path.endswith(Urn.separate):
                        if path == urn or path[:-1] == urn:
                            return True
                    else:
                        if path == urn:
                            return True

                return False

            except etree.XMLSyntaxError:
                raise MethodNotSupported(name="check", server=self.webdav.hostname)

        try:
            urn = Urn(remote_path)
            parent_urn = Urn(urn.parent())
            response = BytesIO()

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': parent_urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'CUSTOMREQUEST': Client.requests['info'],
                'HTTPHEADER': self.get_header('info'),
                'WRITEDATA': response,
                'NOBODY': 0
            }

            request = self.Request(options=options)

            request.perform()
            request.close()

            path = "{root}{path}".format(root=self.webdav.root, path=urn.path())

            return parse(response, path)

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:51,代码来源:client.py

示例8: upload_file

    def upload_file(self, remote_path, local_path, progress=None):

        try:
            if not os.path.exists(local_path):
                raise LocalResourceNotFound(local_path)

            urn = Urn(remote_path)

            if urn.is_dir():
                raise OptionNotValid(name="remote_path", value=remote_path)

            if os.path.isdir(local_path):
                raise OptionNotValid(name="local_path", value=local_path)

            if not os.path.exists(local_path):
                raise LocalResourceNotFound(local_path)

            if not self.check(urn.parent()):
                raise RemoteParentNotFound(urn.path())

            with open(local_path, "rb") as local_file:

                url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
                options = {
                    'URL': "{hostname}{root}{path}".format(**url),
                    'HTTPHEADER': self.get_header('upload_file'),
                    'UPLOAD': 1,
                    'READFUNCTION': local_file.read,
                    'NOPROGRESS': 0 if progress else 1
                }

                if progress:
                   options["PROGRESSFUNCTION"] = progress

                file_size = os.path.getsize(local_path)
                if file_size > self.large_size:
                    options['INFILESIZE_LARGE'] = file_size
                else:
                    options['INFILESIZE'] = file_size

                request = self.Request(options=options)

                request.perform()
                code = request.getinfo(pycurl.HTTP_CODE)
                if code == "507":
                    raise NotEnoughSpace()

                request.close()

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:51,代码来源:client.py

示例9: get_property

    def get_property(self, remote_path, option):

        def parse(response, option):

            response_str = response.getvalue()
            tree = etree.fromstring(response_str)
            xpath = "{xpath_prefix}{xpath_exp}".format(xpath_prefix=".//", xpath_exp=option['name'])
            return tree.findtext(xpath)

        def data(option):

            root = etree.Element("propfind", xmlns="DAV:")
            prop = etree.SubElement(root, "prop")
            etree.SubElement(prop, option.get('name', ""), xmlns=option.get('namespace', ""))
            tree = etree.ElementTree(root)

            buff = BytesIO()

            tree.write(buff)
            return buff.getvalue()

        try:
            urn = Urn(remote_path)

            if not self.check(urn.path()):
                raise RemoteResourceNotFound(urn.path())

            response = BytesIO()

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'CUSTOMREQUEST': Client.requests['get_metadata'],
                'HTTPHEADER': self.get_header('get_metadata'),
                'POSTFIELDS': data(option),
                'WRITEDATA': response,
                'NOBODY': 0
            }

            request = self.Request(options=options)

            request.perform()
            request.close()

            return parse(response, option)

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:48,代码来源:client.py

示例10: download_directory

    def download_directory(self, remote_path, local_path, progress=None):

        urn = Urn(remote_path, directory=True)

        if not self.is_dir(urn.path()):
            raise OptionNotValid(name="remote_path", value=remote_path)

        if os.path.exists(local_path):
            shutil.rmtree(local_path)

        os.makedirs(local_path)

        for resource_name in self.list(urn.path()):
            _remote_path = "{parent}{name}".format(parent=urn.path(), name=resource_name)
            _local_path = os.path.join(local_path, resource_name)
            self.download(local_path=_local_path, remote_path=_remote_path, progress=progress)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:16,代码来源:client.py

示例11: check

    def check(self, remote_path=root):

        try:
            urn = Urn(remote_path)
            response = BytesIO()

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'CUSTOMREQUEST': Client.requests['check'],
                'HTTPHEADER': self.get_header('check'),
                'WRITEDATA': response,
                'NOBODY': 1
            }

            request = self.Request(options=options)

            request.perform()
            code = request.getinfo(pycurl.HTTP_CODE)
            request.close()

            if int(code) == 200:
                return True
        
            return False

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:designerror,项目名称:webdav-client-python,代码行数:28,代码来源:client.py

示例12: rename

    def rename(self, new_name):

        old_path = self.urn.path()
        parent_path = self.urn.parent()
        new_name = Urn(new_name).filename()
        new_path = "{directory}{filename}".format(directory=parent_path, filename=new_name)

        self.client.move(remote_path_from=old_path, remote_path_to=new_path)
        self.urn = Urn(new_path)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:9,代码来源:client.py

示例13: list

    def list(self, remote_path=root):

        def parse(response):

            try:
                response_str = response.getvalue()
                tree = etree.fromstring(response_str)
                hrees = [unquote(hree.text) for hree in tree.findall(".//{DAV:}href")]
                return [Urn(hree) for hree in hrees]
            except etree.XMLSyntaxError:
                return list()

        try:
            directory_urn = Urn(remote_path, directory=True)

            if directory_urn.path() != Client.root:
                if not self.check(directory_urn.path()):
                    raise RemoteResourceNotFound(directory_urn.path())

            response = BytesIO()

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': directory_urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'CUSTOMREQUEST': Client.requests['list'],
                'HTTPHEADER': self.get_header('list'),
                'WRITEDATA': response,
                'NOBODY': 0
            }

            request = self.Request(options=options)

            request.perform()
            request.close()

            urns = parse(response)

            path = "{root}{path}".format(root=self.webdav.root, path=directory_urn.path())
            return [urn.filename() for urn in urns if urn.path() != path and urn.path() != path[:-1]]

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:42,代码来源:client.py

示例14: __init__

    def __init__(self, options):

        self.options = dict()

        for key in self.keys:
            value = options.get(key, '')
            self.options[key] = value
            self.__dict__[key] = value

        self.root = Urn(self.root).quote() if self.root else ''
        self.root = self.root.rstrip(Urn.separate)
开发者ID:designerror,项目名称:webdav-client-python,代码行数:11,代码来源:connection.py

示例15: set_property

    def set_property(self, remote_path, option):

        def data(option):

            root_node = etree.Element("propertyupdate", xmlns="DAV:")
            root_node.set('xmlns:u', option.get('namespace', ""))
            set_node = etree.SubElement(root_node, "set")
            prop_node = etree.SubElement(set_node, "prop")
            opt_node = etree.SubElement(prop_node, "{namespace}:{name}".format(namespace='u', name=option['name']))
            opt_node.text = option.get('value', "")

            tree = etree.ElementTree(root_node)

            buff = BytesIO()
            tree.write(buff)

            return buff.getvalue()

        try:
            urn = Urn(remote_path)

            if not self.check(urn.path()):
                raise RemoteResourceNotFound(urn.path())

            url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
            options = {
                'URL': "{hostname}{root}{path}".format(**url),
                'CUSTOMREQUEST': Client.requests['set_metadata'],
                'HTTPHEADER': self.get_header('get_metadata'),
                'POSTFIELDS': data(option)
            }

            request = self.Request(options=options)

            request.perform()
            request.close()

        except pycurl.error:
            raise NotConnection(self.webdav.hostname)
开发者ID:jeroenmeulenaar,项目名称:webdav-client-python,代码行数:39,代码来源:client.py


注:本文中的webdav.urn.Urn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。