# Path: openaddr/conform.py
# def conform_smash_case(source_definition):
#     "Convert all named fields in source_definition object to lowercase. Returns new object."
#     new_sd = copy.deepcopy(source_definition)
#     conform = new_sd["conform"]
#     for k, v in conform.items():
#         if v not in (X_FIELDNAME, Y_FIELDNAME) and getattr(v, 'lower', None):
#             conform[k] = v.lower()
#         if type(conform[k]) is list:
#             conform[k] = [s.lower() for s in conform[k]]
#         if type(conform[k]) is dict:
#             fxn_smash_case(conform[k])
# 
#             if "functions" in conform[k] and type(conform[k]["functions"]) is list:
#                 for function in conform[k]["functions"]:
#                     if type(function) is dict:
#                         if "field" in function:
#                             function["field"] = function["field"].lower()
# 
#                         if "fields" in function:
#                             function["fields"] = [s.lower() for s in function["fields"]]
# 
#                         if "field_to_remove" in function:
#                             function["field_to_remove"] = function["field_to_remove"].lower()
# 
#     if "advanced_merge" in conform:
#         raise ValueError('Found unsupported "advanced_merge" option in conform')
#     return new_sd
# 
# def row_transform_and_convert(sd, row):
#     "Apply the full conform transform and extract operations to a row"
# 
#     # Some conform specs have fields named with a case different from the source
#     row = row_smash_case(sd, row)
# 
#     c = sd["conform"]
# 
#     "Attribute tags can utilize processing fxns"
#     for k, v in c.items():
#         if k in attrib_types and type(v) is list:
#             "Lists are a concat shortcut to concat fields with spaces"
#             row = row_merge(sd, row, k)
#         if k in attrib_types and type(v) is dict:
#             "Dicts are custom processing functions"
#             row = row_function(sd, row, k, v)
# 
#     if "advanced_merge" in c:
#         raise ValueError('Found unsupported "advanced_merge" option in conform')
#     if "split" in c:
#         raise ValueError('Found unsupported "split" option in conform')
# 
#     # Make up a random fingerprint if none exists
#     cache_fingerprint = sd.get('fingerprint', str(uuid4()))
# 
#     row2 = row_convert_to_out(sd, row)
#     row3 = row_canonicalize_unit_and_number(sd, row2)
#     row4 = row_round_lat_lon(sd, row3)
#     row5 = row_calculate_hash(cache_fingerprint, row4)
#     return row5


import csv
import fiona
import json
import logging
import os
import requests
import sys
import traceback
import zipfile
from . import config
from shapely.geometry import shape
from shapely.wkt import loads, dumps
from openaddr.conform import conform_smash_case, row_transform_and_convert
                geom = clean

        if geom.geom_type == 'Polygon':
            return geom

    return None


def scrape_fiona_metadata(obj, source):
    """
    Uses openaddress machine code to scrape metadata from a fiona object.
    """
    with open('{}/sources/{}'.format(config.openaddr_dir, source)) as file:
        source_json = json.load(file)
    cleaned_json = conform_smash_case(source_json)
    cleaned_prop = {k: str(v or '') for (k, v) in  obj['properties'].items()}

    metadata = row_transform_and_convert(cleaned_json, cleaned_prop)

    return metadata


def scrape_csv_metadata(row, header, source):
    """
    Uses openaddress machine code to scrape metadata from a csv row.
    """
    props = {}

    with open('{}/sources/{}'.format(config.openaddr_dir, source)) as file:
        source_json = json.load(file)

# Path: openaddr/conform.py
# def conform_smash_case(source_definition):
#     "Convert all named fields in source_definition object to lowercase. Returns new object."
#     new_sd = copy.deepcopy(source_definition)
#     conform = new_sd["conform"]
#     for k, v in conform.items():
#         if v not in (X_FIELDNAME, Y_FIELDNAME) and getattr(v, 'lower', None):
#             conform[k] = v.lower()
#         if type(conform[k]) is list:
#             conform[k] = [s.lower() for s in conform[k]]
#         if type(conform[k]) is dict:
#             fxn_smash_case(conform[k])
# 
#             if "functions" in conform[k] and type(conform[k]["functions"]) is list:
#                 for function in conform[k]["functions"]:
#                     if type(function) is dict:
#                         if "field" in function:
#                             function["field"] = function["field"].lower()
# 
#                         if "fields" in function:
#                             function["fields"] = [s.lower() for s in function["fields"]]
# 
#                         if "field_to_remove" in function:
#                             function["field_to_remove"] = function["field_to_remove"].lower()
# 
#     if "advanced_merge" in conform:
#         raise ValueError('Found unsupported "advanced_merge" option in conform')
#     return new_sd
# 
# def row_transform_and_convert(sd, row):
#     "Apply the full conform transform and extract operations to a row"
# 
#     # Some conform specs have fields named with a case different from the source
#     row = row_smash_case(sd, row)
# 
#     c = sd["conform"]
# 
#     "Attribute tags can utilize processing fxns"
#     for k, v in c.items():
#         if k in attrib_types and type(v) is list:
#             "Lists are a concat shortcut to concat fields with spaces"
#             row = row_merge(sd, row, k)
#         if k in attrib_types and type(v) is dict:
#             "Dicts are custom processing functions"
#             row = row_function(sd, row, k, v)
# 
#     if "advanced_merge" in c:
#         raise ValueError('Found unsupported "advanced_merge" option in conform')
#     if "split" in c:
#         raise ValueError('Found unsupported "split" option in conform')
# 
#     # Make up a random fingerprint if none exists
#     cache_fingerprint = sd.get('fingerprint', str(uuid4()))
# 
#     row2 = row_convert_to_out(sd, row)
#     row3 = row_canonicalize_unit_and_number(sd, row2)
#     row4 = row_round_lat_lon(sd, row3)
#     row5 = row_calculate_hash(cache_fingerprint, row4)
#     return row5


# Path: openaddr/parcels/utils.py
import csv
import fiona
import json
import logging
import os
import requests
import sys
import traceback
import zipfile
from . import config
from shapely.geometry import shape
from shapely.wkt import loads, dumps
from openaddr.conform import conform_smash_case, row_transform_and_convert

                geom = clean

        if geom.geom_type == 'Polygon':
            return geom

    return None


def scrape_fiona_metadata(obj, source):
    """
    Uses openaddress machine code to scrape metadata from a fiona object.
    """
    with open('{}/sources/{}'.format(config.openaddr_dir, source)) as file:
        source_json = json.load(file)
    cleaned_json = conform_smash_case(source_json)
    cleaned_prop = {k: str(v or '') for (k, v) in  obj['properties'].items()}

    metadata = row_transform_and_convert(cleaned_json, cleaned_prop)

    return metadata


def scrape_csv_metadata(row, header, source):
    """
    Uses openaddress machine code to scrape metadata from a csv row.
    """
    props = {}

    with open('{}/sources/{}'.format(config.openaddr_dir, source)) as file:
        source_json = json.load(file)

    cleaned_json = conform_smash_case(source_json)