<commit_before>#!/usr/bin/env python
#! -*- coding: utf-8 -*-

###  
# Copyright (c) Rice University 2012
# This software is subject to
# the provisions of the GNU Lesser General
# Public License Version 2.1 (LGPL).
# See LICENCE.txt for details.
###


from flask import Flask, render_template, request, g, session, flash,   redirect, url_for, abort


import datetime
import md5, random
import os, sys
import flask
import statsd
import json
from functools import wraps
import uuid
import requests
import urllib

from rhaptos2.common import log
from rhaptos2.common import err
from rhaptos2.common import conf

from rhaptos2.user import get_app, dolog, usermodel
from rhaptos2.user.backend import db_session

app = get_app()


@app.before_request
def requestid():
    g.requestid = uuid.uuid4()
    g.request_id = g.requestid

@app.teardown_request
def shutdown_session(exception=None):
    db_session.remove()


@app.route('/')
def index():
    dolog("INFO", "THis is request %s" % g.requestid)
    return "This is the USer Database for CNX"


@app.route('/openid/', methods=["GET",])
def get_user_by_identifier():
    """ """
    qstr = request.query_string
    

    unquoted_identifier = qstr.replace("user=", "")
    unquoted_identifier = urllib.unquote(unquoted_identifier)
    dolog("INFO", "THis is request %s" % g.requestid)
    dolog("INFO", "I saw identifier: %s" % unquoted_identifier)


    dolog("INFO", "THis is request %s" % g.requestid)
    dolog("INFO", "I saw identifier: %s" % unquoted_identifier)
    print "A" + unquoted_identifier
    print "B" + urllib.unquote(unquoted_identifier)


    ### errors to abort function
    ### .. todo:: better trap than abort()

    security_token = None
    try:
        json_str = usermodel.get_user_by_identifier(unquoted_identifier)     
    except err.Rhaptos2Error, e:
        abort(404)

    resp = flask.make_response(json_str)
    resp.content_type='application/json'
    return resp

    
@app.route('/user/', methods=["GET",])
def get_user():
    """

    example::

      /user?user=org.cnx.user.f9647df6-cc6e-4885-9b53-254aa55a3383

    .. todo:: Flask will unquote the whole URL and try to route that,
              instead of taking the route that exists in quoted format,
               and then calculating the <parameter>
             
              /openid/this/is/a/path<commit_msg>debug cleanup<commit_after>#!/usr/bin/env python
#! -*- coding: utf-8 -*-

###  
# Copyright (c) Rice University 2012
# This software is subject to
# the provisions of the GNU Lesser General
# Public License Version 2.1 (LGPL).
# See LICENCE.txt for details.
###


from flask import Flask, render_template, request, g, session, flash,   redirect, url_for, abort


import datetime
import md5, random
import os, sys
import flask
import statsd
import json
from functools import wraps
import uuid
import requests
import urllib

from rhaptos2.common import log
from rhaptos2.common import err
from rhaptos2.common import conf

from rhaptos2.user import get_app, dolog, usermodel
from rhaptos2.user.backend import db_session

app = get_app()


@app.before_request
def requestid():
    g.requestid = uuid.uuid4()
    g.request_id = g.requestid

@app.teardown_request
def shutdown_session(exception=None):
    db_session.remove()


@app.route('/')
def index():
    dolog("INFO", "THis is request %s" % g.requestid)
    return "This is the USer Database for CNX"


@app.route('/openid/', methods=["GET",])
def get_user_by_identifier():
    """ """
    qstr = request.query_string
    

    unquoted_identifier = qstr.replace("user=", "")
    unquoted_identifier = urllib.unquote(unquoted_identifier)
    dolog("INFO", "This is request %s" % g.requestid)
    dolog("INFO", "I saw identifier: %s" % unquoted_identifier)


    #print "A" + unquoted_identifier
    #print "B" + urllib.unquote(unquoted_identifier)


    ### errors to abort function
    ### .. todo:: better trap than abort()

    security_token = None
    try:
        json_str = usermodel.get_user_by_identifier(unquoted_identifier)     
    except err.Rhaptos2Error, e:
        abort(404)

    resp = flask.make_response(json_str)
    resp.content_type='application/json'
    return resp

    
@app.route('/user/', methods=["GET",])
def get_user():
    """

    example::

      /user?user=org.cnx.user.f9647df6-cc6e-4885-9b53-254aa55a3383

    .. todo:: Flask will unquote the whole URL and try to route that,
              instead of taking the route that exists in quoted format,
               and then calculating the <parameter>
             
              /openid/this/is/a/path
{'fraction_non_alphanumeric': 0.11309264897781644, 'fraction_numerical': 0.017398869073510223, 'mean_word_length': 3.3592417061611375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '774650', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1487, 'n_words': 418}