Пример #1
0
    def setPublicLink(self, filename, create=True):
        resp = None
        content = None

        data = XMLElement('file')
        data.setHead(self.xmlHead)

        elm = XMLElement('publicLink')
        if create:
            elm.setAttribute('enabled', 'true')
        else:
            elm.setAttribute('enabled', 'false')

        data.addChild(elm)

        resp, content = self.sendRequestPut('/file/%s' % filename,
                                            data.toString())

        if resp is not None:
            if int(resp['status']) == 200:
                content = XMLElement.parse(content)
                if create:
                    print('Created public link: %s' % content.publicLink)
                else:
                    print('Public link destroyed successful.')
            else:
                print('Could not create/destroy public link (Code: %s).' %
                      resp['status'])
        else:
            print('Could not create/destroy public link (request failed).')
    def setPublicLink(self, filename, create=True):
        resp = None
        content = None

        data = XMLElement('file')
        data.setHead(self.xmlHead)
        
        elm = XMLElement('publicLink')
        if create:
            elm.setAttribute('enabled', 'true')
        else:
            elm.setAttribute('enabled', 'false')

        data.addChild(elm)

        resp, content = self.sendRequestPut('/file/%s' % filename, data.toString())

        if resp is not None:
            if int(resp['status']) == 200:
                content = XMLElement.parse(content)
                if create:
                    print('Created public link: %s' % content.publicLink)
                else: 
                    print('Public link destroyed successful.')
            else:
                print('Could not create/destroy public link (Code: %s).' % resp['status'])
        else:
            print('Could not create/destroy public link (request failed).')
Пример #3
0
    def copyFile(self, source, target, name):
        print(source, target, name)
        data = XMLElement('fileCopy')
        data.setHead(self.xmlHead)
        data.setAttribute('source', self.apiURL + '/file/' + source)
        data.addChild(XMLElement('displayName').addChild(XMLTextNode(name)))

        response = self.sendRequest('/folder/%s' % target, data.toString())

        if response is not None:
            info = response.info()
            code = response.getcode()
            location = info['Location']

            if code == 201:
                self.addElementToDatabase('%s/%s' % (target, name), location)
                print('File copied with sucess. Location: %s' % location)
                return True
            else:
                print('File could not be copied (Code: %s)!' % (code))

            return False
    def copyFile(self, source, target, name):
        print(source, target, name)
        data = XMLElement('fileCopy')
        data.setHead(self.xmlHead)
        data.setAttribute('source', self.apiURL+'/file/'+source)
        data.addChild(XMLElement('displayName').addChild(XMLTextNode(name)))

        response = self.sendRequest('/folder/%s' % target, data.toString())
        
        if response is not None:
            info = response.info()
            code = response.getcode()
            location = info['Location']

            if code == 201:
                self.addElementToDatabase('%s/%s' % (target, name), location)
                print('File copied with sucess. Location: %s' % location)
                return True
            else:
                print('File could not be copied (Code: %s)!' % (code))

            return False
Пример #5
0
    def parse(xml, parse = True, first = True):
        xmlpar = []
        if parse:
            # we remove all \n and others!
            xml = re.sub('\n', '', xml)
            xml = re.sub('\r', '', xml)
            xml = re.sub('>( *)<', '><', xml)

            tree = dom.parseString(xml)
            # we have always to use the first child!
            return XMLParser.parse(tree, False)
        else:
            tree = xml

        for branch in tree.childNodes:
            if branch.nodeType == branch.ELEMENT_NODE:
                xmltmp = XMLElement(branch.nodeName)
                # Attribute ?
                if branch._get_attributes() is not None:
                    for attr,value in branch._get_attributes().items():
                        xmltmp.setAttribute(attr,value)

                if branch.childNodes is not None:
                    ch = XMLParser.parse(branch, False, False)
                    if ch is not None:
                        for child in ch:
                            xmltmp.addChild(child)

                xmlpar.append(xmltmp)
            elif branch.nodeType == branch.TEXT_NODE:
                xmlpar.append(XMLTextNode(branch.nodeValue))
            else:
                xmlpar = None

        if first and xmlpar is not None and len(xmlpar) == 1:
            xmlpar = xmlpar[0]

        return xmlpar