<commit_before># Licensed to libcloud.org under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# libcloud.org licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from libcloud.providers import Provider
from libcloud.types import NodeState, InvalidCredsException
from libcloud.base import Node, Response, ConnectionKey, NodeDriver, NodeSize, NodeImage

import base64
from xml.etree import ElementTree as ET


NAMESPACE = "http://www.vmware.com/vcloud1/vl"

class VCloudResponse(Response):

    def parse_body(self):
        if not self.body:
            return None
        return ET.XML(self.body)

    def parse_error(self):
        return self.body

class VCloudConnection(ConnectionKey):
    host = None
    responseCls = VCloudResponse
    token = None
    hostingid = None

    __host = None

    @property
    def host(self):
        if not self.__host:
            headers = {'Authentication': base64.b64encode(self.key),
                       'Content-Length': 0} 

            conn = self.conn_classes[self.secure](self.api_host, self.port[self.secure])
            conn.request(method='POST', url='/api/v0.8/login', headers=headers)

            resp = conn.getresponse()
            headers = dict(resp.getheaders())
            body = resp.read()
            print body

            try:
                self.token = headers['set-cookie']
                print
                print body.strip()
                print 
                ET.XMLTreeBuilder().feed(body.strip())
                print self.hostingid
            except KeyError:
                raise InvalidCredsException()
            
            self.__host = True
            
        return self.api_host

    def add_default_headers(self, headers):
        headers['Cookie'] = self.token
        return headers

class VCloudDriver(NodeDriver):
    type = Provider.VCLOUD

    def _fixxpath(self, xpath):
        # ElementTree wants namespaces in its xpaths, so here we add them.<commit_msg>small fix<commit_after># Licensed to libcloud.org under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# libcloud.org licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from libcloud.providers import Provider
from libcloud.types import NodeState, InvalidCredsException
from libcloud.base import Node, Response, ConnectionKey, NodeDriver, NodeSize, NodeImage

import base64
from xml.etree import ElementTree as ET


NAMESPACE = "http://www.vmware.com/vcloud1/vl"

class VCloudResponse(Response):

    def parse_body(self):
        if not self.body:
            return None
        return ET.XML(self.body)

    def parse_error(self):
        return self.body

class VCloudConnection(ConnectionKey):
    host = None
    responseCls = VCloudResponse
    token = None
    hostingid = None

    __host = None

    @property
    def host(self):
        if not self.__host:
            headers = {'Authentication': base64.b64encode(self.key),
                       'Content-Length': 0} 

            conn = self.conn_classes[self.secure](self.api_host, self.port[self.secure])
            conn.request(method='POST', url='/api/v0.8/login', headers=headers)

            resp = conn.getresponse()
            headers = dict(resp.getheaders())
            body = resp.read()
            print body

            try:
                self.token = headers['set-cookie']
                print
                print body.strip()
                print 
                print ET.XML(body)
            except KeyError:
                raise InvalidCredsException()
            
            self.__host = True
            
        return self.api_host

    def add_default_headers(self, headers):
        headers['Cookie'] = self.token
        return headers

class VCloudDriver(NodeDriver):
    type = Provider.VCLOUD

    def _fixxpath(self, xpath):
        # ElementTree wants namespaces in its xpaths, so here we add them.
{'fraction_non_alphanumeric': 0.07764521807158224, 'fraction_numerical': 0.005476237042831997, 'mean_word_length': 2.464769647696477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2197565', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1303, 'n_words': 461}