<commit_before># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

"""
Google Voice backend code

Resources
	http://thatsmith.com/2009/03/google-voice-addon-for-firefox/
	http://posttopic.com/topic/google-voice-add-on-development
"""


import os
import re
import urllib
import urllib2
import time
import warnings

from xml.etree import ElementTree

from browser_emu import MozillaEmulator

import socket

try:
	import simplejson
except ImportError:
	simplejson = None

socket.setdefaulttimeout(5)


_TRUE_REGEX = re.compile("true")
_FALSE_REGEX = re.compile("false")


def safe_eval(s):
	s = _TRUE_REGEX.sub("True", s)
	s = _FALSE_REGEX.sub("False", s)
	return eval(s, {}, {})


if simplejson is None:
	def parse_json(flattened):
		return safe_eval(flattened)
else:
	def parse_json(flattened):
		return simplejson.loads(json)


class GVDialer(object):
	"""
	This class encapsulates all of the knowledge necessary to interace with the grandcentral servers
	the functions include login, setting up a callback number, and initalting a callback
	"""

	_contactsRe = re.compile(r"""<a href="/mobile/contacts/detail/(\d+)">(.*?)</a>""", re.S)
	_contactsNextRe = re.compile(r""".*<a href="/mobile/contacts(\?page=\d+)">Next</a>""", re.S)
	_contactDetailGroupRe = re.compile(r"""Group:\s*(\w*)""", re.S)
	_contactDetailPhoneRe = re.compile(r"""(\w+):[0-9\-\(\) \t]*?<a href="/mobile/calls/click_to_call\?destno=(\d+).*?">call</a>""", re.S)

	_isNotLoginPageRe = re.compile(r"""I cannot access my account""")
	_tokenRe = re.compile(r"""<input.*?name="_rnr_se".*?value="(.*?)"\s*/>""")
	_accountNumRe = re.compile(r"""<b class="ms2">(.{14})</b></div>""")
	_callbackRe = re.compile(r"""\s+(.*?):\s*(.*?)<br\s*/>\s*$""", re.M)
	_validateRe = re.compile("^[0-9]{10,}$")
	_gvDialingStrRe = re.compile("This may take a few seconds", re.M)

	_clicktocallURL = "http://www.google.com/voice/m/callsms"
	_contactsURL = "http://www.google.com/voice/mobile/contacts"
	_contactDetailURL = "http://www.google.com/voice/mobile/contact"

	_loginURL = "https://www.google.com/accounts/ServiceLoginAuth"
	_setforwardURL = "https://www.google.com//voice/m/setphone"
	_accountNumberURL = "https://www.google.com/voice/mobile"<commit_msg>Hmm, these probably should be using https, but now Google Voice just gives me a different error<commit_after># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

"""
Google Voice backend code

Resources
	http://thatsmith.com/2009/03/google-voice-addon-for-firefox/
	http://posttopic.com/topic/google-voice-add-on-development
"""


import os
import re
import urllib
import urllib2
import time
import warnings

from xml.etree import ElementTree

from browser_emu import MozillaEmulator

import socket

try:
	import simplejson
except ImportError:
	simplejson = None

socket.setdefaulttimeout(5)


_TRUE_REGEX = re.compile("true")
_FALSE_REGEX = re.compile("false")


def safe_eval(s):
	s = _TRUE_REGEX.sub("True", s)
	s = _FALSE_REGEX.sub("False", s)
	return eval(s, {}, {})


if simplejson is None:
	def parse_json(flattened):
		return safe_eval(flattened)
else:
	def parse_json(flattened):
		return simplejson.loads(json)


class GVDialer(object):
	"""
	This class encapsulates all of the knowledge necessary to interace with the grandcentral servers
	the functions include login, setting up a callback number, and initalting a callback
	"""

	_contactsRe = re.compile(r"""<a href="/mobile/contacts/detail/(\d+)">(.*?)</a>""", re.S)
	_contactsNextRe = re.compile(r""".*<a href="/mobile/contacts(\?page=\d+)">Next</a>""", re.S)
	_contactDetailGroupRe = re.compile(r"""Group:\s*(\w*)""", re.S)
	_contactDetailPhoneRe = re.compile(r"""(\w+):[0-9\-\(\) \t]*?<a href="/mobile/calls/click_to_call\?destno=(\d+).*?">call</a>""", re.S)

	_isNotLoginPageRe = re.compile(r"""I cannot access my account""")
	_tokenRe = re.compile(r"""<input.*?name="_rnr_se".*?value="(.*?)"\s*/>""")
	_accountNumRe = re.compile(r"""<b class="ms2">(.{14})</b></div>""")
	_callbackRe = re.compile(r"""\s+(.*?):\s*(.*?)<br\s*/>\s*$""", re.M)
	_validateRe = re.compile("^[0-9]{10,}$")
	_gvDialingStrRe = re.compile("This may take a few seconds", re.M)

	_clicktocallURL = "https://www.google.com/voice/m/callsms"
	_contactsURL = "https://www.google.com/voice/mobile/contacts"
	_contactDetailURL = "https://www.google.com/voice/mobile/contact"

	_loginURL = "https://www.google.com/accounts/ServiceLoginAuth"
	_setforwardURL = "https://www.google.com//voice/m/setphone"
	_accountNumberURL = "https://www.google.com/voice/mobile"
{'fraction_non_alphanumeric': 0.17333070711049833, 'fraction_numerical': 0.011030135907031712, 'mean_word_length': 4.925320886814469, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 9, 'lorem ipsum': 0, 'www.': 12, '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': '3553480', 'n_tokens_mistral': 1868, 'n_tokens_neox': 1804, 'n_words': 413}