Download pool/shard000/Python/0000120_app.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard000/Python/0000120_app.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard000/Python/0000120_app.py
-
curl -L -o 0000120_app.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard000/Python/0000120_app.py
1.48 kB
| import os | |
| import sys | |
| import falcon | |
| from falcon_cors import CORS | |
| from .user import UserResource, UsersEndpoint | |
| from .validator import Validator | |
| from .utils import error_serializer | |
| from .db import DB | |
| from .cfg import Config | |
| # pick the config directory | |
| config_dir = os.environ.get('OWNJSON_CONFIG_DIR', None) | |
| if config_dir is None: | |
| prefix = os.environ.get('XDG_CONFIG_DIR') | |
| if prefix is None: | |
| prefix = os.environ.get('HOME') | |
| config_dir = os.path.join(prefix, '.config/ownjson') | |
| # load config | |
| config = Config() | |
| ok = config.load(config_dir) | |
| if not ok: | |
| sys.exit(1) | |
| # set up the validator object | |
| schema_dir = os.path.join(config_dir, 'server_schemas') | |
| server_validator = Validator() | |
| for name in config.config['server_schemas']: | |
| server_validator.add_schema(name, os.path.join(schema_dir, '%s.schema' % (name) )) | |
| uri = config.get('db_uri') | |
| db_name = config.get('db_name') | |
| db = DB(uri, db_name) | |
| # data to send to kwargs for each resource | |
| data = { | |
| 'config': config.config, | |
| 'server_validator': server_validator, | |
| 'db': db | |
| } | |
| # set up the resources | |
| users = UserResource(**data) | |
| user_endpoint = UsersEndpoint(**data) | |
| cors = CORS(allow_all_origins=True, allow_all_methods=True, | |
| allow_headers_list=['accept', 'content-type', 'authorization']) | |
| # set up the wsgi app and add routes | |
| app = falcon.API(middleware=[ | |
| cors.middleware | |
| ]) | |
| app.set_error_serializer(error_serializer) | |
| app.add_route('/api/{username}', users) | |
| app.add_route('/api/users', user_endpoint) | |