<commit_before>#!/usr/bin/env python
#
# Copyright 2014 The Pennsylvania State University.
#
"""
besapi.py

Created by <NAME> (<EMAIL>) on 2014-03-20.

Library for communicating with the BES (BigFix) REST API.
"""

import requests
from lxml import etree, objectify
from pkg_resources import resource_filename

class BESConnection():

    def __init__(self, username, password, rootserver, verify=False):
    
        if not verify:
            # disable SSL warnings
            # http://stackoverflow.com/questions/27981545/suppress-insecurerequestwarning-unverified-https-request-is-being-made-in-pytho
            requests.packages.urllib3.disable_warnings()

        self.session = requests.Session()
        self.session.auth = (username, password)
        self.rootserver = rootserver
        self.verify = verify

        if not self.login():
            self.get('login').request.raise_for_status()

    def url(self, path):
        if path.startswith(self.rootserver):
            url = path
        else:
            url = "%s/api/%s" % (self.rootserver, path)

        return url<commit_msg>make the rootserver URL not need to include https:// or :52311 if missing<commit_after>#!/usr/bin/env python
#
# Copyright 2014 The Pennsylvania State University.
#
"""
besapi.py

Created by <NAME> (<EMAIL>) on 2014-03-20.

Library for communicating with the BES (BigFix) REST API.
"""

import requests
from lxml import etree, objectify
from pkg_resources import resource_filename

class BESConnection():

    def __init__(self, username, password, rootserver, verify=False):
    
        if not verify:
            # disable SSL warnings
            # http://stackoverflow.com/questions/27981545/suppress-insecurerequestwarning-unverified-https-request-is-being-made-in-pytho
            requests.packages.urllib3.disable_warnings()

        self.session = requests.Session()
        self.session.auth = (username, password)
        
        # if not provided, add on https://
        if not rootserver.startswith("http"):
            rootserver = "https://" + rootserver
        # if port not provided, add on the default :52311
        if not rootserver.count(":") == 2:
            rootserver = rootserver + ":52311"

        self.rootserver = rootserver
        self.verify = verify

        if not self.login():
            self.get('login').request.raise_for_status()

    def url(self, path):
        if path.startswith(self.rootserver):
            url = path
        else:
            url = "%s/api/%s" % (self.rootserver, path)

        return url
{'fraction_non_alphanumeric': 0.107421875, 'fraction_numerical': 0.02265625, 'mean_word_length': 2.5569444444444445, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, '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': '848266', 'n_tokens_mistral': 789, 'n_tokens_neox': 724, 'n_words': 195}