<commit_before># vim:expandtab:smarttab
import logging
from pylons import g, Response
import os
import os.path as path
#from facebook.wsgi import facebook
import facebook
from facebook import FacebookError

from masterapp.lib.base import *
from fileprocess.fileprocess import file_queue, na, msgs

from masterapp import model

log = logging.getLogger(__name__)

class UploadsController(BaseController):
    def __init__(self, *args):
        super(BaseController, self).__init__(args)
        self.apikey = config['pyfacebook.apikey']
        self.secret = config['pyfacebook.secret']

    def file_already_uploaded(self, f_sha, fbid):
        """Checks to see if a song has already been uploaded and marks that user
            as having uploaded it if true"""
        song = model.Session.query(model.File).filter_by(sha=f_sha).first()
        if song == None:
            return False

        #We already have the song, mark the user as having it
        user = model.Session.query(model.User).filter_by(fbid=fbid).first()
        if user == None:
            user = model.User()
            user.fbid = fbid
            model.Session.save(user)
        
        new_owner = model.Owner()
        new_owner.file = song
        new_owner.user = user
        model.Session.save(new_owner)

        model.Session.commit()
        return True

    def get_fb(self):
        return facebook.Facebook(self.apikey, self.secret)

    def get_fbid(self, request):
        session_key = request.params.get('session_key')
        if session_key == None:
            return None
        
        fb = self.get_fb()
        try:
            fb.session_key = session_key
            fbid = fb.users.getLoggedInUser()
        except FacebookError:
            return None

        return fbid

    def read_postdata(dest_file=None):
        """Reads the postdata into the file object or throws it away 
           otherwise"""
        chunk_size = 1024
        file_size = int(request.environ["CONTENT_LENGTH"])
        body = request.environ['wsgi.input']<commit_msg>Fixed a bug in the uploads controller<commit_after># vim:expandtab:smarttab
import logging
from pylons import g, Response
import os
import os.path as path
#from facebook.wsgi import facebook
import facebook
from facebook import FacebookError

from masterapp.lib.base import *
from fileprocess.fileprocess import file_queue, na, msgs

from masterapp import model

log = logging.getLogger(__name__)

class UploadsController(BaseController):
    def __init__(self, *args):
        super(BaseController, self).__init__(args)
        self.apikey = config['pyfacebook.apikey']
        self.secret = config['pyfacebook.secret']

    def file_already_uploaded(self, f_sha, fbid):
        """Checks to see if a song has already been uploaded and marks that user
            as having uploaded it if true"""
        song = model.Session.query(model.File).filter_by(sha=f_sha).first()
        if song == None:
            return False

        #We already have the song, mark the user as having it
        user = model.Session.query(model.User).filter_by(fbid=fbid).first()
        if user == None:
            user = model.User()
            user.fbid = fbid
            model.Session.save(user)
        
        new_owner = model.Owner()
        new_owner.file = song
        new_owner.user = user
        model.Session.save(new_owner)

        model.Session.commit()
        return True

    def get_fb(self):
        return facebook.Facebook(self.apikey, self.secret)

    def get_fbid(self, request):
        session_key = request.params.get('session_key')
        if session_key == None:
            return None
        
        fb = self.get_fb()
        try:
            fb.session_key = session_key
            fbid = fb.users.getLoggedInUser()
        except FacebookError:
            return None

        return fbid

    def read_postdata(self, dest_file=None):
        """Reads the postdata into the file object or throws it away 
           otherwise"""
        chunk_size = 1024
        file_size = int(request.environ["CONTENT_LENGTH"])
        body = request.environ['wsgi.input']
{'fraction_non_alphanumeric': 0.0875965250965251, 'fraction_numerical': 0.0019305019305019305, 'mean_word_length': 2.41996699669967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '812754', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1155, 'n_words': 328}