<commit_before>import bottle
from bottle import route, request, response, static_file, hook
## pcapi imports
import logtool

log = logtool.getLogger("pcapi")

## Dropbox imports
#dboxpath = config.get("path","dropbox_path")
#sys.path.append(os.path.join(pwd,dboxpath))

from pcapi_exceptions import *
from pcapi_rest import PCAPIRest

################ ROUTES ####################

#######################################################
###  Rest Callbacks (can be tested with wget/curl)  ###
#######################################################

###  Provider capabilities ###

@route('/auth/providers',method=["GET"])
def capabilities():
    return PCAPIRest(request,response).capabilities()    

### /export/ a  public URL 
@route('/export/<provider>/<userid>/<path:path>', method=["GET"])
def export(userid, provider, path="/"):
    return PCAPIRest(request,response).export(provider, userid, path)

###  /sync/... API ###

@route('/sync/<provider>/<userid>')
@route('/sync/<provider>/<userid>/<cursor>')
def sync(userid, provider, cursor=None):
    return PCAPIRest(request,response).sync(provider, userid, cursor)

###  /assets/... API ###
@route('/records/<provider>/<userid>/assets/',method=["GET","PUT","POST","DELETE"] )
@route('/records/<provider>/<userid>/assets/<path:path>',method=["GET","POST","PUT","DELETE"] )
def assets(provider, userid, path="/"):
    flt = request.GET.get("frmt")
    return PCAPIRest(request,response).assets(provider, userid, path, flt)

###  /records/... API ###
@route('/records/<provider>/<userid>/',method=["GET","PUT","POST","DELETE"] )
@route('/records/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE"] )
def records(provider, userid, path="/"):
    flt = request.GET.get("filter")
    return PCAPIRest(request,response).records(provider, userid, path, flt)

###  /editors/... API ###

@route('/editors/<provider>/<userid>/',method=["GET","POST","PUT","DELETE"] )
@route('/editors/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE"] )
def editors(provider, userid, path="/"):
    flt = request.GET.get("format")
    return PCAPIRest(request,response).editors(provider, userid, path, flt)

###  /tiles/... API ###

@route('/tiles/<provider>/<userid>/',method=["GET","POST","PUT","DELETE"] )
@route('/tiles/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE"] )
def tiles(provider, userid, path="/"):
    return PCAPIRest(request,response).tiles(provider, userid, path)

###  /fs/... API ###

@route('/fs/<provider>/<userid>/',method=["GET","POST","PUT","DELETE"] )
@route('/fs/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE"] )
def fs(provider, userid, path="/"):
    """ Upload file to path (as documented in the API docs)   
    """
    return PCAPIRest(request, response).fs(provider, userid, path)     

###  /auth/... API ###

# Login to Dropbox.
@route('/auth/<provider>', method='GET')
@route('/auth/<provider>/<userid>', method='GET')
def login(provider,userid=None):
    return PCAPIRest(request, response).login(provider, userid)

### STATIC FILES (html/css/js etc.)###

def init_static_routes():
    """ Call this function to setup static routes using the documentroot defined in config.ini """
    root = config.getStaticHTML()
    @route('/<filename:re:(?!ws/).*>')    
    def serve_static(filename):
        return static_file(filename, root=root, download=False)
    
    @route('/')
    def default_static():
        return static_file('index.html', root=root, download=False)

########## CORS ##################

@hook('after_request')
def enable_cors():
    response.headers['Access-Control-Allow-Origin'] = '*'<commit_msg>IssueID #15: add CORS to all methods and add OPTIONS method on the rest API<commit_after>import bottle
from bottle import route, request, response, static_file, hook
## pcapi imports
import logtool

log = logtool.getLogger("pcapi")

## Dropbox imports
#dboxpath = config.get("path","dropbox_path")
#sys.path.append(os.path.join(pwd,dboxpath))

from pcapi_exceptions import *
from pcapi_rest import PCAPIRest

################ ROUTES ####################

#######################################################
###  Rest Callbacks (can be tested with wget/curl)  ###
#######################################################

###  Provider capabilities ###

@route('/auth/providers',method=["GET"])
def capabilities():
    return PCAPIRest(request,response).capabilities()    

### /export/ a  public URL 
@route('/export/<provider>/<userid>/<path:path>', method=["GET"])
def export(userid, provider, path="/"):
    return PCAPIRest(request,response).export(provider, userid, path)

###  /sync/... API ###

@route('/sync/<provider>/<userid>')
@route('/sync/<provider>/<userid>/<cursor>')
def sync(userid, provider, cursor=None):
    return PCAPIRest(request,response).sync(provider, userid, cursor)

###  /assets/... API ###
@route('/records/<provider>/<userid>/assets/',method=["GET","PUT","POST","DELETE"] )
@route('/records/<provider>/<userid>/assets/<path:path>',method=["GET","POST","PUT","DELETE"] )
def assets(provider, userid, path="/"):
    flt = request.GET.get("frmt")
    return PCAPIRest(request,response).assets(provider, userid, path, flt)

###  /records/... API ###
@route('/records/<provider>/<userid>/',method=["GET","PUT","POST","DELETE","OPTIONS"] )
@route('/records/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE","OPTIONS"] )
def records(provider, userid, path="/"):
    flt = request.GET.get("filter")
    return PCAPIRest(request,response).records(provider, userid, path, flt)

###  /editors/... API ###

@route('/editors/<provider>/<userid>/',method=["GET","POST","PUT","DELETE","OPTIONS"] )
@route('/editors/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE","OPTIONS"] )
def editors(provider, userid, path="/"):
    flt = request.GET.get("format")
    return PCAPIRest(request,response).editors(provider, userid, path, flt)

###  /tiles/... API ###

@route('/tiles/<provider>/<userid>/',method=["GET","POST","PUT","DELETE"] )
@route('/tiles/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE"] )
def tiles(provider, userid, path="/"):
    return PCAPIRest(request,response).tiles(provider, userid, path)

###  /fs/... API ###

@route('/fs/<provider>/<userid>/',method=["GET","POST","PUT","DELETE"] )
@route('/fs/<provider>/<userid>/<path:path>',method=["GET","POST","PUT","DELETE"] )
def fs(provider, userid, path="/"):
    """ Upload file to path (as documented in the API docs)
    """
    return PCAPIRest(request, response).fs(provider, userid, path)

###  /auth/... API ###

# Login to Dropbox.
@route('/auth/<provider>', method='GET')
@route('/auth/<provider>/<userid>', method='GET')
def login(provider,userid=None):
    return PCAPIRest(request, response).login(provider, userid)

### STATIC FILES (html/css/js etc.)###

def init_static_routes():
    """ Call this function to setup static routes using the documentroot defined in config.ini """
    root = config.getStaticHTML()
    @route('/<filename:re:(?!ws/).*>')    
    def serve_static(filename):
        return static_file(filename, root=root, download=False)
    
    @route('/')
    def default_static():
        return static_file('index.html', root=root, download=False)

########## CORS ##################

@hook('after_request')
def enable_cors():
    response.headers['Access-Control-Allow-Origin'] = '*'
    response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS, DELETE'
{'fraction_non_alphanumeric': 0.2586183947823772, 'fraction_numerical': 0.0002662052442433116, 'mean_word_length': 5.673179396092363, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3186668', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2448, 'n_words': 428}