partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
train
GlobExpression.InterpolateGrouping
Interpolate inline globbing groups.
grr/core/grr_response_core/lib/rdfvalues/paths.py
def InterpolateGrouping(self, pattern): """Interpolate inline globbing groups.""" components = [] offset = 0 for match in GROUPING_PATTERN.finditer(pattern): components.append([pattern[offset:match.start()]]) # Expand the attribute into the set of possibilities: alternatives = match.g...
def InterpolateGrouping(self, pattern): """Interpolate inline globbing groups.""" components = [] offset = 0 for match in GROUPING_PATTERN.finditer(pattern): components.append([pattern[offset:match.start()]]) # Expand the attribute into the set of possibilities: alternatives = match.g...
[ "Interpolate", "inline", "globbing", "groups", "." ]
google/grr
python
https://github.com/google/grr/blob/5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74/grr/core/grr_response_core/lib/rdfvalues/paths.py#L298-L314
[ "def", "InterpolateGrouping", "(", "self", ",", "pattern", ")", ":", "components", "=", "[", "]", "offset", "=", "0", "for", "match", "in", "GROUPING_PATTERN", ".", "finditer", "(", "pattern", ")", ":", "components", ".", "append", "(", "[", "pattern", "...
5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74
train
GlobExpression.AsRegEx
Return the current glob as a simple regex. Note: No interpolation is performed. Returns: A RegularExpression() object.
grr/core/grr_response_core/lib/rdfvalues/paths.py
def AsRegEx(self): """Return the current glob as a simple regex. Note: No interpolation is performed. Returns: A RegularExpression() object. """ parts = self.__class__.REGEX_SPLIT_PATTERN.split(self._value) result = u"".join(self._ReplaceRegExPart(p) for p in parts) return rdf_stand...
def AsRegEx(self): """Return the current glob as a simple regex. Note: No interpolation is performed. Returns: A RegularExpression() object. """ parts = self.__class__.REGEX_SPLIT_PATTERN.split(self._value) result = u"".join(self._ReplaceRegExPart(p) for p in parts) return rdf_stand...
[ "Return", "the", "current", "glob", "as", "a", "simple", "regex", "." ]
google/grr
python
https://github.com/google/grr/blob/5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74/grr/core/grr_response_core/lib/rdfvalues/paths.py#L335-L346
[ "def", "AsRegEx", "(", "self", ")", ":", "parts", "=", "self", ".", "__class__", ".", "REGEX_SPLIT_PATTERN", ".", "split", "(", "self", ".", "_value", ")", "result", "=", "u\"\"", ".", "join", "(", "self", ".", "_ReplaceRegExPart", "(", "p", ")", "for"...
5cef4e8e2f0d5df43ea4877e9c798e0bf60bfe74
train
dateadd
Add a value to a date.
examples/marshmallow_example.py
def dateadd(value: fields.DateTime(), addend: fields.Int(validate=Range(min=1)), unit: fields.Str(validate=OneOf(['minutes', 'days']))='days'): """Add a value to a date.""" value = value or dt.datetime.utcnow() if unit == 'minutes': delta = dt.timedelta(minutes=addend) el...
def dateadd(value: fields.DateTime(), addend: fields.Int(validate=Range(min=1)), unit: fields.Str(validate=OneOf(['minutes', 'days']))='days'): """Add a value to a date.""" value = value or dt.datetime.utcnow() if unit == 'minutes': delta = dt.timedelta(minutes=addend) el...
[ "Add", "a", "value", "to", "a", "date", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/marshmallow_example.py#L26-L36
[ "def", "dateadd", "(", "value", ":", "fields", ".", "DateTime", "(", ")", ",", "addend", ":", "fields", ".", "Int", "(", "validate", "=", "Range", "(", "min", "=", "1", ")", ")", ",", "unit", ":", "fields", ".", "Str", "(", "validate", "=", "OneO...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
arguments
Returns the name of all arguments a function takes
hug/introspect.py
def arguments(function, extra_arguments=0): """Returns the name of all arguments a function takes""" if not hasattr(function, '__code__'): return () return function.__code__.co_varnames[:function.__code__.co_argcount + extra_arguments]
def arguments(function, extra_arguments=0): """Returns the name of all arguments a function takes""" if not hasattr(function, '__code__'): return () return function.__code__.co_varnames[:function.__code__.co_argcount + extra_arguments]
[ "Returns", "the", "name", "of", "all", "arguments", "a", "function", "takes" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/introspect.py#L43-L48
[ "def", "arguments", "(", "function", ",", "extra_arguments", "=", "0", ")", ":", "if", "not", "hasattr", "(", "function", ",", "'__code__'", ")", ":", "return", "(", ")", "return", "function", ".", "__code__", ".", "co_varnames", "[", ":", "function", "....
080901c81576657f82e2432fd4a82f1d0d2f370c
train
generate_accepted_kwargs
Dynamically creates a function that when called with dictionary of arguments will produce a kwarg that's compatible with the supplied function
hug/introspect.py
def generate_accepted_kwargs(function, *named_arguments): """Dynamically creates a function that when called with dictionary of arguments will produce a kwarg that's compatible with the supplied function """ if hasattr(function, '__code__') and takes_kwargs(function): function_takes_kwargs = ...
def generate_accepted_kwargs(function, *named_arguments): """Dynamically creates a function that when called with dictionary of arguments will produce a kwarg that's compatible with the supplied function """ if hasattr(function, '__code__') and takes_kwargs(function): function_takes_kwargs = ...
[ "Dynamically", "creates", "a", "function", "that", "when", "called", "with", "dictionary", "of", "arguments", "will", "produce", "a", "kwarg", "that", "s", "compatible", "with", "the", "supplied", "function" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/introspect.py#L71-L88
[ "def", "generate_accepted_kwargs", "(", "function", ",", "*", "named_arguments", ")", ":", "if", "hasattr", "(", "function", ",", "'__code__'", ")", "and", "takes_kwargs", "(", "function", ")", ":", "function_takes_kwargs", "=", "True", "function_takes_arguments", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
authenticator
Wraps authentication logic, verify_user through to the authentication function. The verify_user function passed in should accept an API key and return a user object to store in the request context if authentication succeeded.
hug/authentication.py
def authenticator(function, challenges=()): """Wraps authentication logic, verify_user through to the authentication function. The verify_user function passed in should accept an API key and return a user object to store in the request context if authentication succeeded. """ challenges = challenge...
def authenticator(function, challenges=()): """Wraps authentication logic, verify_user through to the authentication function. The verify_user function passed in should accept an API key and return a user object to store in the request context if authentication succeeded. """ challenges = challenge...
[ "Wraps", "authentication", "logic", "verify_user", "through", "to", "the", "authentication", "function", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/authentication.py#L30-L64
[ "def", "authenticator", "(", "function", ",", "challenges", "=", "(", ")", ")", ":", "challenges", "=", "challenges", "or", "(", "'{} realm=\"simple\"'", ".", "format", "(", "function", ".", "__name__", ")", ",", ")", "def", "wrapper", "(", "verify_user", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
basic
Basic HTTP Authentication
hug/authentication.py
def basic(request, response, verify_user, realm='simple', context=None, **kwargs): """Basic HTTP Authentication""" http_auth = request.auth response.set_header('WWW-Authenticate', 'Basic') if http_auth is None: return if isinstance(http_auth, bytes): http_auth = http_auth.decode('ut...
def basic(request, response, verify_user, realm='simple', context=None, **kwargs): """Basic HTTP Authentication""" http_auth = request.auth response.set_header('WWW-Authenticate', 'Basic') if http_auth is None: return if isinstance(http_auth, bytes): http_auth = http_auth.decode('ut...
[ "Basic", "HTTP", "Authentication" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/authentication.py#L68-L98
[ "def", "basic", "(", "request", ",", "response", ",", "verify_user", ",", "realm", "=", "'simple'", ",", "context", "=", "None", ",", "*", "*", "kwargs", ")", ":", "http_auth", "=", "request", ".", "auth", "response", ".", "set_header", "(", "'WWW-Authen...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
api_key
API Key Header Authentication The verify_user function passed in to ths authenticator shall receive an API key as input, and return a user object to store in the request context if the request was successful.
hug/authentication.py
def api_key(request, response, verify_user, context=None, **kwargs): """API Key Header Authentication The verify_user function passed in to ths authenticator shall receive an API key as input, and return a user object to store in the request context if the request was successful. """ api_key = ...
def api_key(request, response, verify_user, context=None, **kwargs): """API Key Header Authentication The verify_user function passed in to ths authenticator shall receive an API key as input, and return a user object to store in the request context if the request was successful. """ api_key = ...
[ "API", "Key", "Header", "Authentication" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/authentication.py#L102-L121
[ "def", "api_key", "(", "request", ",", "response", ",", "verify_user", ",", "context", "=", "None", ",", "*", "*", "kwargs", ")", ":", "api_key", "=", "request", ".", "get_header", "(", "'X-Api-Key'", ")", "if", "api_key", ":", "try", ":", "user", "=",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
token
Token verification Checks for the Authorization header and verifies using the verify_user function
hug/authentication.py
def token(request, response, verify_user, context=None, **kwargs): """Token verification Checks for the Authorization header and verifies using the verify_user function """ token = request.get_header('Authorization') if token: try: verified_token = verify_user(token) exc...
def token(request, response, verify_user, context=None, **kwargs): """Token verification Checks for the Authorization header and verifies using the verify_user function """ token = request.get_header('Authorization') if token: try: verified_token = verify_user(token) exc...
[ "Token", "verification" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/authentication.py#L125-L140
[ "def", "token", "(", "request", ",", "response", ",", "verify_user", ",", "context", "=", "None", ",", "*", "*", "kwargs", ")", ":", "token", "=", "request", ".", "get_header", "(", "'Authorization'", ")", "if", "token", ":", "try", ":", "verified_token"...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
verify
Returns a simple verification callback that simply verifies that the users and password match that provided
hug/authentication.py
def verify(user, password): """Returns a simple verification callback that simply verifies that the users and password match that provided""" def verify_user(user_name, user_password): if user_name == user and user_password == password: return user_name return False return verify...
def verify(user, password): """Returns a simple verification callback that simply verifies that the users and password match that provided""" def verify_user(user_name, user_password): if user_name == user and user_password == password: return user_name return False return verify...
[ "Returns", "a", "simple", "verification", "callback", "that", "simply", "verifies", "that", "the", "users", "and", "password", "match", "that", "provided" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/authentication.py#L143-L149
[ "def", "verify", "(", "user", ",", "password", ")", ":", "def", "verify_user", "(", "user_name", ",", "user_password", ")", ":", "if", "user_name", "==", "user", "and", "user_password", "==", "password", ":", "return", "user_name", "return", "False", "return...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
SessionMiddleware.process_request
Get session ID from cookie, load corresponding session data from coupled store and inject session data into the request context.
hug/middleware.py
def process_request(self, request, response): """Get session ID from cookie, load corresponding session data from coupled store and inject session data into the request context. """ sid = request.cookies.get(self.cookie_name, None) data = {} if sid is not None: ...
def process_request(self, request, response): """Get session ID from cookie, load corresponding session data from coupled store and inject session data into the request context. """ sid = request.cookies.get(self.cookie_name, None) data = {} if sid is not None: ...
[ "Get", "session", "ID", "from", "cookie", "load", "corresponding", "session", "data", "from", "coupled", "store", "and", "inject", "session", "data", "into", "the", "request", "context", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/middleware.py#L61-L70
[ "def", "process_request", "(", "self", ",", "request", ",", "response", ")", ":", "sid", "=", "request", ".", "cookies", ".", "get", "(", "self", ".", "cookie_name", ",", "None", ")", "data", "=", "{", "}", "if", "sid", "is", "not", "None", ":", "i...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
SessionMiddleware.process_response
Save request context in coupled store object. Set cookie containing a session ID.
hug/middleware.py
def process_response(self, request, response, resource, req_succeeded): """Save request context in coupled store object. Set cookie containing a session ID.""" sid = request.cookies.get(self.cookie_name, None) if sid is None or not self.store.exists(sid): sid = self.generate_sid() ...
def process_response(self, request, response, resource, req_succeeded): """Save request context in coupled store object. Set cookie containing a session ID.""" sid = request.cookies.get(self.cookie_name, None) if sid is None or not self.store.exists(sid): sid = self.generate_sid() ...
[ "Save", "request", "context", "in", "coupled", "store", "object", ".", "Set", "cookie", "containing", "a", "session", "ID", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/middleware.py#L72-L81
[ "def", "process_response", "(", "self", ",", "request", ",", "response", ",", "resource", ",", "req_succeeded", ")", ":", "sid", "=", "request", ".", "cookies", ".", "get", "(", "self", ".", "cookie_name", ",", "None", ")", "if", "sid", "is", "None", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
LogMiddleware._generate_combined_log
Given a request/response pair, generate a logging format similar to the NGINX combined style.
hug/middleware.py
def _generate_combined_log(self, request, response): """Given a request/response pair, generate a logging format similar to the NGINX combined style.""" current_time = datetime.utcnow() data_len = '-' if response.data is None else len(response.data) return '{0} - - [{1}] {2} {3} {4} {5} ...
def _generate_combined_log(self, request, response): """Given a request/response pair, generate a logging format similar to the NGINX combined style.""" current_time = datetime.utcnow() data_len = '-' if response.data is None else len(response.data) return '{0} - - [{1}] {2} {3} {4} {5} ...
[ "Given", "a", "request", "/", "response", "pair", "generate", "a", "logging", "format", "similar", "to", "the", "NGINX", "combined", "style", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/middleware.py#L91-L97
[ "def", "_generate_combined_log", "(", "self", ",", "request", ",", "response", ")", ":", "current_time", "=", "datetime", ".", "utcnow", "(", ")", "data_len", "=", "'-'", "if", "response", ".", "data", "is", "None", "else", "len", "(", "response", ".", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
LogMiddleware.process_request
Logs the basic endpoint requested
hug/middleware.py
def process_request(self, request, response): """Logs the basic endpoint requested""" self.logger.info('Requested: {0} {1} {2}'.format(request.method, request.relative_uri, request.content_type))
def process_request(self, request, response): """Logs the basic endpoint requested""" self.logger.info('Requested: {0} {1} {2}'.format(request.method, request.relative_uri, request.content_type))
[ "Logs", "the", "basic", "endpoint", "requested" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/middleware.py#L99-L101
[ "def", "process_request", "(", "self", ",", "request", ",", "response", ")", ":", "self", ".", "logger", ".", "info", "(", "'Requested: {0} {1} {2}'", ".", "format", "(", "request", ".", "method", ",", "request", ".", "relative_uri", ",", "request", ".", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
LogMiddleware.process_response
Logs the basic data returned by the API
hug/middleware.py
def process_response(self, request, response, resource, req_succeeded): """Logs the basic data returned by the API""" self.logger.info(self._generate_combined_log(request, response))
def process_response(self, request, response, resource, req_succeeded): """Logs the basic data returned by the API""" self.logger.info(self._generate_combined_log(request, response))
[ "Logs", "the", "basic", "data", "returned", "by", "the", "API" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/middleware.py#L103-L105
[ "def", "process_response", "(", "self", ",", "request", ",", "response", ",", "resource", ",", "req_succeeded", ")", ":", "self", ".", "logger", ".", "info", "(", "self", ".", "_generate_combined_log", "(", "request", ",", "response", ")", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
CORSMiddleware.match_route
Match a request with parameter to it's corresponding route
hug/middleware.py
def match_route(self, reqpath): """Match a request with parameter to it's corresponding route""" route_dicts = [routes for _, routes in self.api.http.routes.items()][0] routes = [route for route, _ in route_dicts.items()] if reqpath not in routes: for route in routes: # repl...
def match_route(self, reqpath): """Match a request with parameter to it's corresponding route""" route_dicts = [routes for _, routes in self.api.http.routes.items()][0] routes = [route for route, _ in route_dicts.items()] if reqpath not in routes: for route in routes: # repl...
[ "Match", "a", "request", "with", "parameter", "to", "it", "s", "corresponding", "route" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/middleware.py#L122-L134
[ "def", "match_route", "(", "self", ",", "reqpath", ")", ":", "route_dicts", "=", "[", "routes", "for", "_", ",", "routes", "in", "self", ".", "api", ".", "http", ".", "routes", ".", "items", "(", ")", "]", "[", "0", "]", "routes", "=", "[", "rout...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
CORSMiddleware.process_response
Add CORS headers to the response
hug/middleware.py
def process_response(self, request, response, resource, req_succeeded): """Add CORS headers to the response""" response.set_header('Access-Control-Allow-Credentials', str(self.allow_credentials).lower()) origin = request.get_header('ORIGIN') if origin and (origin in self.allow_origins) ...
def process_response(self, request, response, resource, req_succeeded): """Add CORS headers to the response""" response.set_header('Access-Control-Allow-Credentials', str(self.allow_credentials).lower()) origin = request.get_header('ORIGIN') if origin and (origin in self.allow_origins) ...
[ "Add", "CORS", "headers", "to", "the", "response" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/middleware.py#L136-L162
[ "def", "process_response", "(", "self", ",", "request", ",", "response", ",", "resource", ",", "req_succeeded", ")", ":", "response", ".", "set_header", "(", "'Access-Control-Allow-Credentials'", ",", "str", "(", "self", ".", "allow_credentials", ")", ".", "lowe...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
create
Creates a new type handler with the specified type-casting handler
hug/types.py
def create(doc=None, error_text=None, exception_handlers=empty.dict, extend=Type, chain=True, auto_instance=True, accept_context=False): """Creates a new type handler with the specified type-casting handler""" extend = extend if type(extend) == type else type(extend) def new_type_handler(functio...
def create(doc=None, error_text=None, exception_handlers=empty.dict, extend=Type, chain=True, auto_instance=True, accept_context=False): """Creates a new type handler with the specified type-casting handler""" extend = extend if type(extend) == type else type(extend) def new_type_handler(functio...
[ "Creates", "a", "new", "type", "handler", "with", "the", "specified", "type", "-", "casting", "handler" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/types.py#L48-L165
[ "def", "create", "(", "doc", "=", "None", ",", "error_text", "=", "None", ",", "exception_handlers", "=", "empty", ".", "dict", ",", "extend", "=", "Type", ",", "chain", "=", "True", ",", "auto_instance", "=", "True", ",", "accept_context", "=", "False",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
accept
Allows quick wrapping of any Python type cast function for use as a hug type annotation
hug/types.py
def accept(kind, doc=None, error_text=None, exception_handlers=empty.dict, accept_context=False): """Allows quick wrapping of any Python type cast function for use as a hug type annotation""" return create( doc, error_text, exception_handlers=exception_handlers, chain=False, ...
def accept(kind, doc=None, error_text=None, exception_handlers=empty.dict, accept_context=False): """Allows quick wrapping of any Python type cast function for use as a hug type annotation""" return create( doc, error_text, exception_handlers=exception_handlers, chain=False, ...
[ "Allows", "quick", "wrapping", "of", "any", "Python", "type", "cast", "function", "for", "use", "as", "a", "hug", "type", "annotation" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/types.py#L168-L176
[ "def", "accept", "(", "kind", ",", "doc", "=", "None", ",", "error_text", "=", "None", ",", "exception_handlers", "=", "empty", ".", "dict", ",", "accept_context", "=", "False", ")", ":", "return", "create", "(", "doc", ",", "error_text", ",", "exception...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
to
Redirects to the specified location using the provided http_code (defaults to HTTP_302 FOUND)
hug/redirect.py
def to(location, code=falcon.HTTP_302): """Redirects to the specified location using the provided http_code (defaults to HTTP_302 FOUND)""" raise falcon.http_status.HTTPStatus(code, {'location': location})
def to(location, code=falcon.HTTP_302): """Redirects to the specified location using the provided http_code (defaults to HTTP_302 FOUND)""" raise falcon.http_status.HTTPStatus(code, {'location': location})
[ "Redirects", "to", "the", "specified", "location", "using", "the", "provided", "http_code", "(", "defaults", "to", "HTTP_302", "FOUND", ")" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/redirect.py#L27-L29
[ "def", "to", "(", "location", ",", "code", "=", "falcon", ".", "HTTP_302", ")", ":", "raise", "falcon", ".", "http_status", ".", "HTTPStatus", "(", "code", ",", "{", "'location'", ":", "location", "}", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
underscore
Converts text that may be camelcased into an underscored format
hug/format.py
def underscore(text): """Converts text that may be camelcased into an underscored format""" return UNDERSCORE[1].sub(r'\1_\2', UNDERSCORE[0].sub(r'\1_\2', text)).lower()
def underscore(text): """Converts text that may be camelcased into an underscored format""" return UNDERSCORE[1].sub(r'\1_\2', UNDERSCORE[0].sub(r'\1_\2', text)).lower()
[ "Converts", "text", "that", "may", "be", "camelcased", "into", "an", "underscored", "format" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/format.py#L48-L50
[ "def", "underscore", "(", "text", ")", ":", "return", "UNDERSCORE", "[", "1", "]", ".", "sub", "(", "r'\\1_\\2'", ",", "UNDERSCORE", "[", "0", "]", ".", "sub", "(", "r'\\1_\\2'", ",", "text", ")", ")", ".", "lower", "(", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
hug
Hug API Development Server
hug/development_runner.py
def hug(file: 'A Python file that contains a Hug API'=None, module: 'A Python module that contains a Hug API'=None, host: 'Interface to bind to'='', port: number=8000, no_404_documentation: boolean=False, manual_reload: boolean=False, interval: number=1, command: 'Run a command defined in the gi...
def hug(file: 'A Python file that contains a Hug API'=None, module: 'A Python module that contains a Hug API'=None, host: 'Interface to bind to'='', port: number=8000, no_404_documentation: boolean=False, manual_reload: boolean=False, interval: number=1, command: 'Run a command defined in the gi...
[ "Hug", "API", "Development", "Server" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/development_runner.py#L46-L99
[ "def", "hug", "(", "file", ":", "'A Python file that contains a Hug API'", "=", "None", ",", "module", ":", "'A Python module that contains a Hug API'", "=", "None", ",", "host", ":", "'Interface to bind to'", "=", "''", ",", "port", ":", "number", "=", "8000", ",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
token_gen_call
Authenticate and return a token
examples/authentication.py
def token_gen_call(username, password): """Authenticate and return a token""" secret_key = 'super-secret-key-please-change' mockusername = 'User2' mockpassword = 'Mypassword' if mockpassword == password and mockusername == username: # This is an example. Don't do that. return {"token" : jwt....
def token_gen_call(username, password): """Authenticate and return a token""" secret_key = 'super-secret-key-please-change' mockusername = 'User2' mockpassword = 'Mypassword' if mockpassword == password and mockusername == username: # This is an example. Don't do that. return {"token" : jwt....
[ "Authenticate", "and", "return", "a", "token" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/authentication.py#L77-L84
[ "def", "token_gen_call", "(", "username", ",", "password", ")", ":", "secret_key", "=", "'super-secret-key-please-change'", "mockusername", "=", "'User2'", "mockpassword", "=", "'Mypassword'", "if", "mockpassword", "==", "password", "and", "mockusername", "==", "usern...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
documentation
returns documentation for the current api
hug/directives.py
def documentation(default=None, api_version=None, api=None, **kwargs): """returns documentation for the current api""" api_version = default or api_version if api: return api.http.documentation(base_url="", api_version=api_version)
def documentation(default=None, api_version=None, api=None, **kwargs): """returns documentation for the current api""" api_version = default or api_version if api: return api.http.documentation(base_url="", api_version=api_version)
[ "returns", "documentation", "for", "the", "current", "api" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/directives.py#L84-L88
[ "def", "documentation", "(", "default", "=", "None", ",", "api_version", "=", "None", ",", "api", "=", "None", ",", "*", "*", "kwargs", ")", ":", "api_version", "=", "default", "or", "api_version", "if", "api", ":", "return", "api", ".", "http", ".", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
json
Takes JSON formatted data, converting it into native Python objects
hug/input_format.py
def json(body, charset='utf-8', **kwargs): """Takes JSON formatted data, converting it into native Python objects""" return json_converter.loads(text(body, charset=charset))
def json(body, charset='utf-8', **kwargs): """Takes JSON formatted data, converting it into native Python objects""" return json_converter.loads(text(body, charset=charset))
[ "Takes", "JSON", "formatted", "data", "converting", "it", "into", "native", "Python", "objects" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/input_format.py#L41-L43
[ "def", "json", "(", "body", ",", "charset", "=", "'utf-8'", ",", "*", "*", "kwargs", ")", ":", "return", "json_converter", ".", "loads", "(", "text", "(", "body", ",", "charset", "=", "charset", ")", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
urlencoded
Converts query strings into native Python objects
hug/input_format.py
def urlencoded(body, charset='ascii', **kwargs): """Converts query strings into native Python objects""" return parse_query_string(text(body, charset=charset), False)
def urlencoded(body, charset='ascii', **kwargs): """Converts query strings into native Python objects""" return parse_query_string(text(body, charset=charset), False)
[ "Converts", "query", "strings", "into", "native", "Python", "objects" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/input_format.py#L66-L68
[ "def", "urlencoded", "(", "body", ",", "charset", "=", "'ascii'", ",", "*", "*", "kwargs", ")", ":", "return", "parse_query_string", "(", "text", "(", "body", ",", "charset", "=", "charset", ")", ",", "False", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
multipart
Converts multipart form data into native Python objects
hug/input_format.py
def multipart(body, content_length=0, **header_params): """Converts multipart form data into native Python objects""" header_params.setdefault('CONTENT-LENGTH', content_length) if header_params and 'boundary' in header_params: if type(header_params['boundary']) is str: header_params['bou...
def multipart(body, content_length=0, **header_params): """Converts multipart form data into native Python objects""" header_params.setdefault('CONTENT-LENGTH', content_length) if header_params and 'boundary' in header_params: if type(header_params['boundary']) is str: header_params['bou...
[ "Converts", "multipart", "form", "data", "into", "native", "Python", "objects" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/input_format.py#L72-L83
[ "def", "multipart", "(", "body", ",", "content_length", "=", "0", ",", "*", "*", "header_params", ")", ":", "header_params", ".", "setdefault", "(", "'CONTENT-LENGTH'", ",", "content_length", ")", "if", "header_params", "and", "'boundary'", "in", "header_params"...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
setup
Sets up and fills test directory for serving. Using different filetypes to see how they are dealt with. The tempoary directory will clean itself up.
examples/static_serve.py
def setup(api=None): """Sets up and fills test directory for serving. Using different filetypes to see how they are dealt with. The tempoary directory will clean itself up. """ global tmp_dir_object tmp_dir_object = tempfile.TemporaryDirectory() dir_name = tmp_dir_object.name dir_a =...
def setup(api=None): """Sets up and fills test directory for serving. Using different filetypes to see how they are dealt with. The tempoary directory will clean itself up. """ global tmp_dir_object tmp_dir_object = tempfile.TemporaryDirectory() dir_name = tmp_dir_object.name dir_a =...
[ "Sets", "up", "and", "fills", "test", "directory", "for", "serving", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/static_serve.py#L12-L48
[ "def", "setup", "(", "api", "=", "None", ")", ":", "global", "tmp_dir_object", "tmp_dir_object", "=", "tempfile", ".", "TemporaryDirectory", "(", ")", "dir_name", "=", "tmp_dir_object", ".", "name", "dir_a", "=", "os", ".", "path", ".", "join", "(", "dir_n...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
content_type
Returns a different transformer depending on the content type passed in. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[content-type]': transformation_action, ... }
hug/transform.py
def content_type(transformers, default=None): """Returns a different transformer depending on the content type passed in. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[content-type]': transformation_action, ...
def content_type(transformers, default=None): """Returns a different transformer depending on the content type passed in. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[content-type]': transformation_action, ...
[ "Returns", "a", "different", "transformer", "depending", "on", "the", "content", "type", "passed", "in", ".", "If", "none", "match", "and", "no", "default", "is", "given", "no", "transformation", "takes", "place", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/transform.py#L27-L47
[ "def", "content_type", "(", "transformers", ",", "default", "=", "None", ")", ":", "transformers", "=", "{", "content_type", ":", "auto_kwargs", "(", "transformer", ")", "if", "transformer", "else", "transformer", "for", "content_type", ",", "transformer", "in",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
suffix
Returns a different transformer depending on the suffix at the end of the requested URL. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[suffix]': transformation_action, ... }
hug/transform.py
def suffix(transformers, default=None): """Returns a different transformer depending on the suffix at the end of the requested URL. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[suffix]': transformation_action, ...
def suffix(transformers, default=None): """Returns a different transformer depending on the suffix at the end of the requested URL. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[suffix]': transformation_action, ...
[ "Returns", "a", "different", "transformer", "depending", "on", "the", "suffix", "at", "the", "end", "of", "the", "requested", "URL", ".", "If", "none", "match", "and", "no", "default", "is", "given", "no", "transformation", "takes", "place", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/transform.py#L50-L73
[ "def", "suffix", "(", "transformers", ",", "default", "=", "None", ")", ":", "transformers", "=", "{", "suffix", ":", "auto_kwargs", "(", "transformer", ")", "if", "transformer", "else", "transformer", "for", "suffix", ",", "transformer", "in", "transformers",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
prefix
Returns a different transformer depending on the prefix at the end of the requested URL. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[prefix]': transformation_action, ... }
hug/transform.py
def prefix(transformers, default=None): """Returns a different transformer depending on the prefix at the end of the requested URL. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[prefix]': transformation_action, ...
def prefix(transformers, default=None): """Returns a different transformer depending on the prefix at the end of the requested URL. If none match and no default is given no transformation takes place. should pass in a dict with the following format: {'[prefix]': transformation_action, ...
[ "Returns", "a", "different", "transformer", "depending", "on", "the", "prefix", "at", "the", "end", "of", "the", "requested", "URL", ".", "If", "none", "match", "and", "no", "default", "is", "given", "no", "transformation", "takes", "place", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/transform.py#L76-L99
[ "def", "prefix", "(", "transformers", ",", "default", "=", "None", ")", ":", "transformers", "=", "{", "prefix", ":", "auto_kwargs", "(", "transformer", ")", "if", "transformer", "else", "transformer", "for", "prefix", ",", "transformer", "in", "transformers",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
all
Returns the results of applying all passed in transformers to data should pass in list of transformers [transformer_1, transformer_2...]
hug/transform.py
def all(*transformers): """Returns the results of applying all passed in transformers to data should pass in list of transformers [transformer_1, transformer_2...] """ transformers = tuple(auto_kwargs(transformer) for transformer in transformers) def transform(data, request=None, r...
def all(*transformers): """Returns the results of applying all passed in transformers to data should pass in list of transformers [transformer_1, transformer_2...] """ transformers = tuple(auto_kwargs(transformer) for transformer in transformers) def transform(data, request=None, r...
[ "Returns", "the", "results", "of", "applying", "all", "passed", "in", "transformers", "to", "data" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/transform.py#L102-L116
[ "def", "all", "(", "*", "transformers", ")", ":", "transformers", "=", "tuple", "(", "auto_kwargs", "(", "transformer", ")", "for", "transformer", "in", "transformers", ")", "def", "transform", "(", "data", ",", "request", "=", "None", ",", "response", "="...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Interface.validate
Runs all set type transformers / validators against the provided input parameters and returns any errors
hug/interface.py
def validate(self, input_parameters, context): """Runs all set type transformers / validators against the provided input parameters and returns any errors""" errors = {} for key, type_handler in self.input_transformations.items(): if self.raise_on_invalid: if key in ...
def validate(self, input_parameters, context): """Runs all set type transformers / validators against the provided input parameters and returns any errors""" errors = {} for key, type_handler in self.input_transformations.items(): if self.raise_on_invalid: if key in ...
[ "Runs", "all", "set", "type", "transformers", "/", "validators", "against", "the", "provided", "input", "parameters", "and", "returns", "any", "errors" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L198-L230
[ "def", "validate", "(", "self", ",", "input_parameters", ",", "context", ")", ":", "errors", "=", "{", "}", "for", "key", ",", "type_handler", "in", "self", ".", "input_transformations", ".", "items", "(", ")", ":", "if", "self", ".", "raise_on_invalid", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Interface.check_requirements
Checks to see if all requirements set pass if all requirements pass nothing will be returned otherwise, the error reported will be returned
hug/interface.py
def check_requirements(self, request=None, response=None, context=None): """Checks to see if all requirements set pass if all requirements pass nothing will be returned otherwise, the error reported will be returned """ for requirement in self.requires: conclus...
def check_requirements(self, request=None, response=None, context=None): """Checks to see if all requirements set pass if all requirements pass nothing will be returned otherwise, the error reported will be returned """ for requirement in self.requires: conclus...
[ "Checks", "to", "see", "if", "all", "requirements", "set", "pass" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L232-L241
[ "def", "check_requirements", "(", "self", ",", "request", "=", "None", ",", "response", "=", "None", ",", "context", "=", "None", ")", ":", "for", "requirement", "in", "self", ".", "requires", ":", "conclusion", "=", "requirement", "(", "response", "=", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Interface.documentation
Produces general documentation for the interface
hug/interface.py
def documentation(self, add_to=None): """Produces general documentation for the interface""" doc = OrderedDict if add_to is None else add_to usage = self.interface.spec.__doc__ if usage: doc['usage'] = usage if getattr(self, 'requires', None): doc['requir...
def documentation(self, add_to=None): """Produces general documentation for the interface""" doc = OrderedDict if add_to is None else add_to usage = self.interface.spec.__doc__ if usage: doc['usage'] = usage if getattr(self, 'requires', None): doc['requir...
[ "Produces", "general", "documentation", "for", "the", "interface" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L243-L273
[ "def", "documentation", "(", "self", ",", "add_to", "=", "None", ")", ":", "doc", "=", "OrderedDict", "if", "add_to", "is", "None", "else", "add_to", "usage", "=", "self", ".", "interface", ".", "spec", ".", "__doc__", "if", "usage", ":", "doc", "[", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
CLI.output
Outputs the provided data using the transformations and output format specified for this CLI endpoint
hug/interface.py
def output(self, data, context): """Outputs the provided data using the transformations and output format specified for this CLI endpoint""" if self.transform: if hasattr(self.transform, 'context'): self.transform.context = context data = self.transform(data) ...
def output(self, data, context): """Outputs the provided data using the transformations and output format specified for this CLI endpoint""" if self.transform: if hasattr(self.transform, 'context'): self.transform.context = context data = self.transform(data) ...
[ "Outputs", "the", "provided", "data", "using", "the", "transformations", "and", "output", "format", "specified", "for", "this", "CLI", "endpoint" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L458-L472
[ "def", "output", "(", "self", ",", "data", ",", "context", ")", ":", "if", "self", ".", "transform", ":", "if", "hasattr", "(", "self", ".", "transform", ",", "'context'", ")", ":", "self", ".", "transform", ".", "context", "=", "context", "data", "=...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.gather_parameters
Gathers and returns all parameters that will be used for this endpoint
hug/interface.py
def gather_parameters(self, request, response, context, api_version=None, **input_parameters): """Gathers and returns all parameters that will be used for this endpoint""" input_parameters.update(request.params) if self.parse_body and request.content_length: body = request.stream ...
def gather_parameters(self, request, response, context, api_version=None, **input_parameters): """Gathers and returns all parameters that will be used for this endpoint""" input_parameters.update(request.params) if self.parse_body and request.content_length: body = request.stream ...
[ "Gathers", "and", "returns", "all", "parameters", "that", "will", "be", "used", "for", "this", "endpoint" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L596-L624
[ "def", "gather_parameters", "(", "self", ",", "request", ",", "response", ",", "context", ",", "api_version", "=", "None", ",", "*", "*", "input_parameters", ")", ":", "input_parameters", ".", "update", "(", "request", ".", "params", ")", "if", "self", "."...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.transform_data
Runs the transforms specified on this endpoint with the provided data, returning the data modified
hug/interface.py
def transform_data(self, data, request=None, response=None, context=None): transform = self.transform if hasattr(transform, 'context'): self.transform.context = context """Runs the transforms specified on this endpoint with the provided data, returning the data modified""" if...
def transform_data(self, data, request=None, response=None, context=None): transform = self.transform if hasattr(transform, 'context'): self.transform.context = context """Runs the transforms specified on this endpoint with the provided data, returning the data modified""" if...
[ "Runs", "the", "transforms", "specified", "on", "this", "endpoint", "with", "the", "provided", "data", "returning", "the", "data", "modified" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L634-L644
[ "def", "transform_data", "(", "self", ",", "data", ",", "request", "=", "None", ",", "response", "=", "None", ",", "context", "=", "None", ")", ":", "transform", "=", "self", ".", "transform", "if", "hasattr", "(", "transform", ",", "'context'", ")", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.content_type
Returns the content type that should be used by default for this endpoint
hug/interface.py
def content_type(self, request=None, response=None): """Returns the content type that should be used by default for this endpoint""" if callable(self.outputs.content_type): return self.outputs.content_type(request=request, response=response) else: return self.outputs.cont...
def content_type(self, request=None, response=None): """Returns the content type that should be used by default for this endpoint""" if callable(self.outputs.content_type): return self.outputs.content_type(request=request, response=response) else: return self.outputs.cont...
[ "Returns", "the", "content", "type", "that", "should", "be", "used", "by", "default", "for", "this", "endpoint" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L646-L651
[ "def", "content_type", "(", "self", ",", "request", "=", "None", ",", "response", "=", "None", ")", ":", "if", "callable", "(", "self", ".", "outputs", ".", "content_type", ")", ":", "return", "self", ".", "outputs", ".", "content_type", "(", "request", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.invalid_content_type
Returns the content type that should be used by default on validation errors
hug/interface.py
def invalid_content_type(self, request=None, response=None): """Returns the content type that should be used by default on validation errors""" if callable(self.invalid_outputs.content_type): return self.invalid_outputs.content_type(request=request, response=response) else: ...
def invalid_content_type(self, request=None, response=None): """Returns the content type that should be used by default on validation errors""" if callable(self.invalid_outputs.content_type): return self.invalid_outputs.content_type(request=request, response=response) else: ...
[ "Returns", "the", "content", "type", "that", "should", "be", "used", "by", "default", "on", "validation", "errors" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L653-L658
[ "def", "invalid_content_type", "(", "self", ",", "request", "=", "None", ",", "response", "=", "None", ")", ":", "if", "callable", "(", "self", ".", "invalid_outputs", ".", "content_type", ")", ":", "return", "self", ".", "invalid_outputs", ".", "content_typ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.set_response_defaults
Sets up the response defaults that are defined in the URL route
hug/interface.py
def set_response_defaults(self, response, request=None): """Sets up the response defaults that are defined in the URL route""" for header_name, header_value in self.response_headers: response.set_header(header_name, header_value) if self.set_status: response.status = self...
def set_response_defaults(self, response, request=None): """Sets up the response defaults that are defined in the URL route""" for header_name, header_value in self.response_headers: response.set_header(header_name, header_value) if self.set_status: response.status = self...
[ "Sets", "up", "the", "response", "defaults", "that", "are", "defined", "in", "the", "URL", "route" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L671-L677
[ "def", "set_response_defaults", "(", "self", ",", "response", ",", "request", "=", "None", ")", ":", "for", "header_name", ",", "header_value", "in", "self", ".", "response_headers", ":", "response", ".", "set_header", "(", "header_name", ",", "header_value", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.documentation
Returns the documentation specific to an HTTP interface
hug/interface.py
def documentation(self, add_to=None, version=None, prefix="", base_url="", url=""): """Returns the documentation specific to an HTTP interface""" doc = OrderedDict() if add_to is None else add_to usage = self.interface.spec.__doc__ if usage: doc['usage'] = usage for...
def documentation(self, add_to=None, version=None, prefix="", base_url="", url=""): """Returns the documentation specific to an HTTP interface""" doc = OrderedDict() if add_to is None else add_to usage = self.interface.spec.__doc__ if usage: doc['usage'] = usage for...
[ "Returns", "the", "documentation", "specific", "to", "an", "HTTP", "interface" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L793-L814
[ "def", "documentation", "(", "self", ",", "add_to", "=", "None", ",", "version", "=", "None", ",", "prefix", "=", "\"\"", ",", "base_url", "=", "\"\"", ",", "url", "=", "\"\"", ")", ":", "doc", "=", "OrderedDict", "(", ")", "if", "add_to", "is", "N...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.urls
Returns all URLS that are mapped to this interface
hug/interface.py
def urls(self, version=None): """Returns all URLS that are mapped to this interface""" urls = [] for base_url, routes in self.api.http.routes.items(): for url, methods in routes.items(): for method, versions in methods.items(): for interface_versio...
def urls(self, version=None): """Returns all URLS that are mapped to this interface""" urls = [] for base_url, routes in self.api.http.routes.items(): for url, methods in routes.items(): for method, versions in methods.items(): for interface_versio...
[ "Returns", "all", "URLS", "that", "are", "mapped", "to", "this", "interface" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L817-L827
[ "def", "urls", "(", "self", ",", "version", "=", "None", ")", ":", "urls", "=", "[", "]", "for", "base_url", ",", "routes", "in", "self", ".", "api", ".", "http", ".", "routes", ".", "items", "(", ")", ":", "for", "url", ",", "methods", "in", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTP.url
Returns the first matching URL found for the specified arguments
hug/interface.py
def url(self, version=None, **kwargs): """Returns the first matching URL found for the specified arguments""" for url in self.urls(version): if [key for key in kwargs.keys() if not '{' + key + '}' in url]: continue return url.format(**kwargs) raise KeyEr...
def url(self, version=None, **kwargs): """Returns the first matching URL found for the specified arguments""" for url in self.urls(version): if [key for key in kwargs.keys() if not '{' + key + '}' in url]: continue return url.format(**kwargs) raise KeyEr...
[ "Returns", "the", "first", "matching", "URL", "found", "for", "the", "specified", "arguments" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/interface.py#L829-L837
[ "def", "url", "(", "self", ",", "version", "=", "None", ",", "*", "*", "kwargs", ")", ":", "for", "url", "in", "self", ".", "urls", "(", "version", ")", ":", "if", "[", "key", "for", "key", "in", "kwargs", ".", "keys", "(", ")", "if", "not", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
greet
Greets appropriately (from http://blog.ketchum.com/how-to-write-10-common-holiday-greetings/)
examples/happy_birthday.py
def greet(event: str): """Greets appropriately (from http://blog.ketchum.com/how-to-write-10-common-holiday-greetings/) """ greetings = "Happy" if event == "Christmas": greetings = "Merry" if event == "Kwanzaa": greetings = "Joyous" if event == "wishes": greetings = "Warm" ...
def greet(event: str): """Greets appropriately (from http://blog.ketchum.com/how-to-write-10-common-holiday-greetings/) """ greetings = "Happy" if event == "Christmas": greetings = "Merry" if event == "Kwanzaa": greetings = "Joyous" if event == "wishes": greetings = "Warm" ...
[ "Greets", "appropriately", "(", "from", "http", ":", "//", "blog", ".", "ketchum", ".", "com", "/", "how", "-", "to", "-", "write", "-", "10", "-", "common", "-", "holiday", "-", "greetings", "/", ")" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/happy_birthday.py#L11-L21
[ "def", "greet", "(", "event", ":", "str", ")", ":", "greetings", "=", "\"Happy\"", "if", "event", "==", "\"Christmas\"", ":", "greetings", "=", "\"Merry\"", "if", "event", "==", "\"Kwanzaa\"", ":", "greetings", "=", "\"Joyous\"", "if", "event", "==", "\"wi...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
nagiosCommandHelp
Returns command help document when no command is specified
examples/html_serve.py
def nagiosCommandHelp(**kwargs): """ Returns command help document when no command is specified """ with open(os.path.join(DIRECTORY, 'document.html')) as document: return document.read()
def nagiosCommandHelp(**kwargs): """ Returns command help document when no command is specified """ with open(os.path.join(DIRECTORY, 'document.html')) as document: return document.read()
[ "Returns", "command", "help", "document", "when", "no", "command", "is", "specified" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/html_serve.py#L10-L15
[ "def", "nagiosCommandHelp", "(", "*", "*", "kwargs", ")", ":", "with", "open", "(", "os", ".", "path", ".", "join", "(", "DIRECTORY", ",", "'document.html'", ")", ")", "as", "document", ":", "return", "document", ".", "read", "(", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
hash_password
Securely hash a password using a provided salt :param password: :param salt: :return: Hex encoded SHA512 hash of provided password
examples/secure_auth_with_db_example.py
def hash_password(password, salt): """ Securely hash a password using a provided salt :param password: :param salt: :return: Hex encoded SHA512 hash of provided password """ password = str(password).encode('utf-8') salt = str(salt).encode('utf-8') return hashlib.sha512(password + sal...
def hash_password(password, salt): """ Securely hash a password using a provided salt :param password: :param salt: :return: Hex encoded SHA512 hash of provided password """ password = str(password).encode('utf-8') salt = str(salt).encode('utf-8') return hashlib.sha512(password + sal...
[ "Securely", "hash", "a", "password", "using", "a", "provided", "salt", ":", "param", "password", ":", ":", "param", "salt", ":", ":", "return", ":", "Hex", "encoded", "SHA512", "hash", "of", "provided", "password" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/secure_auth_with_db_example.py#L17-L26
[ "def", "hash_password", "(", "password", ",", "salt", ")", ":", "password", "=", "str", "(", "password", ")", ".", "encode", "(", "'utf-8'", ")", "salt", "=", "str", "(", "salt", ")", ".", "encode", "(", "'utf-8'", ")", "return", "hashlib", ".", "sha...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
gen_api_key
Create a random API key for a user :param username: :return: Hex encoded SHA512 random string
examples/secure_auth_with_db_example.py
def gen_api_key(username): """ Create a random API key for a user :param username: :return: Hex encoded SHA512 random string """ salt = str(os.urandom(64)).encode('utf-8') return hash_password(username, salt)
def gen_api_key(username): """ Create a random API key for a user :param username: :return: Hex encoded SHA512 random string """ salt = str(os.urandom(64)).encode('utf-8') return hash_password(username, salt)
[ "Create", "a", "random", "API", "key", "for", "a", "user", ":", "param", "username", ":", ":", "return", ":", "Hex", "encoded", "SHA512", "random", "string" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/secure_auth_with_db_example.py#L29-L36
[ "def", "gen_api_key", "(", "username", ")", ":", "salt", "=", "str", "(", "os", ".", "urandom", "(", "64", ")", ")", ".", "encode", "(", "'utf-8'", ")", "return", "hash_password", "(", "username", ",", "salt", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
authenticate_user
Authenticate a username and password against our database :param username: :param password: :return: authenticated username
examples/secure_auth_with_db_example.py
def authenticate_user(username, password): """ Authenticate a username and password against our database :param username: :param password: :return: authenticated username """ user_model = Query() user = db.get(user_model.username == username) if not user: logger.warning("Use...
def authenticate_user(username, password): """ Authenticate a username and password against our database :param username: :param password: :return: authenticated username """ user_model = Query() user = db.get(user_model.username == username) if not user: logger.warning("Use...
[ "Authenticate", "a", "username", "and", "password", "against", "our", "database", ":", "param", "username", ":", ":", "param", "password", ":", ":", "return", ":", "authenticated", "username" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/secure_auth_with_db_example.py#L40-L57
[ "def", "authenticate_user", "(", "username", ",", "password", ")", ":", "user_model", "=", "Query", "(", ")", "user", "=", "db", ".", "get", "(", "user_model", ".", "username", "==", "username", ")", "if", "not", "user", ":", "logger", ".", "warning", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
authenticate_key
Authenticate an API key against our database :param api_key: :return: authenticated username
examples/secure_auth_with_db_example.py
def authenticate_key(api_key): """ Authenticate an API key against our database :param api_key: :return: authenticated username """ user_model = Query() user = db.search(user_model.api_key == api_key)[0] if user: return user['username'] return False
def authenticate_key(api_key): """ Authenticate an API key against our database :param api_key: :return: authenticated username """ user_model = Query() user = db.search(user_model.api_key == api_key)[0] if user: return user['username'] return False
[ "Authenticate", "an", "API", "key", "against", "our", "database", ":", "param", "api_key", ":", ":", "return", ":", "authenticated", "username" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/secure_auth_with_db_example.py#L61-L71
[ "def", "authenticate_key", "(", "api_key", ")", ":", "user_model", "=", "Query", "(", ")", "user", "=", "db", ".", "search", "(", "user_model", ".", "api_key", "==", "api_key", ")", "[", "0", "]", "if", "user", ":", "return", "user", "[", "'username'",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
add_user
CLI Parameter to add a user to the database :param username: :param password: :return: JSON status output
examples/secure_auth_with_db_example.py
def add_user(username, password): """ CLI Parameter to add a user to the database :param username: :param password: :return: JSON status output """ user_model = Query() if db.search(user_model.username == username): return { 'error': 'User {0} already exists'.format(...
def add_user(username, password): """ CLI Parameter to add a user to the database :param username: :param password: :return: JSON status output """ user_model = Query() if db.search(user_model.username == username): return { 'error': 'User {0} already exists'.format(...
[ "CLI", "Parameter", "to", "add", "a", "user", "to", "the", "database", ":", "param", "username", ":", ":", "param", "password", ":", ":", "return", ":", "JSON", "status", "output" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/secure_auth_with_db_example.py#L82-L112
[ "def", "add_user", "(", "username", ",", "password", ")", ":", "user_model", "=", "Query", "(", ")", "if", "db", ".", "search", "(", "user_model", ".", "username", "==", "username", ")", ":", "return", "{", "'error'", ":", "'User {0} already exists'", ".",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
get_token
Get Job details :param authed_user: :return:
examples/secure_auth_with_db_example.py
def get_token(authed_user: hug.directives.user): """ Get Job details :param authed_user: :return: """ user_model = Query() user = db.search(user_model.username == authed_user)[0] if user: out = { 'user': user['username'], 'api_key': user['api_key'] ...
def get_token(authed_user: hug.directives.user): """ Get Job details :param authed_user: :return: """ user_model = Query() user = db.search(user_model.username == authed_user)[0] if user: out = { 'user': user['username'], 'api_key': user['api_key'] ...
[ "Get", "Job", "details", ":", "param", "authed_user", ":", ":", "return", ":" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/secure_auth_with_db_example.py#L116-L136
[ "def", "get_token", "(", "authed_user", ":", "hug", ".", "directives", ".", "user", ")", ":", "user_model", "=", "Query", "(", ")", "user", "=", "db", ".", "search", "(", "user_model", ".", "username", "==", "authed_user", ")", "[", "0", "]", "if", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
upload_file
accepts file uploads
examples/file_upload_example.py
def upload_file(body): """accepts file uploads""" # <body> is a simple dictionary of {filename: b'content'} print('body: ', body) return {'filename': list(body.keys()).pop(), 'filesize': len(list(body.values()).pop())}
def upload_file(body): """accepts file uploads""" # <body> is a simple dictionary of {filename: b'content'} print('body: ', body) return {'filename': list(body.keys()).pop(), 'filesize': len(list(body.values()).pop())}
[ "accepts", "file", "uploads" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/file_upload_example.py#L21-L25
[ "def", "upload_file", "(", "body", ")", ":", "# <body> is a simple dictionary of {filename: b'content'}", "print", "(", "'body: '", ",", "body", ")", "return", "{", "'filename'", ":", "list", "(", "body", ".", "keys", "(", ")", ")", ".", "pop", "(", ")", ","...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
happy_birthday
Says happy birthday to a user
examples/quick_start/first_step_2.py
def happy_birthday(name: hug.types.text, age: hug.types.number, hug_timer=3): """Says happy birthday to a user""" return {'message': 'Happy {0} Birthday {1}!'.format(age, name), 'took': float(hug_timer)}
def happy_birthday(name: hug.types.text, age: hug.types.number, hug_timer=3): """Says happy birthday to a user""" return {'message': 'Happy {0} Birthday {1}!'.format(age, name), 'took': float(hug_timer)}
[ "Says", "happy", "birthday", "to", "a", "user" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/quick_start/first_step_2.py#L7-L10
[ "def", "happy_birthday", "(", "name", ":", "hug", ".", "types", ".", "text", ",", "age", ":", "hug", ".", "types", ".", "number", ",", "hug_timer", "=", "3", ")", ":", "return", "{", "'message'", ":", "'Happy {0} Birthday {1}!'", ".", "format", "(", "a...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
json_convert
Registers the wrapped method as a JSON converter for the provided types. NOTE: custom converters are always globally applied
hug/output_format.py
def json_convert(*kinds): """Registers the wrapped method as a JSON converter for the provided types. NOTE: custom converters are always globally applied """ def register_json_converter(function): for kind in kinds: json_converters[kind] = function return function return...
def json_convert(*kinds): """Registers the wrapped method as a JSON converter for the provided types. NOTE: custom converters are always globally applied """ def register_json_converter(function): for kind in kinds: json_converters[kind] = function return function return...
[ "Registers", "the", "wrapped", "method", "as", "a", "JSON", "converter", "for", "the", "provided", "types", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L83-L92
[ "def", "json_convert", "(", "*", "kinds", ")", ":", "def", "register_json_converter", "(", "function", ")", ":", "for", "kind", "in", "kinds", ":", "json_converters", "[", "kind", "]", "=", "function", "return", "function", "return", "register_json_converter" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
json
JSON (Javascript Serialized Object Notation)
hug/output_format.py
def json(content, request=None, response=None, ensure_ascii=False, **kwargs): """JSON (Javascript Serialized Object Notation)""" if hasattr(content, 'read'): return content if isinstance(content, tuple) and getattr(content, '_fields', None): content = {field: getattr(content, field) for fie...
def json(content, request=None, response=None, ensure_ascii=False, **kwargs): """JSON (Javascript Serialized Object Notation)""" if hasattr(content, 'read'): return content if isinstance(content, tuple) and getattr(content, '_fields', None): content = {field: getattr(content, field) for fie...
[ "JSON", "(", "Javascript", "Serialized", "Object", "Notation", ")" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L122-L129
[ "def", "json", "(", "content", ",", "request", "=", "None", ",", "response", "=", "None", ",", "ensure_ascii", "=", "False", ",", "*", "*", "kwargs", ")", ":", "if", "hasattr", "(", "content", ",", "'read'", ")", ":", "return", "content", "if", "isin...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
on_valid
Renders as the specified content type only if no errors are found in the provided data object
hug/output_format.py
def on_valid(valid_content_type, on_invalid=json): """Renders as the specified content type only if no errors are found in the provided data object""" invalid_kwargs = introspect.generate_accepted_kwargs(on_invalid, 'request', 'response') invalid_takes_response = introspect.takes_all_arguments(on_invalid, '...
def on_valid(valid_content_type, on_invalid=json): """Renders as the specified content type only if no errors are found in the provided data object""" invalid_kwargs = introspect.generate_accepted_kwargs(on_invalid, 'request', 'response') invalid_takes_response = introspect.takes_all_arguments(on_invalid, '...
[ "Renders", "as", "the", "specified", "content", "type", "only", "if", "no", "errors", "are", "found", "in", "the", "provided", "data", "object" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L132-L154
[ "def", "on_valid", "(", "valid_content_type", ",", "on_invalid", "=", "json", ")", ":", "invalid_kwargs", "=", "introspect", ".", "generate_accepted_kwargs", "(", "on_invalid", ",", "'request'", ",", "'response'", ")", "invalid_takes_response", "=", "introspect", "....
080901c81576657f82e2432fd4a82f1d0d2f370c
train
html
HTML (Hypertext Markup Language)
hug/output_format.py
def html(content, **kwargs): """HTML (Hypertext Markup Language)""" if hasattr(content, 'read'): return content elif hasattr(content, 'render'): return content.render().encode('utf8') return str(content).encode('utf8')
def html(content, **kwargs): """HTML (Hypertext Markup Language)""" if hasattr(content, 'read'): return content elif hasattr(content, 'render'): return content.render().encode('utf8') return str(content).encode('utf8')
[ "HTML", "(", "Hypertext", "Markup", "Language", ")" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L167-L174
[ "def", "html", "(", "content", ",", "*", "*", "kwargs", ")", ":", "if", "hasattr", "(", "content", ",", "'read'", ")", ":", "return", "content", "elif", "hasattr", "(", "content", ",", "'render'", ")", ":", "return", "content", ".", "render", "(", ")...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
image
Dynamically creates an image type handler for the specified image type
hug/output_format.py
def image(image_format, doc=None): """Dynamically creates an image type handler for the specified image type""" @on_valid('image/{0}'.format(image_format)) def image_handler(data, **kwargs): if hasattr(data, 'read'): return data elif hasattr(data, 'save'): output = st...
def image(image_format, doc=None): """Dynamically creates an image type handler for the specified image type""" @on_valid('image/{0}'.format(image_format)) def image_handler(data, **kwargs): if hasattr(data, 'read'): return data elif hasattr(data, 'save'): output = st...
[ "Dynamically", "creates", "an", "image", "type", "handler", "for", "the", "specified", "image", "type" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L206-L226
[ "def", "image", "(", "image_format", ",", "doc", "=", "None", ")", ":", "@", "on_valid", "(", "'image/{0}'", ".", "format", "(", "image_format", ")", ")", "def", "image_handler", "(", "data", ",", "*", "*", "kwargs", ")", ":", "if", "hasattr", "(", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
video
Dynamically creates a video type handler for the specified video type
hug/output_format.py
def video(video_type, video_mime, doc=None): """Dynamically creates a video type handler for the specified video type""" @on_valid(video_mime) def video_handler(data, **kwargs): if hasattr(data, 'read'): return data elif hasattr(data, 'save'): output = stream() ...
def video(video_type, video_mime, doc=None): """Dynamically creates a video type handler for the specified video type""" @on_valid(video_mime) def video_handler(data, **kwargs): if hasattr(data, 'read'): return data elif hasattr(data, 'save'): output = stream() ...
[ "Dynamically", "creates", "a", "video", "type", "handler", "for", "the", "specified", "video", "type" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L233-L250
[ "def", "video", "(", "video_type", ",", "video_mime", ",", "doc", "=", "None", ")", ":", "@", "on_valid", "(", "video_mime", ")", "def", "video_handler", "(", "data", ",", "*", "*", "kwargs", ")", ":", "if", "hasattr", "(", "data", ",", "'read'", ")"...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
file
A dynamically retrieved file
hug/output_format.py
def file(data, response, **kwargs): """A dynamically retrieved file""" if not data: response.content_type = 'text/plain' return '' if hasattr(data, 'read'): name, data = getattr(data, 'name', ''), data elif os.path.isfile(data): name, data = data, open(data, 'rb') el...
def file(data, response, **kwargs): """A dynamically retrieved file""" if not data: response.content_type = 'text/plain' return '' if hasattr(data, 'read'): name, data = getattr(data, 'name', ''), data elif os.path.isfile(data): name, data = data, open(data, 'rb') el...
[ "A", "dynamically", "retrieved", "file" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L258-L274
[ "def", "file", "(", "data", ",", "response", ",", "*", "*", "kwargs", ")", ":", "if", "not", "data", ":", "response", ".", "content_type", "=", "'text/plain'", "return", "''", "if", "hasattr", "(", "data", ",", "'read'", ")", ":", "name", ",", "data"...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
on_content_type
Returns a content in a different format based on the clients provided content type, should pass in a dict with the following format: {'[content-type]': action, ... }
hug/output_format.py
def on_content_type(handlers, default=None, error='The requested content type does not match any of those allowed'): """Returns a content in a different format based on the clients provided content type, should pass in a dict with the following format: {'[content-type]': action, ......
def on_content_type(handlers, default=None, error='The requested content type does not match any of those allowed'): """Returns a content in a different format based on the clients provided content type, should pass in a dict with the following format: {'[content-type]': action, ......
[ "Returns", "a", "content", "in", "a", "different", "format", "based", "on", "the", "clients", "provided", "content", "type", "should", "pass", "in", "a", "dict", "with", "the", "following", "format", ":" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L277-L295
[ "def", "on_content_type", "(", "handlers", ",", "default", "=", "None", ",", "error", "=", "'The requested content type does not match any of those allowed'", ")", ":", "def", "output_type", "(", "data", ",", "request", ",", "response", ")", ":", "handler", "=", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
accept_quality
Separates out the quality score from the accepted content_type
hug/output_format.py
def accept_quality(accept, default=1): """Separates out the quality score from the accepted content_type""" quality = default if accept and ";" in accept: accept, rest = accept.split(";", 1) accept_quality = RE_ACCEPT_QUALITY.search(rest) if accept_quality: quality = floa...
def accept_quality(accept, default=1): """Separates out the quality score from the accepted content_type""" quality = default if accept and ";" in accept: accept, rest = accept.split(";", 1) accept_quality = RE_ACCEPT_QUALITY.search(rest) if accept_quality: quality = floa...
[ "Separates", "out", "the", "quality", "score", "from", "the", "accepted", "content_type" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L298-L307
[ "def", "accept_quality", "(", "accept", ",", "default", "=", "1", ")", ":", "quality", "=", "default", "if", "accept", "and", "\";\"", "in", "accept", ":", "accept", ",", "rest", "=", "accept", ".", "split", "(", "\";\"", ",", "1", ")", "accept_quality...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
accept
Returns a content in a different format based on the clients defined accepted content type, should pass in a dict with the following format: {'[content-type]': action, ... }
hug/output_format.py
def accept(handlers, default=None, error='The requested content type does not match any of those allowed'): """Returns a content in a different format based on the clients defined accepted content type, should pass in a dict with the following format: {'[content-type]': action, ... ...
def accept(handlers, default=None, error='The requested content type does not match any of those allowed'): """Returns a content in a different format based on the clients defined accepted content type, should pass in a dict with the following format: {'[content-type]': action, ... ...
[ "Returns", "a", "content", "in", "a", "different", "format", "based", "on", "the", "clients", "defined", "accepted", "content", "type", "should", "pass", "in", "a", "dict", "with", "the", "following", "format", ":" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L310-L339
[ "def", "accept", "(", "handlers", ",", "default", "=", "None", ",", "error", "=", "'The requested content type does not match any of those allowed'", ")", ":", "def", "output_type", "(", "data", ",", "request", ",", "response", ")", ":", "accept", "=", "request", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
suffix
Returns a content in a different format based on the suffix placed at the end of the URL route should pass in a dict with the following format: {'[suffix]': action, ... }
hug/output_format.py
def suffix(handlers, default=None, error='The requested suffix does not match any of those allowed'): """Returns a content in a different format based on the suffix placed at the end of the URL route should pass in a dict with the following format: {'[suffix]': action, ... ...
def suffix(handlers, default=None, error='The requested suffix does not match any of those allowed'): """Returns a content in a different format based on the suffix placed at the end of the URL route should pass in a dict with the following format: {'[suffix]': action, ... ...
[ "Returns", "a", "content", "in", "a", "different", "format", "based", "on", "the", "suffix", "placed", "at", "the", "end", "of", "the", "URL", "route", "should", "pass", "in", "a", "dict", "with", "the", "following", "format", ":" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L342-L366
[ "def", "suffix", "(", "handlers", ",", "default", "=", "None", ",", "error", "=", "'The requested suffix does not match any of those allowed'", ")", ":", "def", "output_type", "(", "data", ",", "request", ",", "response", ")", ":", "path", "=", "request", ".", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
prefix
Returns a content in a different format based on the prefix placed at the end of the URL route should pass in a dict with the following format: {'[prefix]': action, ... }
hug/output_format.py
def prefix(handlers, default=None, error='The requested prefix does not match any of those allowed'): """Returns a content in a different format based on the prefix placed at the end of the URL route should pass in a dict with the following format: {'[prefix]': action, ... ...
def prefix(handlers, default=None, error='The requested prefix does not match any of those allowed'): """Returns a content in a different format based on the prefix placed at the end of the URL route should pass in a dict with the following format: {'[prefix]': action, ... ...
[ "Returns", "a", "content", "in", "a", "different", "format", "based", "on", "the", "prefix", "placed", "at", "the", "end", "of", "the", "URL", "route", "should", "pass", "in", "a", "dict", "with", "the", "following", "format", ":" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/output_format.py#L369-L393
[ "def", "prefix", "(", "handlers", ",", "default", "=", "None", ",", "error", "=", "'The requested prefix does not match any of those allowed'", ")", ":", "def", "output_type", "(", "data", ",", "request", ",", "response", ")", ":", "path", "=", "request", ".", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
show
Returns a list of items currently in the database
examples/docker_compose_with_mongodb/app.py
def show(): """Returns a list of items currently in the database""" items = list(collection.find()) # JSON conversion chokes on the _id objects, so we convert # them to strings here for i in items: i['_id'] = str(i['_id']) return items
def show(): """Returns a list of items currently in the database""" items = list(collection.find()) # JSON conversion chokes on the _id objects, so we convert # them to strings here for i in items: i['_id'] = str(i['_id']) return items
[ "Returns", "a", "list", "of", "items", "currently", "in", "the", "database" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/docker_compose_with_mongodb/app.py#L11-L18
[ "def", "show", "(", ")", ":", "items", "=", "list", "(", "collection", ".", "find", "(", ")", ")", "# JSON conversion chokes on the _id objects, so we convert", "# them to strings here", "for", "i", "in", "items", ":", "i", "[", "'_id'", "]", "=", "str", "(", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
new
Inserts the given object as a new item in the database. Returns the ID of the newly created item.
examples/docker_compose_with_mongodb/app.py
def new(name: hug.types.text, description: hug.types.text): """Inserts the given object as a new item in the database. Returns the ID of the newly created item. """ item_doc = {'name': name, 'description': description} collection.insert_one(item_doc) return str(item_doc['_id'])
def new(name: hug.types.text, description: hug.types.text): """Inserts the given object as a new item in the database. Returns the ID of the newly created item. """ item_doc = {'name': name, 'description': description} collection.insert_one(item_doc) return str(item_doc['_id'])
[ "Inserts", "the", "given", "object", "as", "a", "new", "item", "in", "the", "database", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/docker_compose_with_mongodb/app.py#L22-L29
[ "def", "new", "(", "name", ":", "hug", ".", "types", ".", "text", ",", "description", ":", "hug", ".", "types", ".", "text", ")", ":", "item_doc", "=", "{", "'name'", ":", "name", ",", "'description'", ":", "description", "}", "collection", ".", "ins...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Service.request
Calls the service at the specified URL using the "CALL" method
hug/use.py
def request(self, method, url, url_params=empty.dict, headers=empty.dict, timeout=None, **params): """Calls the service at the specified URL using the "CALL" method""" raise NotImplementedError("Concrete services must define the request method")
def request(self, method, url, url_params=empty.dict, headers=empty.dict, timeout=None, **params): """Calls the service at the specified URL using the "CALL" method""" raise NotImplementedError("Concrete services must define the request method")
[ "Calls", "the", "service", "at", "the", "specified", "URL", "using", "the", "CALL", "method" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/use.py#L53-L55
[ "def", "request", "(", "self", ",", "method", ",", "url", ",", "url_params", "=", "empty", ".", "dict", ",", "headers", "=", "empty", ".", "dict", ",", "timeout", "=", "None", ",", "*", "*", "params", ")", ":", "raise", "NotImplementedError", "(", "\...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Service.options
Calls the service at the specified URL using the "OPTIONS" method
hug/use.py
def options(self, url, url_params=empty.dict, headers=empty.dict, timeout=None, **params): """Calls the service at the specified URL using the "OPTIONS" method""" return self.request('OPTIONS', url=url, headers=headers, timeout=timeout, **params)
def options(self, url, url_params=empty.dict, headers=empty.dict, timeout=None, **params): """Calls the service at the specified URL using the "OPTIONS" method""" return self.request('OPTIONS', url=url, headers=headers, timeout=timeout, **params)
[ "Calls", "the", "service", "at", "the", "specified", "URL", "using", "the", "OPTIONS", "method" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/use.py#L81-L83
[ "def", "options", "(", "self", ",", "url", ",", "url_params", "=", "empty", ".", "dict", ",", "headers", "=", "empty", ".", "dict", ",", "timeout", "=", "None", ",", "*", "*", "params", ")", ":", "return", "self", ".", "request", "(", "'OPTIONS'", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Socket.setsockopt
Add socket options to set
hug/use.py
def setsockopt(self, *sockopts): """Add socket options to set""" if type(sockopts[0]) in (list, tuple): for sock_opt in sockopts[0]: level, option, value = sock_opt self.connection.sockopts.add((level, option, value)) else: level, option, v...
def setsockopt(self, *sockopts): """Add socket options to set""" if type(sockopts[0]) in (list, tuple): for sock_opt in sockopts[0]: level, option, value = sock_opt self.connection.sockopts.add((level, option, value)) else: level, option, v...
[ "Add", "socket", "options", "to", "set" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/use.py#L206-L214
[ "def", "setsockopt", "(", "self", ",", "*", "sockopts", ")", ":", "if", "type", "(", "sockopts", "[", "0", "]", ")", "in", "(", "list", ",", "tuple", ")", ":", "for", "sock_opt", "in", "sockopts", "[", "0", "]", ":", "level", ",", "option", ",", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Socket._register_socket
Create/Connect socket, apply options
hug/use.py
def _register_socket(self): """Create/Connect socket, apply options""" _socket = socket.socket(*Socket.protocols[self.connection.proto]) _socket.settimeout(self.timeout) # Reconfigure original socket options. if self.connection.sockopts: for sock_opt in self.connecti...
def _register_socket(self): """Create/Connect socket, apply options""" _socket = socket.socket(*Socket.protocols[self.connection.proto]) _socket.settimeout(self.timeout) # Reconfigure original socket options. if self.connection.sockopts: for sock_opt in self.connecti...
[ "Create", "/", "Connect", "socket", "apply", "options" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/use.py#L216-L228
[ "def", "_register_socket", "(", "self", ")", ":", "_socket", "=", "socket", ".", "socket", "(", "*", "Socket", ".", "protocols", "[", "self", ".", "connection", ".", "proto", "]", ")", "_socket", ".", "settimeout", "(", "self", ".", "timeout", ")", "# ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Socket._stream_send_and_receive
TCP/Stream sender and receiver
hug/use.py
def _stream_send_and_receive(self, _socket, message, *args, **kwargs): """TCP/Stream sender and receiver""" data = BytesIO() _socket_fd = _socket.makefile(mode='rwb', encoding='utf-8') _socket_fd.write(message.encode('utf-8')) _socket_fd.flush() for received in _socket_...
def _stream_send_and_receive(self, _socket, message, *args, **kwargs): """TCP/Stream sender and receiver""" data = BytesIO() _socket_fd = _socket.makefile(mode='rwb', encoding='utf-8') _socket_fd.write(message.encode('utf-8')) _socket_fd.flush() for received in _socket_...
[ "TCP", "/", "Stream", "sender", "and", "receiver" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/use.py#L230-L243
[ "def", "_stream_send_and_receive", "(", "self", ",", "_socket", ",", "message", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "data", "=", "BytesIO", "(", ")", "_socket_fd", "=", "_socket", ".", "makefile", "(", "mode", "=", "'rwb'", ",", "encod...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Socket._dgram_send_and_receive
User Datagram Protocol sender and receiver
hug/use.py
def _dgram_send_and_receive(self, _socket, message, buffer_size=4096, *args): """User Datagram Protocol sender and receiver""" _socket.send(message.encode('utf-8')) data, address = _socket.recvfrom(buffer_size) return BytesIO(data)
def _dgram_send_and_receive(self, _socket, message, buffer_size=4096, *args): """User Datagram Protocol sender and receiver""" _socket.send(message.encode('utf-8')) data, address = _socket.recvfrom(buffer_size) return BytesIO(data)
[ "User", "Datagram", "Protocol", "sender", "and", "receiver" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/use.py#L245-L249
[ "def", "_dgram_send_and_receive", "(", "self", ",", "_socket", ",", "message", ",", "buffer_size", "=", "4096", ",", "*", "args", ")", ":", "_socket", ".", "send", "(", "message", ".", "encode", "(", "'utf-8'", ")", ")", "data", ",", "address", "=", "_...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Socket.request
Populate connection pool, send message, return BytesIO, and cleanup
hug/use.py
def request(self, message, timeout=False, *args, **kwargs): """Populate connection pool, send message, return BytesIO, and cleanup""" if not self.connection_pool.full(): self.connection_pool.put(self._register_socket()) _socket = self.connection_pool.get() # setting timeout...
def request(self, message, timeout=False, *args, **kwargs): """Populate connection pool, send message, return BytesIO, and cleanup""" if not self.connection_pool.full(): self.connection_pool.put(self._register_socket()) _socket = self.connection_pool.get() # setting timeout...
[ "Populate", "connection", "pool", "send", "message", "return", "BytesIO", "and", "cleanup" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/use.py#L251-L267
[ "def", "request", "(", "self", ",", "message", ",", "timeout", "=", "False", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "not", "self", ".", "connection_pool", ".", "full", "(", ")", ":", "self", ".", "connection_pool", ".", "put", "...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
InMemoryStore.get
Get data for given store key. Raise hug.exceptions.StoreKeyNotFound if key does not exist.
hug/store.py
def get(self, key): """Get data for given store key. Raise hug.exceptions.StoreKeyNotFound if key does not exist.""" try: data = self._data[key] except KeyError: raise StoreKeyNotFound(key) return data
def get(self, key): """Get data for given store key. Raise hug.exceptions.StoreKeyNotFound if key does not exist.""" try: data = self._data[key] except KeyError: raise StoreKeyNotFound(key) return data
[ "Get", "data", "for", "given", "store", "key", ".", "Raise", "hug", ".", "exceptions", ".", "StoreKeyNotFound", "if", "key", "does", "not", "exist", "." ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/store.py#L35-L41
[ "def", "get", "(", "self", ",", "key", ")", ":", "try", ":", "data", "=", "self", ".", "_data", "[", "key", "]", "except", "KeyError", ":", "raise", "StoreKeyNotFound", "(", "key", ")", "return", "data" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
top_post
Returns the top post from the provided section
examples/write_once.py
def top_post(section: hug.types.one_of(('news', 'newest', 'show'))='news'): """Returns the top post from the provided section""" content = requests.get('https://news.ycombinator.com/{0}'.format(section)).content text = content.decode('utf-8') return text.split('<tr class=\'athing\'>')[1].split("<a href"...
def top_post(section: hug.types.one_of(('news', 'newest', 'show'))='news'): """Returns the top post from the provided section""" content = requests.get('https://news.ycombinator.com/{0}'.format(section)).content text = content.decode('utf-8') return text.split('<tr class=\'athing\'>')[1].split("<a href"...
[ "Returns", "the", "top", "post", "from", "the", "provided", "section" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/write_once.py#L9-L13
[ "def", "top_post", "(", "section", ":", "hug", ".", "types", ".", "one_of", "(", "(", "'news'", ",", "'newest'", ",", "'show'", ")", ")", "=", "'news'", ")", ":", "content", "=", "requests", ".", "get", "(", "'https://news.ycombinator.com/{0}'", ".", "fo...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
default_output_format
A decorator that allows you to override the default output format for an API
hug/decorators.py
def default_output_format(content_type='application/json', apply_globally=False, api=None, cli=False, http=True): """A decorator that allows you to override the default output format for an API""" def decorator(formatter): formatter = hug.output_format.content_type(content_type)(formatter) if ap...
def default_output_format(content_type='application/json', apply_globally=False, api=None, cli=False, http=True): """A decorator that allows you to override the default output format for an API""" def decorator(formatter): formatter = hug.output_format.content_type(content_type)(formatter) if ap...
[ "A", "decorator", "that", "allows", "you", "to", "override", "the", "default", "output", "format", "for", "an", "API" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L41-L57
[ "def", "default_output_format", "(", "content_type", "=", "'application/json'", ",", "apply_globally", "=", "False", ",", "api", "=", "None", ",", "cli", "=", "False", ",", "http", "=", "True", ")", ":", "def", "decorator", "(", "formatter", ")", ":", "for...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
default_input_format
A decorator that allows you to override the default output format for an API
hug/decorators.py
def default_input_format(content_type='application/json', apply_globally=False, api=None): """A decorator that allows you to override the default output format for an API""" def decorator(formatter): formatter = hug.output_format.content_type(content_type)(formatter) if apply_globally: ...
def default_input_format(content_type='application/json', apply_globally=False, api=None): """A decorator that allows you to override the default output format for an API""" def decorator(formatter): formatter = hug.output_format.content_type(content_type)(formatter) if apply_globally: ...
[ "A", "decorator", "that", "allows", "you", "to", "override", "the", "default", "output", "format", "for", "an", "API" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L60-L70
[ "def", "default_input_format", "(", "content_type", "=", "'application/json'", ",", "apply_globally", "=", "False", ",", "api", "=", "None", ")", ":", "def", "decorator", "(", "formatter", ")", ":", "formatter", "=", "hug", ".", "output_format", ".", "content_...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
directive
A decorator that registers a single hug directive
hug/decorators.py
def directive(apply_globally=False, api=None): """A decorator that registers a single hug directive""" def decorator(directive_method): if apply_globally: hug.defaults.directives[underscore(directive_method.__name__)] = directive_method else: apply_to_api = hug.API(api) i...
def directive(apply_globally=False, api=None): """A decorator that registers a single hug directive""" def decorator(directive_method): if apply_globally: hug.defaults.directives[underscore(directive_method.__name__)] = directive_method else: apply_to_api = hug.API(api) i...
[ "A", "decorator", "that", "registers", "a", "single", "hug", "directive" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L73-L83
[ "def", "directive", "(", "apply_globally", "=", "False", ",", "api", "=", "None", ")", ":", "def", "decorator", "(", "directive_method", ")", ":", "if", "apply_globally", ":", "hug", ".", "defaults", ".", "directives", "[", "underscore", "(", "directive_meth...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
context_factory
A decorator that registers a single hug context factory
hug/decorators.py
def context_factory(apply_globally=False, api=None): """A decorator that registers a single hug context factory""" def decorator(context_factory_): if apply_globally: hug.defaults.context_factory = context_factory_ else: apply_to_api = hug.API(api) if api else hug.api.fro...
def context_factory(apply_globally=False, api=None): """A decorator that registers a single hug context factory""" def decorator(context_factory_): if apply_globally: hug.defaults.context_factory = context_factory_ else: apply_to_api = hug.API(api) if api else hug.api.fro...
[ "A", "decorator", "that", "registers", "a", "single", "hug", "context", "factory" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L86-L95
[ "def", "context_factory", "(", "apply_globally", "=", "False", ",", "api", "=", "None", ")", ":", "def", "decorator", "(", "context_factory_", ")", ":", "if", "apply_globally", ":", "hug", ".", "defaults", ".", "context_factory", "=", "context_factory_", "else...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
delete_context
A decorator that registers a single hug delete context function
hug/decorators.py
def delete_context(apply_globally=False, api=None): """A decorator that registers a single hug delete context function""" def decorator(delete_context_): if apply_globally: hug.defaults.delete_context = delete_context_ else: apply_to_api = hug.API(api) if api else hug.api...
def delete_context(apply_globally=False, api=None): """A decorator that registers a single hug delete context function""" def decorator(delete_context_): if apply_globally: hug.defaults.delete_context = delete_context_ else: apply_to_api = hug.API(api) if api else hug.api...
[ "A", "decorator", "that", "registers", "a", "single", "hug", "delete", "context", "function" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L98-L107
[ "def", "delete_context", "(", "apply_globally", "=", "False", ",", "api", "=", "None", ")", ":", "def", "decorator", "(", "delete_context_", ")", ":", "if", "apply_globally", ":", "hug", ".", "defaults", ".", "delete_context", "=", "delete_context_", "else", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
startup
Runs the provided function on startup, passing in an instance of the api
hug/decorators.py
def startup(api=None): """Runs the provided function on startup, passing in an instance of the api""" def startup_wrapper(startup_function): apply_to_api = hug.API(api) if api else hug.api.from_object(startup_function) apply_to_api.add_startup_handler(startup_function) return startup_fun...
def startup(api=None): """Runs the provided function on startup, passing in an instance of the api""" def startup_wrapper(startup_function): apply_to_api = hug.API(api) if api else hug.api.from_object(startup_function) apply_to_api.add_startup_handler(startup_function) return startup_fun...
[ "Runs", "the", "provided", "function", "on", "startup", "passing", "in", "an", "instance", "of", "the", "api" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L110-L116
[ "def", "startup", "(", "api", "=", "None", ")", ":", "def", "startup_wrapper", "(", "startup_function", ")", ":", "apply_to_api", "=", "hug", ".", "API", "(", "api", ")", "if", "api", "else", "hug", ".", "api", ".", "from_object", "(", "startup_function"...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
request_middleware
Registers a middleware function that will be called on every request
hug/decorators.py
def request_middleware(api=None): """Registers a middleware function that will be called on every request""" def decorator(middleware_method): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_method) class MiddlewareRouter(object): __slots__ = () d...
def request_middleware(api=None): """Registers a middleware function that will be called on every request""" def decorator(middleware_method): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_method) class MiddlewareRouter(object): __slots__ = () d...
[ "Registers", "a", "middleware", "function", "that", "will", "be", "called", "on", "every", "request" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L119-L132
[ "def", "request_middleware", "(", "api", "=", "None", ")", ":", "def", "decorator", "(", "middleware_method", ")", ":", "apply_to_api", "=", "hug", ".", "API", "(", "api", ")", "if", "api", "else", "hug", ".", "api", ".", "from_object", "(", "middleware_...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
response_middleware
Registers a middleware function that will be called on every response
hug/decorators.py
def response_middleware(api=None): """Registers a middleware function that will be called on every response""" def decorator(middleware_method): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_method) class MiddlewareRouter(object): __slots__ = () ...
def response_middleware(api=None): """Registers a middleware function that will be called on every response""" def decorator(middleware_method): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_method) class MiddlewareRouter(object): __slots__ = () ...
[ "Registers", "a", "middleware", "function", "that", "will", "be", "called", "on", "every", "response" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L135-L148
[ "def", "response_middleware", "(", "api", "=", "None", ")", ":", "def", "decorator", "(", "middleware_method", ")", ":", "apply_to_api", "=", "hug", ".", "API", "(", "api", ")", "if", "api", "else", "hug", ".", "api", ".", "from_object", "(", "middleware...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
reqresp_middleware
Registers a middleware function that will be called on every request and response
hug/decorators.py
def reqresp_middleware(api=None): """Registers a middleware function that will be called on every request and response""" def decorator(middleware_generator): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_generator) class MiddlewareRouter(object): __slots__ ...
def reqresp_middleware(api=None): """Registers a middleware function that will be called on every request and response""" def decorator(middleware_generator): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_generator) class MiddlewareRouter(object): __slots__ ...
[ "Registers", "a", "middleware", "function", "that", "will", "be", "called", "on", "every", "request", "and", "response" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L150-L167
[ "def", "reqresp_middleware", "(", "api", "=", "None", ")", ":", "def", "decorator", "(", "middleware_generator", ")", ":", "apply_to_api", "=", "hug", ".", "API", "(", "api", ")", "if", "api", "else", "hug", ".", "api", ".", "from_object", "(", "middlewa...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
middleware_class
Registers a middleware class
hug/decorators.py
def middleware_class(api=None): """Registers a middleware class""" def decorator(middleware_class): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_class) apply_to_api.http.add_middleware(middleware_class()) return middleware_class return decorator
def middleware_class(api=None): """Registers a middleware class""" def decorator(middleware_class): apply_to_api = hug.API(api) if api else hug.api.from_object(middleware_class) apply_to_api.http.add_middleware(middleware_class()) return middleware_class return decorator
[ "Registers", "a", "middleware", "class" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L169-L175
[ "def", "middleware_class", "(", "api", "=", "None", ")", ":", "def", "decorator", "(", "middleware_class", ")", ":", "apply_to_api", "=", "hug", ".", "API", "(", "api", ")", "if", "api", "else", "hug", ".", "api", ".", "from_object", "(", "middleware_cla...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
extend_api
Extends the current api, with handlers from an imported api. Optionally provide a route that prefixes access
hug/decorators.py
def extend_api(route="", api=None, base_url="", **kwargs): """Extends the current api, with handlers from an imported api. Optionally provide a route that prefixes access""" def decorator(extend_with): apply_to_api = hug.API(api) if api else hug.api.from_object(extend_with) for extended_api in e...
def extend_api(route="", api=None, base_url="", **kwargs): """Extends the current api, with handlers from an imported api. Optionally provide a route that prefixes access""" def decorator(extend_with): apply_to_api = hug.API(api) if api else hug.api.from_object(extend_with) for extended_api in e...
[ "Extends", "the", "current", "api", "with", "handlers", "from", "an", "imported", "api", ".", "Optionally", "provide", "a", "route", "that", "prefixes", "access" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L178-L185
[ "def", "extend_api", "(", "route", "=", "\"\"", ",", "api", "=", "None", ",", "base_url", "=", "\"\"", ",", "*", "*", "kwargs", ")", ":", "def", "decorator", "(", "extend_with", ")", ":", "apply_to_api", "=", "hug", ".", "API", "(", "api", ")", "if...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
wraps
Enables building decorators around functions used for hug routes without changing their function signature
hug/decorators.py
def wraps(function): """Enables building decorators around functions used for hug routes without changing their function signature""" def wrap(decorator): decorator = functools.wraps(function)(decorator) if not hasattr(function, 'original'): decorator.original = function else...
def wraps(function): """Enables building decorators around functions used for hug routes without changing their function signature""" def wrap(decorator): decorator = functools.wraps(function)(decorator) if not hasattr(function, 'original'): decorator.original = function else...
[ "Enables", "building", "decorators", "around", "functions", "used", "for", "hug", "routes", "without", "changing", "their", "function", "signature" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L188-L198
[ "def", "wraps", "(", "function", ")", ":", "def", "wrap", "(", "decorator", ")", ":", "decorator", "=", "functools", ".", "wraps", "(", "function", ")", "(", "decorator", ")", "if", "not", "hasattr", "(", "function", ",", "'original'", ")", ":", "decor...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
auto_kwargs
Modifies the provided function to support kwargs by only passing along kwargs for parameters it accepts
hug/decorators.py
def auto_kwargs(function): """Modifies the provided function to support kwargs by only passing along kwargs for parameters it accepts""" supported = introspect.arguments(function) @wraps(function) def call_function(*args, **kwargs): return function(*args, **{key: value for key, value in kwargs....
def auto_kwargs(function): """Modifies the provided function to support kwargs by only passing along kwargs for parameters it accepts""" supported = introspect.arguments(function) @wraps(function) def call_function(*args, **kwargs): return function(*args, **{key: value for key, value in kwargs....
[ "Modifies", "the", "provided", "function", "to", "support", "kwargs", "by", "only", "passing", "along", "kwargs", "for", "parameters", "it", "accepts" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/decorators.py#L201-L208
[ "def", "auto_kwargs", "(", "function", ")", ":", "supported", "=", "introspect", ".", "arguments", "(", "function", ")", "@", "wraps", "(", "function", ")", "def", "call_function", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "function"...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
get_time
Get time from a locally running NTP server
examples/use_socket.py
def get_time(): """Get time from a locally running NTP server""" time_request = '\x1b' + 47 * '\0' now = struct.unpack("!12I", ntp_service.request(time_request, timeout=5.0).data.read())[10] return time.ctime(now - EPOCH_START)
def get_time(): """Get time from a locally running NTP server""" time_request = '\x1b' + 47 * '\0' now = struct.unpack("!12I", ntp_service.request(time_request, timeout=5.0).data.read())[10] return time.ctime(now - EPOCH_START)
[ "Get", "time", "from", "a", "locally", "running", "NTP", "server" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/use_socket.py#L14-L19
[ "def", "get_time", "(", ")", ":", "time_request", "=", "'\\x1b'", "+", "47", "*", "'\\0'", "now", "=", "struct", ".", "unpack", "(", "\"!12I\"", ",", "ntp_service", ".", "request", "(", "time_request", ",", "timeout", "=", "5.0", ")", ".", "data", ".",...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
reverse_http_proxy
Simple reverse http proxy function that returns data/html from another http server (via sockets) only drawback is the peername is static, and currently does not support being changed. Example: curl localhost:8000/reverse_http_proxy?length=400
examples/use_socket.py
def reverse_http_proxy(length: int=100): """Simple reverse http proxy function that returns data/html from another http server (via sockets) only drawback is the peername is static, and currently does not support being changed. Example: curl localhost:8000/reverse_http_proxy?length=400""" http_request ...
def reverse_http_proxy(length: int=100): """Simple reverse http proxy function that returns data/html from another http server (via sockets) only drawback is the peername is static, and currently does not support being changed. Example: curl localhost:8000/reverse_http_proxy?length=400""" http_request ...
[ "Simple", "reverse", "http", "proxy", "function", "that", "returns", "data", "/", "html", "from", "another", "http", "server", "(", "via", "sockets", ")", "only", "drawback", "is", "the", "peername", "is", "static", "and", "currently", "does", "not", "suppor...
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/examples/use_socket.py#L23-L33
[ "def", "reverse_http_proxy", "(", "length", ":", "int", "=", "100", ")", ":", "http_request", "=", "\"\"\"\nGET / HTTP/1.0\\r\\n\\r\\n\nHost: www.google.com\\r\\n\\r\\n\n\\r\\n\\r\\n\n\"\"\"", "return", "http_socket", ".", "request", "(", "http_request", ",", "timeout", "="...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
all
Validation only succeeds if all passed in validators return no errors
hug/validate.py
def all(*validators): """Validation only succeeds if all passed in validators return no errors""" def validate_all(fields): for validator in validators: errors = validator(fields) if errors: return errors validate_all.__doc__ = " and ".join(validator.__doc__ ...
def all(*validators): """Validation only succeeds if all passed in validators return no errors""" def validate_all(fields): for validator in validators: errors = validator(fields) if errors: return errors validate_all.__doc__ = " and ".join(validator.__doc__ ...
[ "Validation", "only", "succeeds", "if", "all", "passed", "in", "validators", "return", "no", "errors" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/validate.py#L25-L34
[ "def", "all", "(", "*", "validators", ")", ":", "def", "validate_all", "(", "fields", ")", ":", "for", "validator", "in", "validators", ":", "errors", "=", "validator", "(", "fields", ")", "if", "errors", ":", "return", "errors", "validate_all", ".", "__...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
any
If any of the specified validators pass the validation succeeds
hug/validate.py
def any(*validators): """If any of the specified validators pass the validation succeeds""" def validate_any(fields): errors = {} for validator in validators: validation_errors = validator(fields) if not validation_errors: return errors.update(...
def any(*validators): """If any of the specified validators pass the validation succeeds""" def validate_any(fields): errors = {} for validator in validators: validation_errors = validator(fields) if not validation_errors: return errors.update(...
[ "If", "any", "of", "the", "specified", "validators", "pass", "the", "validation", "succeeds" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/validate.py#L37-L49
[ "def", "any", "(", "*", "validators", ")", ":", "def", "validate_any", "(", "fields", ")", ":", "errors", "=", "{", "}", "for", "validator", "in", "validators", ":", "validation_errors", "=", "validator", "(", "fields", ")", "if", "not", "validation_errors...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
contains_one_of
Enables ensuring that one of multiple optional fields is set
hug/validate.py
def contains_one_of(*fields): """Enables ensuring that one of multiple optional fields is set""" message = 'Must contain any one of the following fields: {0}'.format(', '.join(fields)) def check_contains(endpoint_fields): for field in fields: if field in endpoint_fields: ...
def contains_one_of(*fields): """Enables ensuring that one of multiple optional fields is set""" message = 'Must contain any one of the following fields: {0}'.format(', '.join(fields)) def check_contains(endpoint_fields): for field in fields: if field in endpoint_fields: ...
[ "Enables", "ensuring", "that", "one", "of", "multiple", "optional", "fields", "is", "set" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/validate.py#L52-L66
[ "def", "contains_one_of", "(", "*", "fields", ")", ":", "message", "=", "'Must contain any one of the following fields: {0}'", ".", "format", "(", "', '", ".", "join", "(", "fields", ")", ")", "def", "check_contains", "(", "endpoint_fields", ")", ":", "for", "fi...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Router.requires
Adds additional requirements to the specified route
hug/routing.py
def requires(self, requirements, **overrides): """Adds additional requirements to the specified route""" return self.where(requires=tuple(self.route.get('requires', ())) + tuple(requirements), **overrides)
def requires(self, requirements, **overrides): """Adds additional requirements to the specified route""" return self.where(requires=tuple(self.route.get('requires', ())) + tuple(requirements), **overrides)
[ "Adds", "additional", "requirements", "to", "the", "specified", "route" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/routing.py#L78-L80
[ "def", "requires", "(", "self", ",", "requirements", ",", "*", "*", "overrides", ")", ":", "return", "self", ".", "where", "(", "requires", "=", "tuple", "(", "self", ".", "route", ".", "get", "(", "'requires'", ",", "(", ")", ")", ")", "+", "tuple...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Router.doesnt_require
Removes individual requirements while keeping all other defined ones within a route
hug/routing.py
def doesnt_require(self, requirements, **overrides): """Removes individual requirements while keeping all other defined ones within a route""" return self.where(requires=tuple(set(self.route.get('requires', ())).difference(requirements if type(...
def doesnt_require(self, requirements, **overrides): """Removes individual requirements while keeping all other defined ones within a route""" return self.where(requires=tuple(set(self.route.get('requires', ())).difference(requirements if type(...
[ "Removes", "individual", "requirements", "while", "keeping", "all", "other", "defined", "ones", "within", "a", "route" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/routing.py#L82-L85
[ "def", "doesnt_require", "(", "self", ",", "requirements", ",", "*", "*", "overrides", ")", ":", "return", "self", ".", "where", "(", "requires", "=", "tuple", "(", "set", "(", "self", ".", "route", ".", "get", "(", "'requires'", ",", "(", ")", ")", ...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
Router.where
Creates a new route, based on the current route, with the specified overrided values
hug/routing.py
def where(self, **overrides): """Creates a new route, based on the current route, with the specified overrided values""" route_data = self.route.copy() route_data.update(overrides) return self.__class__(**route_data)
def where(self, **overrides): """Creates a new route, based on the current route, with the specified overrided values""" route_data = self.route.copy() route_data.update(overrides) return self.__class__(**route_data)
[ "Creates", "a", "new", "route", "based", "on", "the", "current", "route", "with", "the", "specified", "overrided", "values" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/routing.py#L91-L95
[ "def", "where", "(", "self", ",", "*", "*", "overrides", ")", ":", "route_data", "=", "self", ".", "route", ".", "copy", "(", ")", "route_data", ".", "update", "(", "overrides", ")", "return", "self", ".", "__class__", "(", "*", "*", "route_data", ")...
080901c81576657f82e2432fd4a82f1d0d2f370c
train
InternalValidation.raise_on_invalid
Sets the route to raise validation errors instead of catching them
hug/routing.py
def raise_on_invalid(self, setting=True, **overrides): """Sets the route to raise validation errors instead of catching them""" return self.where(raise_on_invalid=setting, **overrides)
def raise_on_invalid(self, setting=True, **overrides): """Sets the route to raise validation errors instead of catching them""" return self.where(raise_on_invalid=setting, **overrides)
[ "Sets", "the", "route", "to", "raise", "validation", "errors", "instead", "of", "catching", "them" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/routing.py#L142-L144
[ "def", "raise_on_invalid", "(", "self", ",", "setting", "=", "True", ",", "*", "*", "overrides", ")", ":", "return", "self", ".", "where", "(", "raise_on_invalid", "=", "setting", ",", "*", "*", "overrides", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c
train
HTTPRouter.parse_body
Tells hug to automatically parse the input body if it matches a registered input format
hug/routing.py
def parse_body(self, automatic=True, **overrides): """Tells hug to automatically parse the input body if it matches a registered input format""" return self.where(parse_body=automatic, **overrides)
def parse_body(self, automatic=True, **overrides): """Tells hug to automatically parse the input body if it matches a registered input format""" return self.where(parse_body=automatic, **overrides)
[ "Tells", "hug", "to", "automatically", "parse", "the", "input", "body", "if", "it", "matches", "a", "registered", "input", "format" ]
hugapi/hug
python
https://github.com/hugapi/hug/blob/080901c81576657f82e2432fd4a82f1d0d2f370c/hug/routing.py#L218-L220
[ "def", "parse_body", "(", "self", ",", "automatic", "=", "True", ",", "*", "*", "overrides", ")", ":", "return", "self", ".", "where", "(", "parse_body", "=", "automatic", ",", "*", "*", "overrides", ")" ]
080901c81576657f82e2432fd4a82f1d0d2f370c