# Path: utils.py
# def convert_to_int(possible_number, use_if_not_int):
#     """
#     Save conversion of string to int with ability to specify default if string is not a number
#     """
#     try:
#         result = int(possible_number)
#     except ValueError:
#         result = use_if_not_int
#     return result
# 
# def strip_the_lines(lines):
#     return map(strip_line, lines)


from django.db.utils import DatabaseError
from utils import convert_to_int, strip_the_lines
from models import CourtLocation
        Note that room_number and zip_code are stored as ints, not strings.
        """

        location_string = self._inmate_details.court_house_location()

        if location_string == "":
            return "", {}

        # Normalize whitespace, newlines (and weird unicode character).
        location_string = location_string.replace(u'\xa0', u' ')
        lines = strip_the_lines(location_string.splitlines())

        if len(lines) == 4:
            try:
                # First line is the shortened form of the branch name, usually.
                location_name = lines[0]

                # Second line must be split into room number and branch name.
                branch_line = lines[1].split(', Room:')
                branch_name = branch_line[0].strip()
                room_number = convert_to_int(branch_line[1], 0)

                # Remove room number and store the address.
                address = lines[2].split('Room:')[0].strip()

                # Fourth line has city, state and zip separated by spaces.
                city_state_zip = lines[3].split(' ')

                city = " ".join(city_state_zip[0:-2]).replace(',', '').strip()
                state = city_state_zip[-2].strip()

# Path: utils.py
# def convert_to_int(possible_number, use_if_not_int):
#     """
#     Save conversion of string to int with ability to specify default if string is not a number
#     """
#     try:
#         result = int(possible_number)
#     except ValueError:
#         result = use_if_not_int
#     return result
# 
# def strip_the_lines(lines):
#     return map(strip_line, lines)


# Path: countyapi/court_date_info.py
from django.db.utils import DatabaseError
from utils import convert_to_int, strip_the_lines
from models import CourtLocation

        Note that room_number and zip_code are stored as ints, not strings.
        """

        location_string = self._inmate_details.court_house_location()

        if location_string == "":
            return "", {}

        # Normalize whitespace, newlines (and weird unicode character).
        location_string = location_string.replace(u'\xa0', u' ')
        lines = strip_the_lines(location_string.splitlines())

        if len(lines) == 4:
            try:
                # First line is the shortened form of the branch name, usually.
                location_name = lines[0]

                # Second line must be split into room number and branch name.
                branch_line = lines[1].split(', Room:')
                branch_name = branch_line[0].strip()
                room_number = convert_to_int(branch_line[1], 0)

                # Remove room number and store the address.
                address = lines[2].split('Room:')[0].strip()

                # Fourth line has city, state and zip separated by spaces.
                city_state_zip = lines[3].split(' ')

                city = " ".join(city_state_zip[0:-2]).replace(',', '').strip()
                state = city_state_zip[-2].strip()

                zip_code = convert_to_int(city_state_zip[-1], 60639)