<commit_before>from lxml import etree
import clockwork_http 
import clockwork_exceptions

SMS_URL = 'https://api.clockworksms.com/xml/send.aspx'
CREDIT_URL = 'https://api.clockworksms.com/xml/credit.aspx'
BALANCE_URL = 'https://api.clockworksms.com/xml/balance.aspx'


class SMS(object):
	"""An SMS object"""

	def __init__(self, to, message, client_id = None, from_name = None, long = None, truncate = None, invalid_char_option = None):
		self.client_id = client_id
		self.from_name = from_name
		self.long = long
		self.truncate = truncate
		self.invalid_char_option = invalid_char_option
		self.to = to
		self.message = message

class SMSResponse(object):
	"""An wrapper around an SMS reponse"""

	def __init__(self, sms, id, error_code, error_message, success):
		self.sms = sms
		self.id = id
		self.error_code = error_code
		self.error_message = error_message
		self.success = success


class API(object):
	"""Wraps the clockwork API"""
	def __init__(self, apikey, from_name = 'Clockwork', concat = 3, 
		invalid_char_option = 'error', long = False, truncate = True, 
		use_ssl = True):
		self.apikey = apikey
		self.from_name = from_name
		self.concat = concat
		self.invalid_char_option = invalid_char_option
		self.long = long
		self.truncate = truncate
		self.use_ssl = use_ssl

	def get_balance(self):
		"""Check the balance fot this account.
		   Returns a dictionary containing:
		   account_type: The account type
		   balance: The balance remaining on the account
		   currency: The currency used for the account balance. Assume GBP in not set"""
		
		xml_root = self.__init_xml('Balance')

		response = clockwork_http.request(BALANCE_URL,etree.tostring(xml_root))
		data_etree = etree.fromstring(response['data'])

		err_desc = data_etree.find('ErrDesc')	
		if err_desc is not None:
			raise clockwork_exceptions.ApiException(err_desc.text, data_etree.find('ErrNo').text)


		result = {}
		result['account_type'] = data_etree.find('AccountType').text<commit_msg>Encode balance request message as utf-8 for consistency.<commit_after>from lxml import etree
import clockwork_http 
import clockwork_exceptions

SMS_URL = 'https://api.clockworksms.com/xml/send.aspx'
CREDIT_URL = 'https://api.clockworksms.com/xml/credit.aspx'
BALANCE_URL = 'https://api.clockworksms.com/xml/balance.aspx'


class SMS(object):
	"""An SMS object"""

	def __init__(self, to, message, client_id = None, from_name = None, long = None, truncate = None, invalid_char_option = None):
		self.client_id = client_id
		self.from_name = from_name
		self.long = long
		self.truncate = truncate
		self.invalid_char_option = invalid_char_option
		self.to = to
		self.message = message

class SMSResponse(object):
	"""An wrapper around an SMS reponse"""

	def __init__(self, sms, id, error_code, error_message, success):
		self.sms = sms
		self.id = id
		self.error_code = error_code
		self.error_message = error_message
		self.success = success


class API(object):
	"""Wraps the clockwork API"""
	def __init__(self, apikey, from_name = 'Clockwork', concat = 3, 
		invalid_char_option = 'error', long = False, truncate = True, 
		use_ssl = True):
		self.apikey = apikey
		self.from_name = from_name
		self.concat = concat
		self.invalid_char_option = invalid_char_option
		self.long = long
		self.truncate = truncate
		self.use_ssl = use_ssl

	def get_balance(self):
		"""Check the balance fot this account.
		   Returns a dictionary containing:
		   account_type: The account type
		   balance: The balance remaining on the account
		   currency: The currency used for the account balance. Assume GBP in not set"""
		
		xml_root = self.__init_xml('Balance')

		response = clockwork_http.request(BALANCE_URL,etree.tostring(xml_root, encoding='utf-8'))
		data_etree = etree.fromstring(response['data'])

		err_desc = data_etree.find('ErrDesc')	
		if err_desc is not None:
			raise clockwork_exceptions.ApiException(err_desc.text, data_etree.find('ErrNo').text)


		result = {}
		result['account_type'] = data_etree.find('AccountType').text
{'fraction_non_alphanumeric': 0.10779188449091362, 'fraction_numerical': 0.0009957679860592482, 'mean_word_length': 4.459239130434782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '4000287', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1323, 'n_words': 331}