This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <limits.h> | |
#include <math.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <sys/time.h> | |
#define Random0to1 ((double) rand() / (RAND_MAX)) + 1 | |
#define ITERATION 100000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HCOPY 000000001033 | |
DBUFFER000033BUFEND001033LENGTH00002D | |
RRDREC WRREC | |
T0000001D1720274B1000000320232900003320074B1000003F2FEC0320160F2016 | |
T00001D0D0100030F200A4B1000003E2000 | |
T00003003454F46 | |
M00000405+RDREC | |
M00001105+WRREC | |
M00002405+WRREC | |
E000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_oauth_req_url(): | |
params = { | |
'client_id': app.config.get('OAUTH_CLIENT_ID'), | |
'response_type': 'code', | |
'scope': 'god', | |
'next': urlparse(request.url).path | |
} | |
return "{0}/oauth/authorize?{1}".format(app.config.get('OAUTH_SERVER'), urlencode(params)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/oauth/login', methods=['GET']) | |
def oauth_login(): | |
form_data = { | |
'code': request.args['code'], | |
'redirect_uri': url_for('oauth_login', _external=True), | |
'grant_type': 'authorization_code', | |
'client_id': app.config.get('OAUTH_CLIENT_ID'), | |
'client_secret': app.config.get('OAUTH_CLIENT_SECRET'), | |
'scope': 'god' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@oauth_provider.invalid_response | |
def invalid_response(req): | |
if req.error_message == 'Bearer token is expired.': | |
raise ExpiredError | |
elif req.error_message == 'Bearer token scope not valid.': | |
raise NoPermissionError | |
else: | |
raise RequiredSignInError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
auth = OAuth(access_token) if use_auth else None | |
payload_data = json.dumps(payload) if payload is not None else None | |
if payload_data is None: | |
request = requests.Request(method, url, params=params, auth=auth).prepare() | |
else: | |
request = requests.Request(method, url, params=params, data=payload_data, auth=auth).prepare() | |
request.headers['Content-Type'] = 'application/json' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.errorhandler(401) | |
def unauthorized(e): | |
# 토큰이 만료된 경우에는 일단 토큰 재발급을 시도해본다 | |
if e.description == 'expired': | |
return refreshing_oauth_token() | |
elif e.description == 'permission_required': | |
return render_template('error/error.html', | |
data={ | |
'title': '401!!', | |
'header': '권한이 없어요!', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def refreshing_oauth_token(): | |
form_data = { | |
'grant_type': 'refresh_token', | |
'client_id': app.config.get('OAUTH_CLIENT_ID'), | |
'client_secret': app.config.get('OAUTH_CLIENT_SECRET'), | |
'refresh_token': REFRESH_TOKEN | |
} | |
response = RequestOauth.get_token(form_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from app import api_root | |
from flask_restful import Resource | |
@api_root.resource('/documents') | |
class DocumentListAPI(Resource): | |
def get(self): | |
items = [ | |
{'id': 1, 'title': 'title1', 'content': 'content1', 'ip': '1.2.3.4'}, | |
{'id': 2, 'title': 'title2', 'content': 'content2', 'ip': '5.6.7.8'}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from app import api_root | |
from flask_restful import Resource | |
@api_root.resource('/documents') | |
class DocumentListAPI(Resource): | |
def get(self): | |
items = [ | |
{'id': 1, 'title': 'title1', 'content': 'content1', 'ip': '1.2.3.4'}, | |
{'id': 2, 'title': 'title2', 'content': 'content2', 'ip': '5.6.7.8'}, |