# Path: smart/lib/utils.py
# class MethodDispatcher(object):
# class URLFetchException(Exception):
# class DjangoVersionDependentExecutor(object):
#   def __init__(self, method_map):
#   def resolve(self, request):
#   def __call__(self, request, *args, **kwargs):
# def is_valid_email(email):
# def random_string(length, choices=[string.letters]):
# def send_mail(subject, body, sender, recipient):
# def render_template_raw(template_name, vars, type='xml'):
# def render_template(template_name, vars, type='xml'):
# def get_element_value(dom, el):
# def url_interpolate(url_template, vars):
# def is_browser(request):
# def get_content_type(request):
# def get_capabilities ():
# def django_json(func):
#   def func_with_json_conversion(*args, **kwargs):
# def smart_path(path):
# def smart_parent(path):
# def x_domain(r):
# def trim(p, n):
#     def __init__(self, status, body=""):
# def url_request(url,  method, headers, data=None):
# def url_request_build(url,  method, headers, data=None):
# def url_request_execute(req):
# def rdf_response(s):
# def rdf_get(record_connector, query):
# def rdf_delete(record_connector, query, save=True): 
# def rdf_post(record_connector, g):
# def string_to_alphanumeric(s):
#     def __init__(self, version_map, default_return_val=None):
#     def __call__(self, *args, **kwargs):


from base import *
from django.utils import simplejson
from django.conf import settings
from smart.common.rdf_tools.rdf_ontology import ontology
from smart.common.rdf_tools.util import rdf, foaf, vcard, sp, serialize_rdf, parse_rdf, bound_graph, URIRef, Namespace
from smart.lib import utils
from smart.models.apps import *
from smart.models.accounts import *
from smart.triplestore import *
from string import Template
        from smart.models.record_object import RecordObject
import re
import datetime
PREFIX v:<http://www.w3.org/2006/vcard/ns#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>

SELECT ?gn ?fn ?dob ?gender ?zipcode ?d
WHERE {
    ?d rdf:type sp:Demographics.
    ?d v:n ?n.
    ?n v:given-name ?gn.
    ?n v:family-name ?fn.
    optional{?d foaf:gender ?gender.}
    optional{?d v:bday ?dob.}

    optional{
        ?d v:adr ?a.
        ?a rdf:type v:Pref.
        ?a v:postal-code ?zipcode.
    }

    optional{
        ?d v:adr ?a.
        ?a v:postal-code ?zipcode.
    }
}"""

        people = list(m.query(q))
        for p in people:
            record = Record()
            record.id = re.search(
                "\/records\/(.*?)\/demographics", str(p[5])).group(1)
            record.fn, record.ln, record.dob, record.gender, record.zipcode = p[:5]

# Path: smart/lib/utils.py
# class MethodDispatcher(object):
# class URLFetchException(Exception):
# class DjangoVersionDependentExecutor(object):
#   def __init__(self, method_map):
#   def resolve(self, request):
#   def __call__(self, request, *args, **kwargs):
# def is_valid_email(email):
# def random_string(length, choices=[string.letters]):
# def send_mail(subject, body, sender, recipient):
# def render_template_raw(template_name, vars, type='xml'):
# def render_template(template_name, vars, type='xml'):
# def get_element_value(dom, el):
# def url_interpolate(url_template, vars):
# def is_browser(request):
# def get_content_type(request):
# def get_capabilities ():
# def django_json(func):
#   def func_with_json_conversion(*args, **kwargs):
# def smart_path(path):
# def smart_parent(path):
# def x_domain(r):
# def trim(p, n):
#     def __init__(self, status, body=""):
# def url_request(url,  method, headers, data=None):
# def url_request_build(url,  method, headers, data=None):
# def url_request_execute(req):
# def rdf_response(s):
# def rdf_get(record_connector, query):
# def rdf_delete(record_connector, query, save=True): 
# def rdf_post(record_connector, g):
# def string_to_alphanumeric(s):
#     def __init__(self, version_map, default_return_val=None):
#     def __call__(self, *args, **kwargs):


# Path: smart/models/records.py
from base import *
from django.utils import simplejson
from django.conf import settings
from smart.common.rdf_tools.rdf_ontology import ontology
from smart.common.rdf_tools.util import rdf, foaf, vcard, sp, serialize_rdf, parse_rdf, bound_graph, URIRef, Namespace
from smart.lib import utils
from smart.models.apps import *
from smart.models.accounts import *
from smart.triplestore import *
from string import Template
        from smart.models.record_object import RecordObject
import re
import datetime

PREFIX v:<http://www.w3.org/2006/vcard/ns#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>

SELECT ?gn ?fn ?dob ?gender ?zipcode ?d
WHERE {
    ?d rdf:type sp:Demographics.
    ?d v:n ?n.
    ?n v:given-name ?gn.
    ?n v:family-name ?fn.
    optional{?d foaf:gender ?gender.}
    optional{?d v:bday ?dob.}

    optional{
        ?d v:adr ?a.
        ?a rdf:type v:Pref.
        ?a v:postal-code ?zipcode.
    }

    optional{
        ?d v:adr ?a.
        ?a v:postal-code ?zipcode.
    }
}"""

        people = list(m.query(q))
        for p in people:
            record = Record()
            record.id = re.search(
                "\/records\/(.*?)\/demographics", str(p[5])).group(1)
            record.fn, record.ln, record.dob, record.gender, record.zipcode = p[:5]

            record_list.append(record)