<commit_before>#!/usr/bin/python
#
# Copyright (C) 2012 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import random
import time
from google.appengine.api import urlfetch

__author__ = '<EMAIL> (<NAME>)'
__author__ = '<EMAIL> (<NAME>)'

# Add the library location to the path
import sys

sys.path.insert(0, 'lib')

import os
import httplib2
from webapp2_extras import sessions
from apiclient.discovery import build
from apiclient.errors import HttpError
import webapp2
from webapp2_extras import jinja2
from models import CourseModel, Credentials, RegisteredUser
from apiclient.http import MediaUpload
from oauth2client.client import flow_from_clientsecrets
from oauth2client.client import FlowExchangeError
from oauth2client.client import AccessTokenRefreshError
from oauth2client.appengine import StorageByKeyName
from oauth2client.appengine import simplejson as json
import logging

ALL_SCOPES = ('https://www.googleapis.com/auth/drive.install '
              'https://www.googleapis.com/auth/drive.file '
              'https://www.googleapis.com/auth/userinfo.email '
              'https://www.googleapis.com/auth/userinfo.profile')


def SibPath(name):
    """Generate a path that is a sibling of this file.

    Args:
      name: Name of sibling file.
    Returns:
      Path to sibling file.
    """
    return os.path.join(os.path.dirname(__file__), name)


# Load the secret that is used for client side sessions
# Create one of these for yourself with, for example:
# python -c "import os; print os.urandom(64)" > session-secret
SESSION_SECRET = open(SibPath('session.secret')).read()

def CreateService(service, version, creds):
    """Create a Google API service.

    Load an API service from a discovery document and authorize it with the
    provided credentials.

    Args:
      service: Service name (e.g 'drive', 'oauth2').
      version: Service version (e.g 'v1').
      creds: Credentials used to authorize service.
    Returns:
      Authorized Google API service.
    """
    # Instantiate an Http instance
    http = httplib2.Http()

    # Authorize the Http instance with the passed credentials
    creds.authorize(http)

    # Build a service from the passed discovery document path
    return build(service, version, http=http)


class DriveState(object):
    """Store state provided by Drive."""

    def __init__(self, state):
        """Create a new instance of drive state.

        Parse and load the JSON state parameter.

        Args:
          state: State query parameter as a string.
        """
        if state:
            state_data = json.loads(state)
            self.action = state_data['action']

            if 'folderId' in state_data:
                self.parent = state_data['folderId']
            self.ids = map(str, state_data.get('ids', []))
        else:
            self.action = 'create'
            self.parent = []

        logging.debug('Create Drive state, parent %s, action s', self.parent, self.action)

    @classmethod
    def FromRequest(cls, request):
        """Create a Drive State instance from an HTTP request.

        Args:
          cls: Type this class method is called against.
          request: HTTP request.
        """
        return DriveState(request.get('state'))


class BaseHandler(webapp2.RequestHandler):<commit_msg>Fix log<commit_after>#!/usr/bin/python
#
# Copyright (C) 2012 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import random
import time
from google.appengine.api import urlfetch

__author__ = '<EMAIL> (<NAME>)'
__author__ = '<EMAIL> (<NAME>)'

# Add the library location to the path
import sys

sys.path.insert(0, 'lib')

import os
import httplib2
from webapp2_extras import sessions
from apiclient.discovery import build
from apiclient.errors import HttpError
import webapp2
from webapp2_extras import jinja2
from models import CourseModel, Credentials, RegisteredUser
from apiclient.http import MediaUpload
from oauth2client.client import flow_from_clientsecrets
from oauth2client.client import FlowExchangeError
from oauth2client.client import AccessTokenRefreshError
from oauth2client.appengine import StorageByKeyName
from oauth2client.appengine import simplejson as json
import logging

ALL_SCOPES = ('https://www.googleapis.com/auth/drive.install '
              'https://www.googleapis.com/auth/drive.file '
              'https://www.googleapis.com/auth/userinfo.email '
              'https://www.googleapis.com/auth/userinfo.profile')


def SibPath(name):
    """Generate a path that is a sibling of this file.

    Args:
      name: Name of sibling file.
    Returns:
      Path to sibling file.
    """
    return os.path.join(os.path.dirname(__file__), name)


# Load the secret that is used for client side sessions
# Create one of these for yourself with, for example:
# python -c "import os; print os.urandom(64)" > session-secret
SESSION_SECRET = open(SibPath('session.secret')).read()

def CreateService(service, version, creds):
    """Create a Google API service.

    Load an API service from a discovery document and authorize it with the
    provided credentials.

    Args:
      service: Service name (e.g 'drive', 'oauth2').
      version: Service version (e.g 'v1').
      creds: Credentials used to authorize service.
    Returns:
      Authorized Google API service.
    """
    # Instantiate an Http instance
    http = httplib2.Http()

    # Authorize the Http instance with the passed credentials
    creds.authorize(http)

    # Build a service from the passed discovery document path
    return build(service, version, http=http)


class DriveState(object):
    """Store state provided by Drive."""

    def __init__(self, state):
        """Create a new instance of drive state.

        Parse and load the JSON state parameter.

        Args:
          state: State query parameter as a string.
        """
        if state:
            state_data = json.loads(state)
            self.action = state_data['action']

            if 'folderId' in state_data:
                self.parent = state_data['folderId']
            self.ids = map(str, state_data.get('ids', []))
        else:
            self.action = 'create'
            self.parent = []

        logging.debug('Create Drive state, parent %s, action %s', unicode(self.parent) if hasattr(self, 'parent') else None, self.action)

    @classmethod
    def FromRequest(cls, request):
        """Create a Drive State instance from an HTTP request.

        Args:
          cls: Type this class method is called against.
          request: HTTP request.
        """
        return DriveState(request.get('state'))


class BaseHandler(webapp2.RequestHandler):
{'fraction_non_alphanumeric': 0.08857626677087405, 'fraction_numerical': 0.006512960791976032, 'mean_word_length': 3.1346257404415723, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 8, 'lorem ipsum': 0, 'www.': 10, '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': '5402970', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2078, 'n_words': 781}