repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
sparklingpandas/sparklingpandas
sparklingpandas/dataframe.py
DataFrame.fromDataFrameRDD
def fromDataFrameRDD(cls, rdd, sql_ctx): """Construct a DataFrame from an RDD of DataFrames. No checking or validation occurs.""" result = DataFrame(None, sql_ctx) return result.from_rdd_of_dataframes(rdd)
python
def fromDataFrameRDD(cls, rdd, sql_ctx): """Construct a DataFrame from an RDD of DataFrames. No checking or validation occurs.""" result = DataFrame(None, sql_ctx) return result.from_rdd_of_dataframes(rdd)
[ "def", "fromDataFrameRDD", "(", "cls", ",", "rdd", ",", "sql_ctx", ")", ":", "result", "=", "DataFrame", "(", "None", ",", "sql_ctx", ")", "return", "result", ".", "from_rdd_of_dataframes", "(", "rdd", ")" ]
Construct a DataFrame from an RDD of DataFrames. No checking or validation occurs.
[ "Construct", "a", "DataFrame", "from", "an", "RDD", "of", "DataFrames", ".", "No", "checking", "or", "validation", "occurs", "." ]
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/dataframe.py#L145-L149
sparklingpandas/sparklingpandas
sparklingpandas/dataframe.py
DataFrame.applymap
def applymap(self, f, **kwargs): """Return a new DataFrame by applying a function to each element of each Panda DataFrame.""" def transform_rdd(rdd): return rdd.map(lambda data: data.applymap(f), **kwargs) return self._evil_apply_with_dataframes(transform_rdd, ...
python
def applymap(self, f, **kwargs): """Return a new DataFrame by applying a function to each element of each Panda DataFrame.""" def transform_rdd(rdd): return rdd.map(lambda data: data.applymap(f), **kwargs) return self._evil_apply_with_dataframes(transform_rdd, ...
[ "def", "applymap", "(", "self", ",", "f", ",", "*", "*", "kwargs", ")", ":", "def", "transform_rdd", "(", "rdd", ")", ":", "return", "rdd", ".", "map", "(", "lambda", "data", ":", "data", ".", "applymap", "(", "f", ")", ",", "*", "*", "kwargs", ...
Return a new DataFrame by applying a function to each element of each Panda DataFrame.
[ "Return", "a", "new", "DataFrame", "by", "applying", "a", "function", "to", "each", "element", "of", "each", "Panda", "DataFrame", "." ]
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/dataframe.py#L165-L171
sparklingpandas/sparklingpandas
sparklingpandas/dataframe.py
DataFrame.groupby
def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=False): """Returns a groupby on the schema rdd. This returns a GroupBy object. Note that grouping by a column name will be faster than most other options due to implementation.""" ...
python
def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=False): """Returns a groupby on the schema rdd. This returns a GroupBy object. Note that grouping by a column name will be faster than most other options due to implementation.""" ...
[ "def", "groupby", "(", "self", ",", "by", "=", "None", ",", "axis", "=", "0", ",", "level", "=", "None", ",", "as_index", "=", "True", ",", "sort", "=", "True", ",", "group_keys", "=", "True", ",", "squeeze", "=", "False", ")", ":", "from", "spar...
Returns a groupby on the schema rdd. This returns a GroupBy object. Note that grouping by a column name will be faster than most other options due to implementation.
[ "Returns", "a", "groupby", "on", "the", "schema", "rdd", ".", "This", "returns", "a", "GroupBy", "object", ".", "Note", "that", "grouping", "by", "a", "column", "name", "will", "be", "faster", "than", "most", "other", "options", "due", "to", "implementatio...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/dataframe.py#L181-L188
sparklingpandas/sparklingpandas
sparklingpandas/dataframe.py
DataFrame.collect
def collect(self): """Collect the elements in an DataFrame and concatenate the partition.""" local_df = self._schema_rdd.toPandas() correct_idx_df = _update_index_on_df(local_df, self._index_names) return correct_idx_df
python
def collect(self): """Collect the elements in an DataFrame and concatenate the partition.""" local_df = self._schema_rdd.toPandas() correct_idx_df = _update_index_on_df(local_df, self._index_names) return correct_idx_df
[ "def", "collect", "(", "self", ")", ":", "local_df", "=", "self", ".", "_schema_rdd", ".", "toPandas", "(", ")", "correct_idx_df", "=", "_update_index_on_df", "(", "local_df", ",", "self", ".", "_index_names", ")", "return", "correct_idx_df" ]
Collect the elements in an DataFrame and concatenate the partition.
[ "Collect", "the", "elements", "in", "an", "DataFrame", "and", "concatenate", "the", "partition", "." ]
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/dataframe.py#L233-L238
sparklingpandas/sparklingpandas
sparklingpandas/dataframe.py
DataFrame.stats
def stats(self, columns): """Compute the stats for each column provided in columns. Parameters ---------- columns : list of str, contains all columns to compute stats on. """ assert (not isinstance(columns, basestring)), "columns should be a " \ ...
python
def stats(self, columns): """Compute the stats for each column provided in columns. Parameters ---------- columns : list of str, contains all columns to compute stats on. """ assert (not isinstance(columns, basestring)), "columns should be a " \ ...
[ "def", "stats", "(", "self", ",", "columns", ")", ":", "assert", "(", "not", "isinstance", "(", "columns", ",", "basestring", ")", ")", ",", "\"columns should be a \"", "\"list of strs, \"", "\"not a str!\"", "assert", "isinstance", "(", "columns", ",", "list",...
Compute the stats for each column provided in columns. Parameters ---------- columns : list of str, contains all columns to compute stats on.
[ "Compute", "the", "stats", "for", "each", "column", "provided", "in", "columns", ".", "Parameters", "----------", "columns", ":", "list", "of", "str", "contains", "all", "columns", "to", "compute", "stats", "on", "." ]
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/dataframe.py#L240-L256
sparklingpandas/sparklingpandas
sparklingpandas/prdd.py
PRDD.applymap
def applymap(self, func, **kwargs): """Return a new PRDD by applying a function to each element of each pandas DataFrame.""" return self.from_rdd( self._rdd.map(lambda data: data.applymap(func), **kwargs))
python
def applymap(self, func, **kwargs): """Return a new PRDD by applying a function to each element of each pandas DataFrame.""" return self.from_rdd( self._rdd.map(lambda data: data.applymap(func), **kwargs))
[ "def", "applymap", "(", "self", ",", "func", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "from_rdd", "(", "self", ".", "_rdd", ".", "map", "(", "lambda", "data", ":", "data", ".", "applymap", "(", "func", ")", ",", "*", "*", "kwargs...
Return a new PRDD by applying a function to each element of each pandas DataFrame.
[ "Return", "a", "new", "PRDD", "by", "applying", "a", "function", "to", "each", "element", "of", "each", "pandas", "DataFrame", "." ]
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/prdd.py#L49-L53
sparklingpandas/sparklingpandas
sparklingpandas/prdd.py
PRDD.groupby
def groupby(self, *args, **kwargs): """Takes the same parameters as groupby on DataFrame. Like with groupby on DataFrame disabling sorting will result in an even larger performance improvement. This returns a Sparkling Pandas L{GroupBy} object which supports many of the same operations a...
python
def groupby(self, *args, **kwargs): """Takes the same parameters as groupby on DataFrame. Like with groupby on DataFrame disabling sorting will result in an even larger performance improvement. This returns a Sparkling Pandas L{GroupBy} object which supports many of the same operations a...
[ "def", "groupby", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "from", "sparklingpandas", ".", "groupby", "import", "GroupBy", "return", "GroupBy", "(", "self", ".", "_rdd", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
Takes the same parameters as groupby on DataFrame. Like with groupby on DataFrame disabling sorting will result in an even larger performance improvement. This returns a Sparkling Pandas L{GroupBy} object which supports many of the same operations as regular GroupBy but not all.
[ "Takes", "the", "same", "parameters", "as", "groupby", "on", "DataFrame", ".", "Like", "with", "groupby", "on", "DataFrame", "disabling", "sorting", "will", "result", "in", "an", "even", "larger", "performance", "improvement", ".", "This", "returns", "a", "Spa...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/prdd.py#L59-L66
sparklingpandas/sparklingpandas
sparklingpandas/prdd.py
PRDD.collect
def collect(self): """Collect the elements in an PRDD and concatenate the partition.""" # The order of the frame order appends is based on the implementation # of reduce which calls our function with # f(valueToBeAdded, accumulator) so we do our reduce implementation. def append_...
python
def collect(self): """Collect the elements in an PRDD and concatenate the partition.""" # The order of the frame order appends is based on the implementation # of reduce which calls our function with # f(valueToBeAdded, accumulator) so we do our reduce implementation. def append_...
[ "def", "collect", "(", "self", ")", ":", "# The order of the frame order appends is based on the implementation", "# of reduce which calls our function with", "# f(valueToBeAdded, accumulator) so we do our reduce implementation.", "def", "append_frames", "(", "frame_a", ",", "frame_b", ...
Collect the elements in an PRDD and concatenate the partition.
[ "Collect", "the", "elements", "in", "an", "PRDD", "and", "concatenate", "the", "partition", "." ]
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/prdd.py#L108-L115
sparklingpandas/sparklingpandas
sparklingpandas/prdd.py
PRDD._custom_rdd_reduce
def _custom_rdd_reduce(self, reduce_func): """Provides a custom RDD reduce which preserves ordering if the RDD has been sorted. This is useful for us because we need this functionality as many pandas operations support sorting the results. The standard reduce in PySpark does not have thi...
python
def _custom_rdd_reduce(self, reduce_func): """Provides a custom RDD reduce which preserves ordering if the RDD has been sorted. This is useful for us because we need this functionality as many pandas operations support sorting the results. The standard reduce in PySpark does not have thi...
[ "def", "_custom_rdd_reduce", "(", "self", ",", "reduce_func", ")", ":", "def", "accumulating_iter", "(", "iterator", ")", ":", "acc", "=", "None", "for", "obj", "in", "iterator", ":", "if", "acc", "is", "None", ":", "acc", "=", "obj", "else", ":", "acc...
Provides a custom RDD reduce which preserves ordering if the RDD has been sorted. This is useful for us because we need this functionality as many pandas operations support sorting the results. The standard reduce in PySpark does not have this property. Note that when PySpark no longer ...
[ "Provides", "a", "custom", "RDD", "reduce", "which", "preserves", "ordering", "if", "the", "RDD", "has", "been", "sorted", ".", "This", "is", "useful", "for", "us", "because", "we", "need", "this", "functionality", "as", "many", "pandas", "operations", "supp...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/prdd.py#L117-L134
sparklingpandas/sparklingpandas
sparklingpandas/prdd.py
PRDD.stats
def stats(self, columns): """Compute the stats for each column provided in columns. Parameters ---------- columns : list of str, contains all columns to compute stats on. """ def reduce_func(sc1, sc2): return sc1.merge_pstats(sc2) return self._rdd.map...
python
def stats(self, columns): """Compute the stats for each column provided in columns. Parameters ---------- columns : list of str, contains all columns to compute stats on. """ def reduce_func(sc1, sc2): return sc1.merge_pstats(sc2) return self._rdd.map...
[ "def", "stats", "(", "self", ",", "columns", ")", ":", "def", "reduce_func", "(", "sc1", ",", "sc2", ")", ":", "return", "sc1", ".", "merge_pstats", "(", "sc2", ")", "return", "self", ".", "_rdd", ".", "mapPartitions", "(", "lambda", "partition", ":", ...
Compute the stats for each column provided in columns. Parameters ---------- columns : list of str, contains all columns to compute stats on.
[ "Compute", "the", "stats", "for", "each", "column", "provided", "in", "columns", ".", "Parameters", "----------", "columns", ":", "list", "of", "str", "contains", "all", "columns", "to", "compute", "stats", "on", "." ]
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/prdd.py#L136-L147
sparklingpandas/sparklingpandas
sparklingpandas/pcontext.py
PSparkContext.read_csv
def read_csv(self, file_path, use_whole_file=False, names=None, skiprows=0, *args, **kwargs): """Read a CSV file in and parse it into Pandas DataFrames. By default, the first row from the first partition of that data is parsed and used as the column names for the data from. If n...
python
def read_csv(self, file_path, use_whole_file=False, names=None, skiprows=0, *args, **kwargs): """Read a CSV file in and parse it into Pandas DataFrames. By default, the first row from the first partition of that data is parsed and used as the column names for the data from. If n...
[ "def", "read_csv", "(", "self", ",", "file_path", ",", "use_whole_file", "=", "False", ",", "names", "=", "None", ",", "skiprows", "=", "0", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "def", "csv_file", "(", "partition_number", ",", "files", ...
Read a CSV file in and parse it into Pandas DataFrames. By default, the first row from the first partition of that data is parsed and used as the column names for the data from. If no 'names' param is provided we parse the first row of the first partition of data and use it for column na...
[ "Read", "a", "CSV", "file", "in", "and", "parse", "it", "into", "Pandas", "DataFrames", ".", "By", "default", "the", "first", "row", "from", "the", "first", "partition", "of", "that", "data", "is", "parsed", "and", "used", "as", "the", "column", "names",...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/pcontext.py#L68-L155
sparklingpandas/sparklingpandas
sparklingpandas/pcontext.py
PSparkContext.jsonFile
def jsonFile(self, path, schema=None, sampling_ratio=1.0): """Loads a text file storing one JSON object per line as a L{DataFrame}. Parameters ---------- path: string The path of the json files to load. Should be Hadoop style paths (e.g. hdfs://..., file...
python
def jsonFile(self, path, schema=None, sampling_ratio=1.0): """Loads a text file storing one JSON object per line as a L{DataFrame}. Parameters ---------- path: string The path of the json files to load. Should be Hadoop style paths (e.g. hdfs://..., file...
[ "def", "jsonFile", "(", "self", ",", "path", ",", "schema", "=", "None", ",", "sampling_ratio", "=", "1.0", ")", ":", "schema_rdd", "=", "self", ".", "sql_ctx", ".", "jsonFile", "(", "path", ",", "schema", ",", "sampling_ratio", ")", "return", "self", ...
Loads a text file storing one JSON object per line as a L{DataFrame}. Parameters ---------- path: string The path of the json files to load. Should be Hadoop style paths (e.g. hdfs://..., file://... etc.). schema: StructType, optional If you...
[ "Loads", "a", "text", "file", "storing", "one", "JSON", "object", "per", "line", "as", "a", "L", "{", "DataFrame", "}", ".", "Parameters", "----------", "path", ":", "string", "The", "path", "of", "the", "json", "files", "to", "load", ".", "Should", "b...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/pcontext.py#L171-L196
sparklingpandas/sparklingpandas
sparklingpandas/pcontext.py
PSparkContext.from_pd_data_frame
def from_pd_data_frame(self, local_df): """Make a Sparkling Pandas dataframe from a local Pandas DataFrame. The intend use is for testing or joining distributed data with local data. The types are re-infered, so they may not match. Parameters ---------- local_df: ...
python
def from_pd_data_frame(self, local_df): """Make a Sparkling Pandas dataframe from a local Pandas DataFrame. The intend use is for testing or joining distributed data with local data. The types are re-infered, so they may not match. Parameters ---------- local_df: ...
[ "def", "from_pd_data_frame", "(", "self", ",", "local_df", ")", ":", "def", "frame_to_rows", "(", "frame", ")", ":", "\"\"\"Convert a Pandas DataFrame into a list of Spark SQL Rows\"\"\"", "# TODO: Convert to row objects directly?", "return", "[", "r", ".", "tolist", "(", ...
Make a Sparkling Pandas dataframe from a local Pandas DataFrame. The intend use is for testing or joining distributed data with local data. The types are re-infered, so they may not match. Parameters ---------- local_df: Pandas DataFrame The data to turn into ...
[ "Make", "a", "Sparkling", "Pandas", "dataframe", "from", "a", "local", "Pandas", "DataFrame", ".", "The", "intend", "use", "is", "for", "testing", "or", "joining", "distributed", "data", "with", "local", "data", ".", "The", "types", "are", "re", "-", "infe...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/pcontext.py#L198-L229
sparklingpandas/sparklingpandas
sparklingpandas/pcontext.py
PSparkContext.sql
def sql(self, query): """Perform a SQL query and create a L{DataFrame} of the result. The SQL query is run using Spark SQL. This is not intended for querying arbitrary databases, but rather querying Spark SQL tables. Parameters ---------- query: string The SQL...
python
def sql(self, query): """Perform a SQL query and create a L{DataFrame} of the result. The SQL query is run using Spark SQL. This is not intended for querying arbitrary databases, but rather querying Spark SQL tables. Parameters ---------- query: string The SQL...
[ "def", "sql", "(", "self", ",", "query", ")", ":", "return", "DataFrame", ".", "from_spark_rdd", "(", "self", ".", "sql_ctx", ".", "sql", "(", "query", ")", ",", "self", ".", "sql_ctx", ")" ]
Perform a SQL query and create a L{DataFrame} of the result. The SQL query is run using Spark SQL. This is not intended for querying arbitrary databases, but rather querying Spark SQL tables. Parameters ---------- query: string The SQL query to pass to Spark SQL to ex...
[ "Perform", "a", "SQL", "query", "and", "create", "a", "L", "{", "DataFrame", "}", "of", "the", "result", ".", "The", "SQL", "query", "is", "run", "using", "Spark", "SQL", ".", "This", "is", "not", "intended", "for", "querying", "arbitrary", "databases", ...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/pcontext.py#L231-L243
sparklingpandas/sparklingpandas
sparklingpandas/pcontext.py
PSparkContext.table
def table(self, table): """Returns the provided Spark SQL table as a L{DataFrame} Parameters ---------- table: string The name of the Spark SQL table to turn into a L{DataFrame} Returns ------- Sparkling Pandas DataFrame. """ return Dat...
python
def table(self, table): """Returns the provided Spark SQL table as a L{DataFrame} Parameters ---------- table: string The name of the Spark SQL table to turn into a L{DataFrame} Returns ------- Sparkling Pandas DataFrame. """ return Dat...
[ "def", "table", "(", "self", ",", "table", ")", ":", "return", "DataFrame", ".", "from_spark_rdd", "(", "self", ".", "sql_ctx", ".", "table", "(", "table", ")", ",", "self", ".", "sql_ctx", ")" ]
Returns the provided Spark SQL table as a L{DataFrame} Parameters ---------- table: string The name of the Spark SQL table to turn into a L{DataFrame} Returns ------- Sparkling Pandas DataFrame.
[ "Returns", "the", "provided", "Spark", "SQL", "table", "as", "a", "L", "{", "DataFrame", "}", "Parameters", "----------", "table", ":", "string", "The", "name", "of", "the", "Spark", "SQL", "table", "to", "turn", "into", "a", "L", "{", "DataFrame", "}", ...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/pcontext.py#L245-L256
sparklingpandas/sparklingpandas
sparklingpandas/pcontext.py
PSparkContext.DataFrame
def DataFrame(self, elements, *args, **kwargs): """Create a Sparkling Pandas DataFrame for the provided elements, following the same API as constructing a Panda's DataFrame. Note: since elements is local this is only useful for distributing dataframes which are small enough to fit on a s...
python
def DataFrame(self, elements, *args, **kwargs): """Create a Sparkling Pandas DataFrame for the provided elements, following the same API as constructing a Panda's DataFrame. Note: since elements is local this is only useful for distributing dataframes which are small enough to fit on a s...
[ "def", "DataFrame", "(", "self", ",", "elements", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "from_pd_data_frame", "(", "pandas", ".", "DataFrame", "(", "elements", ",", "*", "args", ",", "*", "*", "kwargs", ")", ")" ...
Create a Sparkling Pandas DataFrame for the provided elements, following the same API as constructing a Panda's DataFrame. Note: since elements is local this is only useful for distributing dataframes which are small enough to fit on a single machine anyways. Parameters ---------...
[ "Create", "a", "Sparkling", "Pandas", "DataFrame", "for", "the", "provided", "elements", "following", "the", "same", "API", "as", "constructing", "a", "Panda", "s", "DataFrame", ".", "Note", ":", "since", "elements", "is", "local", "this", "is", "only", "use...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/pcontext.py#L272-L289
sparklingpandas/sparklingpandas
sparklingpandas/pcontext.py
PSparkContext.read_json
def read_json(self, file_path, *args, **kwargs): """Read a json file in and parse it into Pandas DataFrames. If no names is provided we use the first row for the names. Currently, it is not possible to skip the first n rows of a file. Headers are provided in the json fi...
python
def read_json(self, file_path, *args, **kwargs): """Read a json file in and parse it into Pandas DataFrames. If no names is provided we use the first row for the names. Currently, it is not possible to skip the first n rows of a file. Headers are provided in the json fi...
[ "def", "read_json", "(", "self", ",", "file_path", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "def", "json_file_to_df", "(", "files", ")", ":", "\"\"\" Transforms a JSON file into a list of data\"\"\"", "for", "_", ",", "contents", "in", "files", ":"...
Read a json file in and parse it into Pandas DataFrames. If no names is provided we use the first row for the names. Currently, it is not possible to skip the first n rows of a file. Headers are provided in the json file and not specified separately. Parameters ---------- ...
[ "Read", "a", "json", "file", "in", "and", "parse", "it", "into", "Pandas", "DataFrames", ".", "If", "no", "names", "is", "provided", "we", "use", "the", "first", "row", "for", "the", "names", ".", "Currently", "it", "is", "not", "possible", "to", "skip...
train
https://github.com/sparklingpandas/sparklingpandas/blob/7d549df4348c979042b683c355aa778fc6d3a768/sparklingpandas/pcontext.py#L303-L329
zimeon/iiif
iiif/manipulator_gen.py
IIIFManipulatorGen.do_first
def do_first(self): """Load generator, set size. We take the generator module name from self.srcfile so that this manipulator will work with different generators in a similar way to how the ordinary generators work with different images """ # Load generator modul...
python
def do_first(self): """Load generator, set size. We take the generator module name from self.srcfile so that this manipulator will work with different generators in a similar way to how the ordinary generators work with different images """ # Load generator modul...
[ "def", "do_first", "(", "self", ")", ":", "# Load generator module and create instance if we haven't already", "if", "(", "not", "self", ".", "srcfile", ")", ":", "raise", "IIIFError", "(", "text", "=", "(", "\"No generator specified\"", ")", ")", "if", "(", "not"...
Load generator, set size. We take the generator module name from self.srcfile so that this manipulator will work with different generators in a similar way to how the ordinary generators work with different images
[ "Load", "generator", "set", "size", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_gen.py#L31-L60
zimeon/iiif
iiif/manipulator_gen.py
IIIFManipulatorGen.do_region
def do_region(self, x, y, w, h): """Record region.""" if (x is None): self.rx = 0 self.ry = 0 self.rw = self.width self.rh = self.height else: self.rx = x self.ry = y self.rw = w self.rh = h
python
def do_region(self, x, y, w, h): """Record region.""" if (x is None): self.rx = 0 self.ry = 0 self.rw = self.width self.rh = self.height else: self.rx = x self.ry = y self.rw = w self.rh = h
[ "def", "do_region", "(", "self", ",", "x", ",", "y", ",", "w", ",", "h", ")", ":", "if", "(", "x", "is", "None", ")", ":", "self", ".", "rx", "=", "0", "self", ".", "ry", "=", "0", "self", ".", "rw", "=", "self", ".", "width", "self", "."...
Record region.
[ "Record", "region", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_gen.py#L62-L73
zimeon/iiif
iiif/manipulator_gen.py
IIIFManipulatorGen.do_size
def do_size(self, w, h): """Record size.""" if (w is None): self.sw = self.rw self.sh = self.rh else: self.sw = w self.sh = h # Now we have region and size, generate the image image = Image.new("RGB", (self.sw, self.sh), self.gen.ba...
python
def do_size(self, w, h): """Record size.""" if (w is None): self.sw = self.rw self.sh = self.rh else: self.sw = w self.sh = h # Now we have region and size, generate the image image = Image.new("RGB", (self.sw, self.sh), self.gen.ba...
[ "def", "do_size", "(", "self", ",", "w", ",", "h", ")", ":", "if", "(", "w", "is", "None", ")", ":", "self", ".", "sw", "=", "self", ".", "rw", "self", ".", "sh", "=", "self", ".", "rh", "else", ":", "self", ".", "sw", "=", "w", "self", "...
Record size.
[ "Record", "size", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_gen.py#L75-L92
zimeon/iiif
iiif_static.py
main
def main(): """Parse arguments, instantiate IIIFStatic, run.""" if (sys.version_info < (2, 7)): sys.exit("This program requires python version 2.7 or later") # Options and arguments p = optparse.OptionParser(description='IIIF Image API static file generator', usage...
python
def main(): """Parse arguments, instantiate IIIFStatic, run.""" if (sys.version_info < (2, 7)): sys.exit("This program requires python version 2.7 or later") # Options and arguments p = optparse.OptionParser(description='IIIF Image API static file generator', usage...
[ "def", "main", "(", ")", ":", "if", "(", "sys", ".", "version_info", "<", "(", "2", ",", "7", ")", ")", ":", "sys", ".", "exit", "(", "\"This program requires python version 2.7 or later\"", ")", "# Options and arguments", "p", "=", "optparse", ".", "OptionP...
Parse arguments, instantiate IIIFStatic, run.
[ "Parse", "arguments", "instantiate", "IIIFStatic", "run", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif_static.py#L17-L122
zimeon/iiif
iiif/auth_basic.py
IIIFAuthBasic.login_handler
def login_handler(self, config=None, prefix=None, **args): """HTTP Basic login handler. Respond with 401 and WWW-Authenticate header if there are no credentials or bad credentials. If there are credentials then simply check for username equal to password for validity. """ ...
python
def login_handler(self, config=None, prefix=None, **args): """HTTP Basic login handler. Respond with 401 and WWW-Authenticate header if there are no credentials or bad credentials. If there are credentials then simply check for username equal to password for validity. """ ...
[ "def", "login_handler", "(", "self", ",", "config", "=", "None", ",", "prefix", "=", "None", ",", "*", "*", "args", ")", ":", "headers", "=", "{", "}", "headers", "[", "'Access-control-allow-origin'", "]", "=", "'*'", "headers", "[", "'Content-type'", "]...
HTTP Basic login handler. Respond with 401 and WWW-Authenticate header if there are no credentials or bad credentials. If there are credentials then simply check for username equal to password for validity.
[ "HTTP", "Basic", "login", "handler", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth_basic.py#L26-L44
zimeon/iiif
iiif/auth_clickthrough.py
IIIFAuthClickthrough.login_service_description
def login_service_description(self): """Clickthrough login service description. The login service description _MUST_ include the token service description. Additionally, for a clickthroudh loginThe authentication pattern is indicated via the profile URI which is built using self.auth_pa...
python
def login_service_description(self): """Clickthrough login service description. The login service description _MUST_ include the token service description. Additionally, for a clickthroudh loginThe authentication pattern is indicated via the profile URI which is built using self.auth_pa...
[ "def", "login_service_description", "(", "self", ")", ":", "desc", "=", "super", "(", "IIIFAuthClickthrough", ",", "self", ")", ".", "login_service_description", "(", ")", "desc", "[", "'confirmLabel'", "]", "=", "self", ".", "confirm_label", "return", "desc" ]
Clickthrough login service description. The login service description _MUST_ include the token service description. Additionally, for a clickthroudh loginThe authentication pattern is indicated via the profile URI which is built using self.auth_pattern.
[ "Clickthrough", "login", "service", "description", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth_clickthrough.py#L22-L31
zimeon/iiif
iiif/request.py
IIIFRequest.clear
def clear(self): """Clear all data that might pertain to an individual IIIF URL. Does not change/reset the baseurl or API version which might be useful in a sequence of calls. """ # API parameters self.identifier = None self.region = None self.size = None...
python
def clear(self): """Clear all data that might pertain to an individual IIIF URL. Does not change/reset the baseurl or API version which might be useful in a sequence of calls. """ # API parameters self.identifier = None self.region = None self.size = None...
[ "def", "clear", "(", "self", ")", ":", "# API parameters", "self", ".", "identifier", "=", "None", "self", ".", "region", "=", "None", "self", ".", "size", "=", "None", "self", ".", "rotation", "=", "None", "self", ".", "quality", "=", "None", "self", ...
Clear all data that might pertain to an individual IIIF URL. Does not change/reset the baseurl or API version which might be useful in a sequence of calls.
[ "Clear", "all", "data", "that", "might", "pertain", "to", "an", "individual", "IIIF", "URL", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L83-L108
zimeon/iiif
iiif/request.py
IIIFRequest.api_version
def api_version(self, v): """Set the api_version and associated configurations.""" self._api_version = v if (self._api_version >= '2.0'): self.default_quality = 'default' self.allowed_qualities = ['default', 'color', 'bitonal', 'gray'] else: # versions 1.0 and 1....
python
def api_version(self, v): """Set the api_version and associated configurations.""" self._api_version = v if (self._api_version >= '2.0'): self.default_quality = 'default' self.allowed_qualities = ['default', 'color', 'bitonal', 'gray'] else: # versions 1.0 and 1....
[ "def", "api_version", "(", "self", ",", "v", ")", ":", "self", ".", "_api_version", "=", "v", "if", "(", "self", ".", "_api_version", ">=", "'2.0'", ")", ":", "self", ".", "default_quality", "=", "'default'", "self", ".", "allowed_qualities", "=", "[", ...
Set the api_version and associated configurations.
[ "Set", "the", "api_version", "and", "associated", "configurations", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L116-L124
zimeon/iiif
iiif/request.py
IIIFRequest.url
def url(self, **params): """Build a URL path for image or info request. An IIIF Image request with parameterized form is assumed unless the info parameter is specified, in which case an Image Information request URI is constructred. """ self._setattrs(**params) p...
python
def url(self, **params): """Build a URL path for image or info request. An IIIF Image request with parameterized form is assumed unless the info parameter is specified, in which case an Image Information request URI is constructred. """ self._setattrs(**params) p...
[ "def", "url", "(", "self", ",", "*", "*", "params", ")", ":", "self", ".", "_setattrs", "(", "*", "*", "params", ")", "path", "=", "self", ".", "baseurl", "+", "self", ".", "quote", "(", "self", ".", "identifier", ")", "+", "\"/\"", "if", "(", ...
Build a URL path for image or info request. An IIIF Image request with parameterized form is assumed unless the info parameter is specified, in which case an Image Information request URI is constructred.
[ "Build", "a", "URL", "path", "for", "image", "or", "info", "request", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L148-L194
zimeon/iiif
iiif/request.py
IIIFRequest.parse_url
def parse_url(self, url): """Parse an IIIF API URL path and each component. Will parse a URL or URL path that accords with either the parametrized or info request forms. Will raise an IIIFRequestError on failure. A wrapper for the split_url() and parse_parameters() methods. ...
python
def parse_url(self, url): """Parse an IIIF API URL path and each component. Will parse a URL or URL path that accords with either the parametrized or info request forms. Will raise an IIIFRequestError on failure. A wrapper for the split_url() and parse_parameters() methods. ...
[ "def", "parse_url", "(", "self", ",", "url", ")", ":", "self", ".", "split_url", "(", "url", ")", "if", "(", "not", "self", ".", "info", ")", ":", "self", ".", "parse_parameters", "(", ")", "return", "(", "self", ")" ]
Parse an IIIF API URL path and each component. Will parse a URL or URL path that accords with either the parametrized or info request forms. Will raise an IIIFRequestError on failure. A wrapper for the split_url() and parse_parameters() methods. Note that behavior of split_url(...
[ "Parse", "an", "IIIF", "API", "URL", "path", "and", "each", "component", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L196-L210
zimeon/iiif
iiif/request.py
IIIFRequest.split_url
def split_url(self, url): """Parse an IIIF API URL path into components. Will parse a URL or URL path that accords with either the parametrized or info API forms. Will raise an IIIFRequestError on failure. If self.identifier is set then url is assumed not to include the ...
python
def split_url(self, url): """Parse an IIIF API URL path into components. Will parse a URL or URL path that accords with either the parametrized or info API forms. Will raise an IIIFRequestError on failure. If self.identifier is set then url is assumed not to include the ...
[ "def", "split_url", "(", "self", ",", "url", ")", ":", "# clear data first", "identifier", "=", "self", ".", "identifier", "self", ".", "clear", "(", ")", "# url must start with baseurl if set (including slash)", "if", "(", "self", ".", "baseurl", "is", "not", "...
Parse an IIIF API URL path into components. Will parse a URL or URL path that accords with either the parametrized or info API forms. Will raise an IIIFRequestError on failure. If self.identifier is set then url is assumed not to include the identifier.
[ "Parse", "an", "IIIF", "API", "URL", "path", "into", "components", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L228-L285
zimeon/iiif
iiif/request.py
IIIFRequest.strip_format
def strip_format(self, str_and_format): """Look for optional .fmt at end of URI. The format must start with letter. Note that we want to catch the case of a dot and no format (format='') which is different from no dot (format=None) Sets self.format as side effect, returns possi...
python
def strip_format(self, str_and_format): """Look for optional .fmt at end of URI. The format must start with letter. Note that we want to catch the case of a dot and no format (format='') which is different from no dot (format=None) Sets self.format as side effect, returns possi...
[ "def", "strip_format", "(", "self", ",", "str_and_format", ")", ":", "m", "=", "re", ".", "match", "(", "\"(.+)\\.([a-zA-Z]\\w*)$\"", ",", "str_and_format", ")", "if", "(", "m", ")", ":", "# There is a format string at end, chop off and store", "str_and_format", "="...
Look for optional .fmt at end of URI. The format must start with letter. Note that we want to catch the case of a dot and no format (format='') which is different from no dot (format=None) Sets self.format as side effect, returns possibly modified string
[ "Look", "for", "optional", ".", "fmt", "at", "end", "of", "URI", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L287-L301
zimeon/iiif
iiif/request.py
IIIFRequest.parse_parameters
def parse_parameters(self): """Parse the parameters of an Image Information request. Will throw an IIIFRequestError on failure, set attributes on success. Care is taken not to change any of the artibutes which store path components. All parsed values are stored in new attributes...
python
def parse_parameters(self): """Parse the parameters of an Image Information request. Will throw an IIIFRequestError on failure, set attributes on success. Care is taken not to change any of the artibutes which store path components. All parsed values are stored in new attributes...
[ "def", "parse_parameters", "(", "self", ")", ":", "self", ".", "parse_region", "(", ")", "self", ".", "parse_size", "(", ")", "self", ".", "parse_rotation", "(", ")", "self", ".", "parse_quality", "(", ")", "self", ".", "parse_format", "(", ")" ]
Parse the parameters of an Image Information request. Will throw an IIIFRequestError on failure, set attributes on success. Care is taken not to change any of the artibutes which store path components. All parsed values are stored in new attributes.
[ "Parse", "the", "parameters", "of", "an", "Image", "Information", "request", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L303-L315
zimeon/iiif
iiif/request.py
IIIFRequest.parse_region
def parse_region(self): """Parse the region component of the path. /full/ -> self.region_full = True (test this first) /square/ -> self.region_square = True (test this second) /x,y,w,h/ -> self.region_xywh = (x,y,w,h) /pct:x,y,w,h/ -> self.region_xywh and self.region_pct = True ...
python
def parse_region(self): """Parse the region component of the path. /full/ -> self.region_full = True (test this first) /square/ -> self.region_square = True (test this second) /x,y,w,h/ -> self.region_xywh = (x,y,w,h) /pct:x,y,w,h/ -> self.region_xywh and self.region_pct = True ...
[ "def", "parse_region", "(", "self", ")", ":", "self", ".", "region_full", "=", "False", "self", ".", "region_square", "=", "False", "self", ".", "region_pct", "=", "False", "if", "(", "self", ".", "region", "is", "None", "or", "self", ".", "region", "=...
Parse the region component of the path. /full/ -> self.region_full = True (test this first) /square/ -> self.region_square = True (test this second) /x,y,w,h/ -> self.region_xywh = (x,y,w,h) /pct:x,y,w,h/ -> self.region_xywh and self.region_pct = True Will throw errors if the p...
[ "Parse", "the", "region", "component", "of", "the", "path", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L317-L386
zimeon/iiif
iiif/request.py
IIIFRequest.parse_size
def parse_size(self, size=None): """Parse the size component of the path. /full/ -> self.size_full = True /max/ -> self.size_mac = True (2.1 and up) /w,/ -> self.size_wh = (w,None) /,h/ -> self.size_wh = (None,h) /w,h/ -> self.size_wh = (w,h) /pct:p/ -> self.siz...
python
def parse_size(self, size=None): """Parse the size component of the path. /full/ -> self.size_full = True /max/ -> self.size_mac = True (2.1 and up) /w,/ -> self.size_wh = (w,None) /,h/ -> self.size_wh = (None,h) /w,h/ -> self.size_wh = (w,h) /pct:p/ -> self.siz...
[ "def", "parse_size", "(", "self", ",", "size", "=", "None", ")", ":", "if", "(", "size", "is", "not", "None", ")", ":", "self", ".", "size", "=", "size", "self", ".", "size_pct", "=", "None", "self", ".", "size_bang", "=", "False", "self", ".", "...
Parse the size component of the path. /full/ -> self.size_full = True /max/ -> self.size_mac = True (2.1 and up) /w,/ -> self.size_wh = (w,None) /,h/ -> self.size_wh = (None,h) /w,h/ -> self.size_wh = (w,h) /pct:p/ -> self.size_pct = p /!w,h/ -> self.size_wh = (...
[ "Parse", "the", "size", "component", "of", "the", "path", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L388-L457
zimeon/iiif
iiif/request.py
IIIFRequest._parse_w_comma_h
def _parse_w_comma_h(self, whstr, param): """Utility to parse "w,h" "w," or ",h" values. Returns (w,h) where w,h are either None or ineteger. Will throw a ValueError if there is a problem with one or both. """ try: (wstr, hstr) = whstr.split(',', 2) w = s...
python
def _parse_w_comma_h(self, whstr, param): """Utility to parse "w,h" "w," or ",h" values. Returns (w,h) where w,h are either None or ineteger. Will throw a ValueError if there is a problem with one or both. """ try: (wstr, hstr) = whstr.split(',', 2) w = s...
[ "def", "_parse_w_comma_h", "(", "self", ",", "whstr", ",", "param", ")", ":", "try", ":", "(", "wstr", ",", "hstr", ")", "=", "whstr", ".", "split", "(", "','", ",", "2", ")", "w", "=", "self", ".", "_parse_non_negative_int", "(", "wstr", ",", "'w'...
Utility to parse "w,h" "w," or ",h" values. Returns (w,h) where w,h are either None or ineteger. Will throw a ValueError if there is a problem with one or both.
[ "Utility", "to", "parse", "w", "h", "w", "or", "h", "values", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L459-L477
zimeon/iiif
iiif/request.py
IIIFRequest._parse_non_negative_int
def _parse_non_negative_int(self, istr, name): """Parse integer from string (istr). The (name) parameter is used just for IIIFRequestError message generation to indicate what the error is in. """ if (istr == ''): return(None) try: i = int(istr) ...
python
def _parse_non_negative_int(self, istr, name): """Parse integer from string (istr). The (name) parameter is used just for IIIFRequestError message generation to indicate what the error is in. """ if (istr == ''): return(None) try: i = int(istr) ...
[ "def", "_parse_non_negative_int", "(", "self", ",", "istr", ",", "name", ")", ":", "if", "(", "istr", "==", "''", ")", ":", "return", "(", "None", ")", "try", ":", "i", "=", "int", "(", "istr", ")", "except", "ValueError", ":", "raise", "ValueError",...
Parse integer from string (istr). The (name) parameter is used just for IIIFRequestError message generation to indicate what the error is in.
[ "Parse", "integer", "from", "string", "(", "istr", ")", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L479-L493
zimeon/iiif
iiif/request.py
IIIFRequest.parse_rotation
def parse_rotation(self, rotation=None): """Check and interpret rotation. Uses value of self.rotation as starting point unless rotation parameter is specified in the call. Sets self.rotation_deg to a floating point number 0 <= angle < 360. Includes translation of 360 to 0. If th...
python
def parse_rotation(self, rotation=None): """Check and interpret rotation. Uses value of self.rotation as starting point unless rotation parameter is specified in the call. Sets self.rotation_deg to a floating point number 0 <= angle < 360. Includes translation of 360 to 0. If th...
[ "def", "parse_rotation", "(", "self", ",", "rotation", "=", "None", ")", ":", "if", "(", "rotation", "is", "not", "None", ")", ":", "self", ".", "rotation", "=", "rotation", "self", ".", "rotation_deg", "=", "0.0", "self", ".", "rotation_mirror", "=", ...
Check and interpret rotation. Uses value of self.rotation as starting point unless rotation parameter is specified in the call. Sets self.rotation_deg to a floating point number 0 <= angle < 360. Includes translation of 360 to 0. If there is a prefix bang (!) then self.rotation_mirror ...
[ "Check", "and", "interpret", "rotation", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L495-L529
zimeon/iiif
iiif/request.py
IIIFRequest.parse_quality
def parse_quality(self): """Check quality paramater. Sets self.quality_val based on simple substitution of 'native' for default. Checks for the three valid values else throws an IIIFRequestError. """ if (self.quality is None): self.quality_val = self.default_...
python
def parse_quality(self): """Check quality paramater. Sets self.quality_val based on simple substitution of 'native' for default. Checks for the three valid values else throws an IIIFRequestError. """ if (self.quality is None): self.quality_val = self.default_...
[ "def", "parse_quality", "(", "self", ")", ":", "if", "(", "self", ".", "quality", "is", "None", ")", ":", "self", ".", "quality_val", "=", "self", ".", "default_quality", "elif", "(", "self", ".", "quality", "not", "in", "self", ".", "allowed_qualities",...
Check quality paramater. Sets self.quality_val based on simple substitution of 'native' for default. Checks for the three valid values else throws an IIIFRequestError.
[ "Check", "quality", "paramater", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L531-L546
zimeon/iiif
iiif/request.py
IIIFRequest.parse_format
def parse_format(self): """Check format parameter. All formats values listed in the specification are lowercase alphanumeric value commonly used as file extensions. To leave opportunity for extension here just do a limited sanity check on characters and length. """ ...
python
def parse_format(self): """Check format parameter. All formats values listed in the specification are lowercase alphanumeric value commonly used as file extensions. To leave opportunity for extension here just do a limited sanity check on characters and length. """ ...
[ "def", "parse_format", "(", "self", ")", ":", "if", "(", "self", ".", "format", "is", "not", "None", "and", "not", "re", ".", "match", "(", "r'''\\w{1,20}$'''", ",", "self", ".", "format", ")", ")", ":", "raise", "IIIFRequestError", "(", "parameter", "...
Check format parameter. All formats values listed in the specification are lowercase alphanumeric value commonly used as file extensions. To leave opportunity for extension here just do a limited sanity check on characters and length.
[ "Check", "format", "parameter", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L548-L560
zimeon/iiif
iiif/request.py
IIIFRequest.is_scaled_full_image
def is_scaled_full_image(self): """True if this request is for a scaled full image. To be used to determine whether this request should be used in the set of `sizes` specificed in the Image Information. """ return(self.region_full and self.size_wh[0] is not None a...
python
def is_scaled_full_image(self): """True if this request is for a scaled full image. To be used to determine whether this request should be used in the set of `sizes` specificed in the Image Information. """ return(self.region_full and self.size_wh[0] is not None a...
[ "def", "is_scaled_full_image", "(", "self", ")", ":", "return", "(", "self", ".", "region_full", "and", "self", ".", "size_wh", "[", "0", "]", "is", "not", "None", "and", "self", ".", "size_wh", "[", "1", "]", "is", "not", "None", "and", "not", "self...
True if this request is for a scaled full image. To be used to determine whether this request should be used in the set of `sizes` specificed in the Image Information.
[ "True", "if", "this", "request", "is", "for", "a", "scaled", "full", "image", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/request.py#L562-L574
zimeon/iiif
iiif_reference_server.py
get_config
def get_config(base_dir=''): """Get config from defaults, config file and/or parse arguments. Uses configargparse to allow argments to be set from a config file or via command line arguments. base_dir - set a specific base directory for file/path defaults. """ p = configargparse.ArgParser(de...
python
def get_config(base_dir=''): """Get config from defaults, config file and/or parse arguments. Uses configargparse to allow argments to be set from a config file or via command line arguments. base_dir - set a specific base directory for file/path defaults. """ p = configargparse.ArgParser(de...
[ "def", "get_config", "(", "base_dir", "=", "''", ")", ":", "p", "=", "configargparse", ".", "ArgParser", "(", "description", "=", "'IIIF Image API Reference Service'", ",", "default_config_files", "=", "[", "os", ".", "path", ".", "join", "(", "base_dir", ",",...
Get config from defaults, config file and/or parse arguments. Uses configargparse to allow argments to be set from a config file or via command line arguments. base_dir - set a specific base directory for file/path defaults.
[ "Get", "config", "from", "defaults", "config", "file", "and", "/", "or", "parse", "arguments", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif_reference_server.py#L21-L56
zimeon/iiif
iiif_reference_server.py
create_reference_server_flask_app
def create_reference_server_flask_app(cfg): """Create referece server Flask application with one or more IIIF handlers.""" # Create Flask app app = Flask(__name__) Flask.secret_key = "SECRET_HERE" app.debug = cfg.debug # Install request handlers client_prefixes = dict() for api_version i...
python
def create_reference_server_flask_app(cfg): """Create referece server Flask application with one or more IIIF handlers.""" # Create Flask app app = Flask(__name__) Flask.secret_key = "SECRET_HERE" app.debug = cfg.debug # Install request handlers client_prefixes = dict() for api_version i...
[ "def", "create_reference_server_flask_app", "(", "cfg", ")", ":", "# Create Flask app", "app", "=", "Flask", "(", "__name__", ")", "Flask", ".", "secret_key", "=", "\"SECRET_HERE\"", "app", ".", "debug", "=", "cfg", ".", "debug", "# Install request handlers", "cli...
Create referece server Flask application with one or more IIIF handlers.
[ "Create", "referece", "server", "Flask", "application", "with", "one", "or", "more", "IIIF", "handlers", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif_reference_server.py#L59-L76
zimeon/iiif
iiif/generators/sierpinski_carpet.py
PixelGen.pixel
def pixel(self, x, y, size=None): """Return color for a pixel.""" if (size is None): size = self.sz # Have we go to the smallest element? if (size <= 3): if (_middle(x, y)): return (None) else: return (0, 0, 0) d...
python
def pixel(self, x, y, size=None): """Return color for a pixel.""" if (size is None): size = self.sz # Have we go to the smallest element? if (size <= 3): if (_middle(x, y)): return (None) else: return (0, 0, 0) d...
[ "def", "pixel", "(", "self", ",", "x", ",", "y", ",", "size", "=", "None", ")", ":", "if", "(", "size", "is", "None", ")", ":", "size", "=", "self", ".", "sz", "# Have we go to the smallest element?", "if", "(", "size", "<=", "3", ")", ":", "if", ...
Return color for a pixel.
[ "Return", "color", "for", "a", "pixel", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/generators/sierpinski_carpet.py#L33-L46
zimeon/iiif
iiif/info.py
IIIFInfo.id
def id(self): """id property based on server_and_prefix and identifier.""" id = '' if (self.server_and_prefix is not None and self.server_and_prefix != ''): id += self.server_and_prefix + '/' if (self.identifier is not None): id += self.identifier ...
python
def id(self): """id property based on server_and_prefix and identifier.""" id = '' if (self.server_and_prefix is not None and self.server_and_prefix != ''): id += self.server_and_prefix + '/' if (self.identifier is not None): id += self.identifier ...
[ "def", "id", "(", "self", ")", ":", "id", "=", "''", "if", "(", "self", ".", "server_and_prefix", "is", "not", "None", "and", "self", ".", "server_and_prefix", "!=", "''", ")", ":", "id", "+=", "self", ".", "server_and_prefix", "+", "'/'", "if", "(",...
id property based on server_and_prefix and identifier.
[ "id", "property", "based", "on", "server_and_prefix", "and", "identifier", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L227-L235
zimeon/iiif
iiif/info.py
IIIFInfo.id
def id(self, value): """Split into server_and_prefix and identifier.""" i = value.rfind('/') if (i > 0): self.server_and_prefix = value[:i] self.identifier = value[(i + 1):] elif (i == 0): self.server_and_prefix = '' self.identifier = value...
python
def id(self, value): """Split into server_and_prefix and identifier.""" i = value.rfind('/') if (i > 0): self.server_and_prefix = value[:i] self.identifier = value[(i + 1):] elif (i == 0): self.server_and_prefix = '' self.identifier = value...
[ "def", "id", "(", "self", ",", "value", ")", ":", "i", "=", "value", ".", "rfind", "(", "'/'", ")", "if", "(", "i", ">", "0", ")", ":", "self", ".", "server_and_prefix", "=", "value", "[", ":", "i", "]", "self", ".", "identifier", "=", "value",...
Split into server_and_prefix and identifier.
[ "Split", "into", "server_and_prefix", "and", "identifier", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L238-L249
zimeon/iiif
iiif/info.py
IIIFInfo.set_version_info
def set_version_info(self, api_version=None): """Set up normal values for given api_version. Will use current value of self.api_version if a version number is not specified in the call. Will raise an IIIFInfoError """ if (api_version is None): api_version = self.api_...
python
def set_version_info(self, api_version=None): """Set up normal values for given api_version. Will use current value of self.api_version if a version number is not specified in the call. Will raise an IIIFInfoError """ if (api_version is None): api_version = self.api_...
[ "def", "set_version_info", "(", "self", ",", "api_version", "=", "None", ")", ":", "if", "(", "api_version", "is", "None", ")", ":", "api_version", "=", "self", ".", "api_version", "if", "(", "api_version", "not", "in", "CONF", ")", ":", "raise", "IIIFIn...
Set up normal values for given api_version. Will use current value of self.api_version if a version number is not specified in the call. Will raise an IIIFInfoError
[ "Set", "up", "normal", "values", "for", "given", "api_version", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L251-L267
zimeon/iiif
iiif/info.py
IIIFInfo.compliance
def compliance(self, value): """Set the compliance profile URI.""" if (self.api_version < '2.0'): self.profile = value else: try: self.profile[0] = value except AttributeError: # handle case where profile not initialized as arra...
python
def compliance(self, value): """Set the compliance profile URI.""" if (self.api_version < '2.0'): self.profile = value else: try: self.profile[0] = value except AttributeError: # handle case where profile not initialized as arra...
[ "def", "compliance", "(", "self", ",", "value", ")", ":", "if", "(", "self", ".", "api_version", "<", "'2.0'", ")", ":", "self", ".", "profile", "=", "value", "else", ":", "try", ":", "self", ".", "profile", "[", "0", "]", "=", "value", "except", ...
Set the compliance profile URI.
[ "Set", "the", "compliance", "profile", "URI", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L284-L293
zimeon/iiif
iiif/info.py
IIIFInfo.level
def level(self): """Extract level number from compliance profile URI. Returns integer level number or raises IIIFInfoError """ m = re.match( self.compliance_prefix + r'(\d)' + self.compliance_suffix + r'$', self.compliance) ...
python
def level(self): """Extract level number from compliance profile URI. Returns integer level number or raises IIIFInfoError """ m = re.match( self.compliance_prefix + r'(\d)' + self.compliance_suffix + r'$', self.compliance) ...
[ "def", "level", "(", "self", ")", ":", "m", "=", "re", ".", "match", "(", "self", ".", "compliance_prefix", "+", "r'(\\d)'", "+", "self", ".", "compliance_suffix", "+", "r'$'", ",", "self", ".", "compliance", ")", "if", "(", "m", ")", ":", "return", ...
Extract level number from compliance profile URI. Returns integer level number or raises IIIFInfoError
[ "Extract", "level", "number", "from", "compliance", "profile", "URI", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L296-L310
zimeon/iiif
iiif/info.py
IIIFInfo.level
def level(self, value): """Build profile URI from level. Level should be an integer 0,1,2 """ self.compliance = self.compliance_prefix + \ ("%d" % value) + self.compliance_suffix
python
def level(self, value): """Build profile URI from level. Level should be an integer 0,1,2 """ self.compliance = self.compliance_prefix + \ ("%d" % value) + self.compliance_suffix
[ "def", "level", "(", "self", ",", "value", ")", ":", "self", ".", "compliance", "=", "self", ".", "compliance_prefix", "+", "(", "\"%d\"", "%", "value", ")", "+", "self", ".", "compliance_suffix" ]
Build profile URI from level. Level should be an integer 0,1,2
[ "Build", "profile", "URI", "from", "level", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L313-L319
zimeon/iiif
iiif/info.py
IIIFInfo.add_service
def add_service(self, service): """Add a service description. Handles transition from self.service=None, self.service=dict for a single service, and then self.service=[dict,dict,...] for multiple """ if (self.service is None): self.service = service elif (isi...
python
def add_service(self, service): """Add a service description. Handles transition from self.service=None, self.service=dict for a single service, and then self.service=[dict,dict,...] for multiple """ if (self.service is None): self.service = service elif (isi...
[ "def", "add_service", "(", "self", ",", "service", ")", ":", "if", "(", "self", ".", "service", "is", "None", ")", ":", "self", ".", "service", "=", "service", "elif", "(", "isinstance", "(", "self", ".", "service", ",", "dict", ")", ")", ":", "sel...
Add a service description. Handles transition from self.service=None, self.service=dict for a single service, and then self.service=[dict,dict,...] for multiple
[ "Add", "a", "service", "description", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L391-L402
zimeon/iiif
iiif/info.py
IIIFInfo.validate
def validate(self): """Validate this object as Image API data. Raise IIIFInfoError with helpful message if not valid. """ errors = [] for param in self.required_params: if (not hasattr(self, param) or getattr(self, param) is None): errors.append("miss...
python
def validate(self): """Validate this object as Image API data. Raise IIIFInfoError with helpful message if not valid. """ errors = [] for param in self.required_params: if (not hasattr(self, param) or getattr(self, param) is None): errors.append("miss...
[ "def", "validate", "(", "self", ")", ":", "errors", "=", "[", "]", "for", "param", "in", "self", ".", "required_params", ":", "if", "(", "not", "hasattr", "(", "self", ",", "param", ")", "or", "getattr", "(", "self", ",", "param", ")", "is", "None"...
Validate this object as Image API data. Raise IIIFInfoError with helpful message if not valid.
[ "Validate", "this", "object", "as", "Image", "API", "data", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L417-L428
zimeon/iiif
iiif/info.py
IIIFInfo.as_json
def as_json(self, validate=True): """Return JSON serialization. Will raise IIIFInfoError if insufficient parameters are present to have a valid info.json response (unless validate is False). """ if (validate): self.validate() json_dict = {} if (self.a...
python
def as_json(self, validate=True): """Return JSON serialization. Will raise IIIFInfoError if insufficient parameters are present to have a valid info.json response (unless validate is False). """ if (validate): self.validate() json_dict = {} if (self.a...
[ "def", "as_json", "(", "self", ",", "validate", "=", "True", ")", ":", "if", "(", "validate", ")", ":", "self", ".", "validate", "(", ")", "json_dict", "=", "{", "}", "if", "(", "self", ".", "api_version", ">", "'1.0'", ")", ":", "json_dict", "[", ...
Return JSON serialization. Will raise IIIFInfoError if insufficient parameters are present to have a valid info.json response (unless validate is False).
[ "Return", "JSON", "serialization", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L430-L471
zimeon/iiif
iiif/info.py
IIIFInfo.read
def read(self, fh, api_version=None): """Read info.json from file like object. Parameters: fh -- file like object supporting fh.read() api_version -- IIIF Image API version expected If api_version is set then the parsing will assume this API version, else the version wi...
python
def read(self, fh, api_version=None): """Read info.json from file like object. Parameters: fh -- file like object supporting fh.read() api_version -- IIIF Image API version expected If api_version is set then the parsing will assume this API version, else the version wi...
[ "def", "read", "(", "self", ",", "fh", ",", "api_version", "=", "None", ")", ":", "j", "=", "json", ".", "load", "(", "fh", ")", "#", "# @context and API version", "self", ".", "context", "=", "None", "if", "(", "api_version", "==", "'1.0'", ")", ":"...
Read info.json from file like object. Parameters: fh -- file like object supporting fh.read() api_version -- IIIF Image API version expected If api_version is set then the parsing will assume this API version, else the version will be determined from the incoming data. NOTE tha...
[ "Read", "info", ".", "json", "from", "file", "like", "object", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/info.py#L473-L546
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.set_max_image_pixels
def set_max_image_pixels(self, pixels): """Set PIL limit on pixel size of images to load if non-zero. WARNING: This is a global setting in PIL, it is not local to this manipulator instance! Setting a value here will not only set the given limit but also convert the PIL "Decompr...
python
def set_max_image_pixels(self, pixels): """Set PIL limit on pixel size of images to load if non-zero. WARNING: This is a global setting in PIL, it is not local to this manipulator instance! Setting a value here will not only set the given limit but also convert the PIL "Decompr...
[ "def", "set_max_image_pixels", "(", "self", ",", "pixels", ")", ":", "if", "(", "pixels", ")", ":", "Image", ".", "MAX_IMAGE_PIXELS", "=", "pixels", "Image", ".", "warnings", ".", "simplefilter", "(", "'error'", ",", "Image", ".", "DecompressionBombWarning", ...
Set PIL limit on pixel size of images to load if non-zero. WARNING: This is a global setting in PIL, it is not local to this manipulator instance! Setting a value here will not only set the given limit but also convert the PIL "DecompressionBombWarning" into an error. Thus sett...
[ "Set", "PIL", "limit", "on", "pixel", "size", "of", "images", "to", "load", "if", "non", "-", "zero", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L42-L57
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.do_first
def do_first(self): """Create PIL object from input image file. Image location must be in self.srcfile. Will result in self.width and self.height being set to the image dimensions. Will raise an IIIFError on failure to load the image """ self.logger.debug("do_first: src...
python
def do_first(self): """Create PIL object from input image file. Image location must be in self.srcfile. Will result in self.width and self.height being set to the image dimensions. Will raise an IIIFError on failure to load the image """ self.logger.debug("do_first: src...
[ "def", "do_first", "(", "self", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"do_first: src=%s\"", "%", "(", "self", ".", "srcfile", ")", ")", "try", ":", "self", ".", "image", "=", "Image", ".", "open", "(", "self", ".", "srcfile", ")", "...
Create PIL object from input image file. Image location must be in self.srcfile. Will result in self.width and self.height being set to the image dimensions. Will raise an IIIFError on failure to load the image
[ "Create", "PIL", "object", "from", "input", "image", "file", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L59-L78
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.do_region
def do_region(self, x, y, w, h): """Apply region selection.""" if (x is None): self.logger.debug("region: full (nop)") else: self.logger.debug("region: (%d,%d,%d,%d)" % (x, y, w, h)) self.image = self.image.crop((x, y, x + w, y + h)) self.width = w...
python
def do_region(self, x, y, w, h): """Apply region selection.""" if (x is None): self.logger.debug("region: full (nop)") else: self.logger.debug("region: (%d,%d,%d,%d)" % (x, y, w, h)) self.image = self.image.crop((x, y, x + w, y + h)) self.width = w...
[ "def", "do_region", "(", "self", ",", "x", ",", "y", ",", "w", ",", "h", ")", ":", "if", "(", "x", "is", "None", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"region: full (nop)\"", ")", "else", ":", "self", ".", "logger", ".", "debug", ...
Apply region selection.
[ "Apply", "region", "selection", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L80-L88
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.do_size
def do_size(self, w, h): """Apply size scaling.""" if (w is None): self.logger.debug("size: no scaling (nop)") else: self.logger.debug("size: scaling to (%d,%d)" % (w, h)) self.image = self.image.resize((w, h)) self.width = w self.heigh...
python
def do_size(self, w, h): """Apply size scaling.""" if (w is None): self.logger.debug("size: no scaling (nop)") else: self.logger.debug("size: scaling to (%d,%d)" % (w, h)) self.image = self.image.resize((w, h)) self.width = w self.heigh...
[ "def", "do_size", "(", "self", ",", "w", ",", "h", ")", ":", "if", "(", "w", "is", "None", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"size: no scaling (nop)\"", ")", "else", ":", "self", ".", "logger", ".", "debug", "(", "\"size: scaling ...
Apply size scaling.
[ "Apply", "size", "scaling", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L90-L98
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.do_rotation
def do_rotation(self, mirror, rot): """Apply rotation and/or mirroring.""" if (not mirror and rot == 0.0): self.logger.debug("rotation: no rotation (nop)") else: # FIXME - with PIL one can use the transpose() method to do 90deg # FIXME - rotations as well as m...
python
def do_rotation(self, mirror, rot): """Apply rotation and/or mirroring.""" if (not mirror and rot == 0.0): self.logger.debug("rotation: no rotation (nop)") else: # FIXME - with PIL one can use the transpose() method to do 90deg # FIXME - rotations as well as m...
[ "def", "do_rotation", "(", "self", ",", "mirror", ",", "rot", ")", ":", "if", "(", "not", "mirror", "and", "rot", "==", "0.0", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"rotation: no rotation (nop)\"", ")", "else", ":", "# FIXME - with PIL one ...
Apply rotation and/or mirroring.
[ "Apply", "rotation", "and", "/", "or", "mirroring", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L100-L113
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.do_quality
def do_quality(self, quality): """Apply value of quality parameter. For PIL docs see <http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.convert> """ if (quality == 'grey' or quality == 'gray'): # Checking for 1.1 gray or 20.0 grey elsewhere...
python
def do_quality(self, quality): """Apply value of quality parameter. For PIL docs see <http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.convert> """ if (quality == 'grey' or quality == 'gray'): # Checking for 1.1 gray or 20.0 grey elsewhere...
[ "def", "do_quality", "(", "self", ",", "quality", ")", ":", "if", "(", "quality", "==", "'grey'", "or", "quality", "==", "'gray'", ")", ":", "# Checking for 1.1 gray or 20.0 grey elsewhere", "self", ".", "logger", ".", "debug", "(", "\"quality: converting to gray\...
Apply value of quality parameter. For PIL docs see <http://pillow.readthedocs.org/en/latest/reference/Image.html#PIL.Image.Image.convert>
[ "Apply", "value", "of", "quality", "parameter", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L115-L144
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.do_format
def do_format(self, format): """Apply format selection. Assume that for tiling applications we want jpg so return that unless an explicit format is requested. """ fmt = ('jpg' if (format is None) else format) if (fmt == 'png'): self.logger.debug("format: png"...
python
def do_format(self, format): """Apply format selection. Assume that for tiling applications we want jpg so return that unless an explicit format is requested. """ fmt = ('jpg' if (format is None) else format) if (fmt == 'png'): self.logger.debug("format: png"...
[ "def", "do_format", "(", "self", ",", "format", ")", ":", "fmt", "=", "(", "'jpg'", "if", "(", "format", "is", "None", ")", "else", "format", ")", "if", "(", "fmt", "==", "'png'", ")", ":", "self", ".", "logger", ".", "debug", "(", "\"format: png\"...
Apply format selection. Assume that for tiling applications we want jpg so return that unless an explicit format is requested.
[ "Apply", "format", "selection", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L146-L179
zimeon/iiif
iiif/manipulator_pil.py
IIIFManipulatorPIL.cleanup
def cleanup(self): """Cleanup: ensure image closed and remove temporary output file.""" if self.image: try: self.image.close() except Exception: pass if (self.outtmp is not None): try: os.unlink(self.outtmp) ...
python
def cleanup(self): """Cleanup: ensure image closed and remove temporary output file.""" if self.image: try: self.image.close() except Exception: pass if (self.outtmp is not None): try: os.unlink(self.outtmp) ...
[ "def", "cleanup", "(", "self", ")", ":", "if", "self", ".", "image", ":", "try", ":", "self", ".", "image", ".", "close", "(", ")", "except", "Exception", ":", "pass", "if", "(", "self", ".", "outtmp", "is", "not", "None", ")", ":", "try", ":", ...
Cleanup: ensure image closed and remove temporary output file.
[ "Cleanup", ":", "ensure", "image", "closed", "and", "remove", "temporary", "output", "file", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/manipulator_pil.py#L181-L193
zimeon/iiif
iiif/generators/check.py
PixelGen.pixel
def pixel(self, x, y, size=None, red=0): """Return color for a pixel. The paremeter size is used to recursively follow down to smaller and smaller middle squares (number 5). The paremeter red is used to shade from black to red going toward the middle of the figure. """ i...
python
def pixel(self, x, y, size=None, red=0): """Return color for a pixel. The paremeter size is used to recursively follow down to smaller and smaller middle squares (number 5). The paremeter red is used to shade from black to red going toward the middle of the figure. """ i...
[ "def", "pixel", "(", "self", ",", "x", ",", "y", ",", "size", "=", "None", ",", "red", "=", "0", ")", ":", "if", "(", "size", "is", "None", ")", ":", "size", "=", "self", ".", "sz", "# Have we go to the smallest element?", "if", "(", "size", "<=", ...
Return color for a pixel. The paremeter size is used to recursively follow down to smaller and smaller middle squares (number 5). The paremeter red is used to shade from black to red going toward the middle of the figure.
[ "Return", "color", "for", "a", "pixel", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/generators/check.py#L31-L55
zimeon/iiif
iiif/flask_utils.py
html_page
def html_page(title="Page Title", body=""): """Create HTML page as string.""" html = "<html>\n<head><title>%s</title></head>\n<body>\n" % (title) html += "<h1>%s</h1>\n" % (title) html += body html += "</body>\n</html>\n" return html
python
def html_page(title="Page Title", body=""): """Create HTML page as string.""" html = "<html>\n<head><title>%s</title></head>\n<body>\n" % (title) html += "<h1>%s</h1>\n" % (title) html += body html += "</body>\n</html>\n" return html
[ "def", "html_page", "(", "title", "=", "\"Page Title\"", ",", "body", "=", "\"\"", ")", ":", "html", "=", "\"<html>\\n<head><title>%s</title></head>\\n<body>\\n\"", "%", "(", "title", ")", "html", "+=", "\"<h1>%s</h1>\\n\"", "%", "(", "title", ")", "html", "+=",...
Create HTML page as string.
[ "Create", "HTML", "page", "as", "string", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L49-L55
zimeon/iiif
iiif/flask_utils.py
top_level_index_page
def top_level_index_page(config): """HTML top-level index page which provides a link to each handler.""" title = "IIIF Test Server on %s" % (config.host) body = "<ul>\n" for prefix in sorted(config.prefixes.keys()): body += '<li><a href="/%s">%s</a></li>\n' % (prefix, prefix) body += "</ul>\...
python
def top_level_index_page(config): """HTML top-level index page which provides a link to each handler.""" title = "IIIF Test Server on %s" % (config.host) body = "<ul>\n" for prefix in sorted(config.prefixes.keys()): body += '<li><a href="/%s">%s</a></li>\n' % (prefix, prefix) body += "</ul>\...
[ "def", "top_level_index_page", "(", "config", ")", ":", "title", "=", "\"IIIF Test Server on %s\"", "%", "(", "config", ".", "host", ")", "body", "=", "\"<ul>\\n\"", "for", "prefix", "in", "sorted", "(", "config", ".", "prefixes", ".", "keys", "(", ")", ")...
HTML top-level index page which provides a link to each handler.
[ "HTML", "top", "-", "level", "index", "page", "which", "provides", "a", "link", "to", "each", "handler", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L58-L65
zimeon/iiif
iiif/flask_utils.py
identifiers
def identifiers(config): """Show list of identifiers for this prefix. Handles both the case of local file based identifiers and also image generators. Arguments: config - configuration object in which: config.klass_name - 'gen' if a generator function config.generator_d...
python
def identifiers(config): """Show list of identifiers for this prefix. Handles both the case of local file based identifiers and also image generators. Arguments: config - configuration object in which: config.klass_name - 'gen' if a generator function config.generator_d...
[ "def", "identifiers", "(", "config", ")", ":", "ids", "=", "[", "]", "if", "(", "config", ".", "klass_name", "==", "'gen'", ")", ":", "for", "generator", "in", "os", ".", "listdir", "(", "config", ".", "generator_dir", ")", ":", "if", "(", "generator...
Show list of identifiers for this prefix. Handles both the case of local file based identifiers and also image generators. Arguments: config - configuration object in which: config.klass_name - 'gen' if a generator function config.generator_dir - directory for generator cod...
[ "Show", "list", "of", "identifiers", "for", "this", "prefix", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L68-L98
zimeon/iiif
iiif/flask_utils.py
prefix_index_page
def prefix_index_page(config): """HTML index page for a specific prefix. The prefix seen by the client is obtained from config.client_prefix as opposed to the local server prefix in config.prefix. Also uses the identifiers(config) function to get identifiers available. Arguments: config - ...
python
def prefix_index_page(config): """HTML index page for a specific prefix. The prefix seen by the client is obtained from config.client_prefix as opposed to the local server prefix in config.prefix. Also uses the identifiers(config) function to get identifiers available. Arguments: config - ...
[ "def", "prefix_index_page", "(", "config", ")", ":", "title", "=", "\"IIIF Image API services under %s\"", "%", "(", "config", ".", "client_prefix", ")", "# details of this prefix handler", "body", "=", "'<p>\\n'", "body", "+=", "'host = %s<br/>\\n'", "%", "(", "confi...
HTML index page for a specific prefix. The prefix seen by the client is obtained from config.client_prefix as opposed to the local server prefix in config.prefix. Also uses the identifiers(config) function to get identifiers available. Arguments: config - configuration object in which: ...
[ "HTML", "index", "page", "for", "a", "specific", "prefix", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L101-L152
zimeon/iiif
iiif/flask_utils.py
host_port_prefix
def host_port_prefix(host, port, prefix): """Return URI composed of scheme, server, port, and prefix.""" uri = "http://" + host if (port != 80): uri += ':' + str(port) if (prefix): uri += '/' + prefix return uri
python
def host_port_prefix(host, port, prefix): """Return URI composed of scheme, server, port, and prefix.""" uri = "http://" + host if (port != 80): uri += ':' + str(port) if (prefix): uri += '/' + prefix return uri
[ "def", "host_port_prefix", "(", "host", ",", "port", ",", "prefix", ")", ":", "uri", "=", "\"http://\"", "+", "host", "if", "(", "port", "!=", "80", ")", ":", "uri", "+=", "':'", "+", "str", "(", "port", ")", "if", "(", "prefix", ")", ":", "uri",...
Return URI composed of scheme, server, port, and prefix.
[ "Return", "URI", "composed", "of", "scheme", "server", "port", "and", "prefix", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L155-L162
zimeon/iiif
iiif/flask_utils.py
osd_page_handler
def osd_page_handler(config=None, identifier=None, prefix=None, **args): """Flask handler to produce HTML response for OpenSeadragon view of identifier. Arguments: config - Config object for this IIIF handler identifier - identifier of image/generator prefix - path prefix **args...
python
def osd_page_handler(config=None, identifier=None, prefix=None, **args): """Flask handler to produce HTML response for OpenSeadragon view of identifier. Arguments: config - Config object for this IIIF handler identifier - identifier of image/generator prefix - path prefix **args...
[ "def", "osd_page_handler", "(", "config", "=", "None", ",", "identifier", "=", "None", ",", "prefix", "=", "None", ",", "*", "*", "args", ")", ":", "template_dir", "=", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "dirname", "(", "_...
Flask handler to produce HTML response for OpenSeadragon view of identifier. Arguments: config - Config object for this IIIF handler identifier - identifier of image/generator prefix - path prefix **args - other aguments ignored
[ "Flask", "handler", "to", "produce", "HTML", "response", "for", "OpenSeadragon", "view", "of", "identifier", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L168-L189
zimeon/iiif
iiif/flask_utils.py
iiif_info_handler
def iiif_info_handler(prefix=None, identifier=None, config=None, klass=None, auth=None, **args): """Handler for IIIF Image Information requests.""" if (not auth or degraded_request(identifier) or auth.info_authz()): # go ahead with request as made if (auth): log...
python
def iiif_info_handler(prefix=None, identifier=None, config=None, klass=None, auth=None, **args): """Handler for IIIF Image Information requests.""" if (not auth or degraded_request(identifier) or auth.info_authz()): # go ahead with request as made if (auth): log...
[ "def", "iiif_info_handler", "(", "prefix", "=", "None", ",", "identifier", "=", "None", ",", "config", "=", "None", ",", "klass", "=", "None", ",", "auth", "=", "None", ",", "*", "*", "args", ")", ":", "if", "(", "not", "auth", "or", "degraded_reques...
Handler for IIIF Image Information requests.
[ "Handler", "for", "IIIF", "Image", "Information", "requests", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L384-L404
zimeon/iiif
iiif/flask_utils.py
iiif_image_handler
def iiif_image_handler(prefix=None, identifier=None, path=None, config=None, klass=None, auth=None, **args): """Handler for IIIF Image Requests. Behaviour for case of a non-authn or non-authz case is to return 403. """ if (not auth or degraded_request(identifier) or auth.imag...
python
def iiif_image_handler(prefix=None, identifier=None, path=None, config=None, klass=None, auth=None, **args): """Handler for IIIF Image Requests. Behaviour for case of a non-authn or non-authz case is to return 403. """ if (not auth or degraded_request(identifier) or auth.imag...
[ "def", "iiif_image_handler", "(", "prefix", "=", "None", ",", "identifier", "=", "None", ",", "path", "=", "None", ",", "config", "=", "None", ",", "klass", "=", "None", ",", "auth", "=", "None", ",", "*", "*", "args", ")", ":", "if", "(", "not", ...
Handler for IIIF Image Requests. Behaviour for case of a non-authn or non-authz case is to return 403.
[ "Handler", "for", "IIIF", "Image", "Requests", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L408-L431
zimeon/iiif
iiif/flask_utils.py
parse_accept_header
def parse_accept_header(accept): """Parse an HTTP Accept header. Parses *accept*, returning a list with pairs of (media_type, q_value), ordered by q values. Adapted from <https://djangosnippets.org/snippets/1042/> """ result = [] for media_range in accept.split(","): parts = media_...
python
def parse_accept_header(accept): """Parse an HTTP Accept header. Parses *accept*, returning a list with pairs of (media_type, q_value), ordered by q values. Adapted from <https://djangosnippets.org/snippets/1042/> """ result = [] for media_range in accept.split(","): parts = media_...
[ "def", "parse_accept_header", "(", "accept", ")", ":", "result", "=", "[", "]", "for", "media_range", "in", "accept", ".", "split", "(", "\",\"", ")", ":", "parts", "=", "media_range", ".", "split", "(", "\";\"", ")", "media_type", "=", "parts", ".", "...
Parse an HTTP Accept header. Parses *accept*, returning a list with pairs of (media_type, q_value), ordered by q values. Adapted from <https://djangosnippets.org/snippets/1042/>
[ "Parse", "an", "HTTP", "Accept", "header", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L450-L472
zimeon/iiif
iiif/flask_utils.py
parse_authorization_header
def parse_authorization_header(value): """Parse the Authenticate header. Returns nothing on failure, opts hash on success with type='basic' or 'digest' and other params. <http://nullege.com/codes/search/werkzeug.http.parse_authorization_header> <http://stackoverflow.com/questions/1349367/parse-an-...
python
def parse_authorization_header(value): """Parse the Authenticate header. Returns nothing on failure, opts hash on success with type='basic' or 'digest' and other params. <http://nullege.com/codes/search/werkzeug.http.parse_authorization_header> <http://stackoverflow.com/questions/1349367/parse-an-...
[ "def", "parse_authorization_header", "(", "value", ")", ":", "try", ":", "(", "auth_type", ",", "auth_info", ")", "=", "value", ".", "split", "(", "' '", ",", "1", ")", "auth_type", "=", "auth_type", ".", "lower", "(", ")", "except", "ValueError", ":", ...
Parse the Authenticate header. Returns nothing on failure, opts hash on success with type='basic' or 'digest' and other params. <http://nullege.com/codes/search/werkzeug.http.parse_authorization_header> <http://stackoverflow.com/questions/1349367/parse-an-http-request-authorization-header-with-python>...
[ "Parse", "the", "Authenticate", "header", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L475-L513
zimeon/iiif
iiif/flask_utils.py
do_conneg
def do_conneg(accept, supported): """Parse accept header and look for preferred type in supported list. Arguments: accept - HTTP Accept header supported - list of MIME type supported by the server Returns: supported MIME type with highest q value in request, else None. FIXME -...
python
def do_conneg(accept, supported): """Parse accept header and look for preferred type in supported list. Arguments: accept - HTTP Accept header supported - list of MIME type supported by the server Returns: supported MIME type with highest q value in request, else None. FIXME -...
[ "def", "do_conneg", "(", "accept", ",", "supported", ")", ":", "for", "result", "in", "parse_accept_header", "(", "accept", ")", ":", "mime_type", "=", "result", "[", "0", "]", "if", "(", "mime_type", "in", "supported", ")", ":", "return", "mime_type", "...
Parse accept header and look for preferred type in supported list. Arguments: accept - HTTP Accept header supported - list of MIME type supported by the server Returns: supported MIME type with highest q value in request, else None. FIXME - Should replace this with negotiator2
[ "Parse", "accept", "header", "and", "look", "for", "preferred", "type", "in", "supported", "list", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L516-L532
zimeon/iiif
iiif/flask_utils.py
setup_auth_paths
def setup_auth_paths(app, auth, prefix, params): """Add URL rules for auth paths.""" base = urljoin('/', prefix + '/') # Must end in slash app.add_url_rule(base + 'login', prefix + 'login_handler', auth.login_handler, defaults=params) app.add_url_rule(base + 'logout', prefix + 'log...
python
def setup_auth_paths(app, auth, prefix, params): """Add URL rules for auth paths.""" base = urljoin('/', prefix + '/') # Must end in slash app.add_url_rule(base + 'login', prefix + 'login_handler', auth.login_handler, defaults=params) app.add_url_rule(base + 'logout', prefix + 'log...
[ "def", "setup_auth_paths", "(", "app", ",", "auth", ",", "prefix", ",", "params", ")", ":", "base", "=", "urljoin", "(", "'/'", ",", "prefix", "+", "'/'", ")", "# Must end in slash", "app", ".", "add_url_rule", "(", "base", "+", "'login'", ",", "prefix",...
Add URL rules for auth paths.
[ "Add", "URL", "rules", "for", "auth", "paths", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L537-L551
zimeon/iiif
iiif/flask_utils.py
make_prefix
def make_prefix(api_version, manipulator, auth_type): """Make prefix string based on configuration parameters.""" prefix = "%s_%s" % (api_version, manipulator) if (auth_type and auth_type != 'none'): prefix += '_' + auth_type return prefix
python
def make_prefix(api_version, manipulator, auth_type): """Make prefix string based on configuration parameters.""" prefix = "%s_%s" % (api_version, manipulator) if (auth_type and auth_type != 'none'): prefix += '_' + auth_type return prefix
[ "def", "make_prefix", "(", "api_version", ",", "manipulator", ",", "auth_type", ")", ":", "prefix", "=", "\"%s_%s\"", "%", "(", "api_version", ",", "manipulator", ")", "if", "(", "auth_type", "and", "auth_type", "!=", "'none'", ")", ":", "prefix", "+=", "'...
Make prefix string based on configuration parameters.
[ "Make", "prefix", "string", "based", "on", "configuration", "parameters", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L554-L559
zimeon/iiif
iiif/flask_utils.py
split_comma_argument
def split_comma_argument(comma_sep_str): """Split a comma separated option into a list.""" terms = [] for term in comma_sep_str.split(','): if term: terms.append(term) return terms
python
def split_comma_argument(comma_sep_str): """Split a comma separated option into a list.""" terms = [] for term in comma_sep_str.split(','): if term: terms.append(term) return terms
[ "def", "split_comma_argument", "(", "comma_sep_str", ")", ":", "terms", "=", "[", "]", "for", "term", "in", "comma_sep_str", ".", "split", "(", "','", ")", ":", "if", "term", ":", "terms", ".", "append", "(", "term", ")", "return", "terms" ]
Split a comma separated option into a list.
[ "Split", "a", "comma", "separated", "option", "into", "a", "list", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L562-L568
zimeon/iiif
iiif/flask_utils.py
add_shared_configs
def add_shared_configs(p, base_dir=''): """Add configargparser/argparse configs for shared argument. Arguments: p - configargparse.ArgParser object base_dir - base directory for file/path defaults. """ p.add('--host', default='localhost', help="Service host") p.add('--port...
python
def add_shared_configs(p, base_dir=''): """Add configargparser/argparse configs for shared argument. Arguments: p - configargparse.ArgParser object base_dir - base directory for file/path defaults. """ p.add('--host', default='localhost', help="Service host") p.add('--port...
[ "def", "add_shared_configs", "(", "p", ",", "base_dir", "=", "''", ")", ":", "p", ".", "add", "(", "'--host'", ",", "default", "=", "'localhost'", ",", "help", "=", "\"Service host\"", ")", "p", ".", "add", "(", "'--port'", ",", "'-p'", ",", "type", ...
Add configargparser/argparse configs for shared argument. Arguments: p - configargparse.ArgParser object base_dir - base directory for file/path defaults.
[ "Add", "configargparser", "/", "argparse", "configs", "for", "shared", "argument", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L571-L611
zimeon/iiif
iiif/flask_utils.py
add_handler
def add_handler(app, config): """Add a single handler to the app. Adds one IIIF Image API handler to app, with config from config. Arguments: app - Flask app config - Configuration object in which: config.prefix - String path prefix for this handler config.client_pr...
python
def add_handler(app, config): """Add a single handler to the app. Adds one IIIF Image API handler to app, with config from config. Arguments: app - Flask app config - Configuration object in which: config.prefix - String path prefix for this handler config.client_pr...
[ "def", "add_handler", "(", "app", ",", "config", ")", ":", "auth", "=", "None", "if", "(", "config", ".", "auth_type", "is", "None", "or", "config", ".", "auth_type", "==", "'none'", ")", ":", "pass", "elif", "(", "config", ".", "auth_type", "==", "'...
Add a single handler to the app. Adds one IIIF Image API handler to app, with config from config. Arguments: app - Flask app config - Configuration object in which: config.prefix - String path prefix for this handler config.client_prefix - String path prefix seen by cli...
[ "Add", "a", "single", "handler", "to", "the", "app", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L614-L702
zimeon/iiif
iiif/flask_utils.py
serve_static
def serve_static(filename=None, prefix='', basedir=None): """Handler for static files: server filename in basedir/prefix. If not specified then basedir defaults to the local third_party directory. """ if not basedir: basedir = os.path.join(os.path.dirname(__file__), 'third_party') retur...
python
def serve_static(filename=None, prefix='', basedir=None): """Handler for static files: server filename in basedir/prefix. If not specified then basedir defaults to the local third_party directory. """ if not basedir: basedir = os.path.join(os.path.dirname(__file__), 'third_party') retur...
[ "def", "serve_static", "(", "filename", "=", "None", ",", "prefix", "=", "''", ",", "basedir", "=", "None", ")", ":", "if", "not", "basedir", ":", "basedir", "=", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "dirname", "(", "__file_...
Handler for static files: server filename in basedir/prefix. If not specified then basedir defaults to the local third_party directory.
[ "Handler", "for", "static", "files", ":", "server", "filename", "in", "basedir", "/", "prefix", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L705-L713
zimeon/iiif
iiif/flask_utils.py
write_pid_file
def write_pid_file(): """Write a file with the PID of this server instance. Call when setting up a command line testserver. """ pidfile = os.path.basename(sys.argv[0])[:-3] + '.pid' # strip .py, add .pid with open(pidfile, 'w') as fh: fh.write("%d\n" % os.getpid()) fh.close()
python
def write_pid_file(): """Write a file with the PID of this server instance. Call when setting up a command line testserver. """ pidfile = os.path.basename(sys.argv[0])[:-3] + '.pid' # strip .py, add .pid with open(pidfile, 'w') as fh: fh.write("%d\n" % os.getpid()) fh.close()
[ "def", "write_pid_file", "(", ")", ":", "pidfile", "=", "os", ".", "path", ".", "basename", "(", "sys", ".", "argv", "[", "0", "]", ")", "[", ":", "-", "3", "]", "+", "'.pid'", "# strip .py, add .pid", "with", "open", "(", "pidfile", ",", "'w'", ")...
Write a file with the PID of this server instance. Call when setting up a command line testserver.
[ "Write", "a", "file", "with", "the", "PID", "of", "this", "server", "instance", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L739-L747
zimeon/iiif
iiif/flask_utils.py
setup_app
def setup_app(app, cfg): """Setup Flask app and handle reverse proxy setup if configured. Arguments: app - Flask application cfg - configuration data """ # Set up app_host and app_port in case that we are running # under reverse proxy setup, otherwise they default to # config.ho...
python
def setup_app(app, cfg): """Setup Flask app and handle reverse proxy setup if configured. Arguments: app - Flask application cfg - configuration data """ # Set up app_host and app_port in case that we are running # under reverse proxy setup, otherwise they default to # config.ho...
[ "def", "setup_app", "(", "app", ",", "cfg", ")", ":", "# Set up app_host and app_port in case that we are running", "# under reverse proxy setup, otherwise they default to", "# config.host and config.port.", "if", "(", "cfg", ".", "app_host", "and", "cfg", ".", "app_port", ")...
Setup Flask app and handle reverse proxy setup if configured. Arguments: app - Flask application cfg - configuration data
[ "Setup", "Flask", "app", "and", "handle", "reverse", "proxy", "setup", "if", "configured", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L750-L770
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.server_and_prefix
def server_and_prefix(self): """Server and prefix from config.""" return(host_port_prefix(self.config.host, self.config.port, self.prefix))
python
def server_and_prefix(self): """Server and prefix from config.""" return(host_port_prefix(self.config.host, self.config.port, self.prefix))
[ "def", "server_and_prefix", "(", "self", ")", ":", "return", "(", "host_port_prefix", "(", "self", ".", "config", ".", "host", ",", "self", ".", "config", ".", "port", ",", "self", ".", "prefix", ")", ")" ]
Server and prefix from config.
[ "Server", "and", "prefix", "from", "config", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L231-L233
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.json_mime_type
def json_mime_type(self): """Return the MIME type for a JSON response. For version 2.0+ the server must return json-ld MIME type if that format is requested. Implement for 1.1 also. http://iiif.io/api/image/2.1/#information-request """ mime_type = "application/json" ...
python
def json_mime_type(self): """Return the MIME type for a JSON response. For version 2.0+ the server must return json-ld MIME type if that format is requested. Implement for 1.1 also. http://iiif.io/api/image/2.1/#information-request """ mime_type = "application/json" ...
[ "def", "json_mime_type", "(", "self", ")", ":", "mime_type", "=", "\"application/json\"", "if", "(", "self", ".", "api_version", ">=", "'1.1'", "and", "'Accept'", "in", "request", ".", "headers", ")", ":", "mime_type", "=", "do_conneg", "(", "request", ".", ...
Return the MIME type for a JSON response. For version 2.0+ the server must return json-ld MIME type if that format is requested. Implement for 1.1 also. http://iiif.io/api/image/2.1/#information-request
[ "Return", "the", "MIME", "type", "for", "a", "JSON", "response", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L236-L247
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.file
def file(self): """Filename property for the source image for the current identifier.""" file = None if (self.config.klass_name == 'gen'): for ext in ['.py']: file = os.path.join( self.config.generator_dir, self.identifier + ext) if...
python
def file(self): """Filename property for the source image for the current identifier.""" file = None if (self.config.klass_name == 'gen'): for ext in ['.py']: file = os.path.join( self.config.generator_dir, self.identifier + ext) if...
[ "def", "file", "(", "self", ")", ":", "file", "=", "None", "if", "(", "self", ".", "config", ".", "klass_name", "==", "'gen'", ")", ":", "for", "ext", "in", "[", "'.py'", "]", ":", "file", "=", "os", ".", "path", ".", "join", "(", "self", ".", ...
Filename property for the source image for the current identifier.
[ "Filename", "property", "for", "the", "source", "image", "for", "the", "current", "identifier", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L250-L268
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.add_compliance_header
def add_compliance_header(self): """Add IIIF Compliance level header to response.""" if (self.manipulator.compliance_uri is not None): self.headers['Link'] = '<' + \ self.manipulator.compliance_uri + '>;rel="profile"'
python
def add_compliance_header(self): """Add IIIF Compliance level header to response.""" if (self.manipulator.compliance_uri is not None): self.headers['Link'] = '<' + \ self.manipulator.compliance_uri + '>;rel="profile"'
[ "def", "add_compliance_header", "(", "self", ")", ":", "if", "(", "self", ".", "manipulator", ".", "compliance_uri", "is", "not", "None", ")", ":", "self", ".", "headers", "[", "'Link'", "]", "=", "'<'", "+", "self", ".", "manipulator", ".", "compliance_...
Add IIIF Compliance level header to response.
[ "Add", "IIIF", "Compliance", "level", "header", "to", "response", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L270-L274
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.make_response
def make_response(self, content, code=200, headers=None): """Wrapper around Flask.make_response which also adds any local headers.""" if headers: for header in headers: self.headers[header] = headers[header] return make_response(content, code, self.headers)
python
def make_response(self, content, code=200, headers=None): """Wrapper around Flask.make_response which also adds any local headers.""" if headers: for header in headers: self.headers[header] = headers[header] return make_response(content, code, self.headers)
[ "def", "make_response", "(", "self", ",", "content", ",", "code", "=", "200", ",", "headers", "=", "None", ")", ":", "if", "headers", ":", "for", "header", "in", "headers", ":", "self", ".", "headers", "[", "header", "]", "=", "headers", "[", "header...
Wrapper around Flask.make_response which also adds any local headers.
[ "Wrapper", "around", "Flask", ".", "make_response", "which", "also", "adds", "any", "local", "headers", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L276-L281
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.image_information_response
def image_information_response(self): """Parse image information request and create response.""" dr = degraded_request(self.identifier) if (dr): self.logger.info("image_information: degraded %s -> %s" % (self.identifier, dr)) self.degraded = s...
python
def image_information_response(self): """Parse image information request and create response.""" dr = degraded_request(self.identifier) if (dr): self.logger.info("image_information: degraded %s -> %s" % (self.identifier, dr)) self.degraded = s...
[ "def", "image_information_response", "(", "self", ")", ":", "dr", "=", "degraded_request", "(", "self", ".", "identifier", ")", "if", "(", "dr", ")", ":", "self", ".", "logger", ".", "info", "(", "\"image_information: degraded %s -> %s\"", "%", "(", "self", ...
Parse image information request and create response.
[ "Parse", "image", "information", "request", "and", "create", "response", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L283-L320
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.image_request_response
def image_request_response(self, path): """Parse image request and create response.""" # Parse the request in path if (len(path) > 1024): raise IIIFError(code=414, text="URI Too Long: Max 1024 chars, got %d\n" % len(path)) try: self.iii...
python
def image_request_response(self, path): """Parse image request and create response.""" # Parse the request in path if (len(path) > 1024): raise IIIFError(code=414, text="URI Too Long: Max 1024 chars, got %d\n" % len(path)) try: self.iii...
[ "def", "image_request_response", "(", "self", ",", "path", ")", ":", "# Parse the request in path", "if", "(", "len", "(", "path", ")", ">", "1024", ")", ":", "raise", "IIIFError", "(", "code", "=", "414", ",", "text", "=", "\"URI Too Long: Max 1024 chars, got...
Parse image request and create response.
[ "Parse", "image", "request", "and", "create", "response", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L322-L373
zimeon/iiif
iiif/flask_utils.py
IIIFHandler.error_response
def error_response(self, e): """Make response for an IIIFError e. Also add compliance header. """ self.add_compliance_header() return self.make_response(*e.image_server_response(self.api_version))
python
def error_response(self, e): """Make response for an IIIFError e. Also add compliance header. """ self.add_compliance_header() return self.make_response(*e.image_server_response(self.api_version))
[ "def", "error_response", "(", "self", ",", "e", ")", ":", "self", ".", "add_compliance_header", "(", ")", "return", "self", ".", "make_response", "(", "*", "e", ".", "image_server_response", "(", "self", ".", "api_version", ")", ")" ]
Make response for an IIIFError e. Also add compliance header.
[ "Make", "response", "for", "an", "IIIFError", "e", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/flask_utils.py#L375-L381
zimeon/iiif
iiif_cgi.py
IIIFRequestHandler.error_response
def error_response(self, code, content=''): """Construct and send error response.""" self.send_response(code) self.send_header('Content-Type', 'text/xml') self.add_compliance_header() self.end_headers() self.wfile.write(content)
python
def error_response(self, code, content=''): """Construct and send error response.""" self.send_response(code) self.send_header('Content-Type', 'text/xml') self.add_compliance_header() self.end_headers() self.wfile.write(content)
[ "def", "error_response", "(", "self", ",", "code", ",", "content", "=", "''", ")", ":", "self", ".", "send_response", "(", "code", ")", "self", ".", "send_header", "(", "'Content-Type'", ",", "'text/xml'", ")", "self", ".", "add_compliance_header", "(", ")...
Construct and send error response.
[ "Construct", "and", "send", "error", "response", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif_cgi.py#L64-L70
zimeon/iiif
iiif_cgi.py
IIIFRequestHandler.do_GET
def do_GET(self): """Implement the HTTP GET method. The bulk of this code is wrapped in a big try block and anywhere within the code may raise an IIIFError which then results in an IIIF error response (section 5 of spec). """ self.compliance_uri = None self.iiif ...
python
def do_GET(self): """Implement the HTTP GET method. The bulk of this code is wrapped in a big try block and anywhere within the code may raise an IIIFError which then results in an IIIF error response (section 5 of spec). """ self.compliance_uri = None self.iiif ...
[ "def", "do_GET", "(", "self", ")", ":", "self", ".", "compliance_uri", "=", "None", "self", ".", "iiif", "=", "IIIFRequest", "(", "baseurl", "=", "'/'", ")", "try", ":", "(", "of", ",", "mime_type", ")", "=", "self", ".", "do_GET_body", "(", ")", "...
Implement the HTTP GET method. The bulk of this code is wrapped in a big try block and anywhere within the code may raise an IIIFError which then results in an IIIF error response (section 5 of spec).
[ "Implement", "the", "HTTP", "GET", "method", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif_cgi.py#L78-L113
zimeon/iiif
iiif_cgi.py
IIIFRequestHandler.do_GET_body
def do_GET_body(self): """Create body of GET.""" iiif = self.iiif if (len(self.path) > 1024): raise IIIFError(code=414, text="URI Too Long: Max 1024 chars, got %d\n" % len(self.path)) try: # self.path has leading / then identifier/param...
python
def do_GET_body(self): """Create body of GET.""" iiif = self.iiif if (len(self.path) > 1024): raise IIIFError(code=414, text="URI Too Long: Max 1024 chars, got %d\n" % len(self.path)) try: # self.path has leading / then identifier/param...
[ "def", "do_GET_body", "(", "self", ")", ":", "iiif", "=", "self", ".", "iiif", "if", "(", "len", "(", "self", ".", "path", ")", ">", "1024", ")", ":", "raise", "IIIFError", "(", "code", "=", "414", ",", "text", "=", "\"URI Too Long: Max 1024 chars, got...
Create body of GET.
[ "Create", "body", "of", "GET", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif_cgi.py#L115-L162
zimeon/iiif
iiif/auth.py
IIIFAuth.set_cookie_prefix
def set_cookie_prefix(self, cookie_prefix=None): """Set a random cookie prefix unless one is specified. In order to run multiple demonstration auth services on the same server we need to have different cookie names for each auth domain. Unless cookie_prefix is set, generate a random ...
python
def set_cookie_prefix(self, cookie_prefix=None): """Set a random cookie prefix unless one is specified. In order to run multiple demonstration auth services on the same server we need to have different cookie names for each auth domain. Unless cookie_prefix is set, generate a random ...
[ "def", "set_cookie_prefix", "(", "self", ",", "cookie_prefix", "=", "None", ")", ":", "if", "(", "cookie_prefix", "is", "None", ")", ":", "self", ".", "cookie_prefix", "=", "\"%06d_\"", "%", "int", "(", "random", ".", "random", "(", ")", "*", "1000000", ...
Set a random cookie prefix unless one is specified. In order to run multiple demonstration auth services on the same server we need to have different cookie names for each auth domain. Unless cookie_prefix is set, generate a random one.
[ "Set", "a", "random", "cookie", "prefix", "unless", "one", "is", "specified", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L41-L52
zimeon/iiif
iiif/auth.py
IIIFAuth.add_services
def add_services(self, info): """Add auth service descriptions to an IIIFInfo object. Login service description is the wrapper for all other auth service descriptions so we have nothing unless self.login_uri is specified. If we do then add any other auth services at children. ...
python
def add_services(self, info): """Add auth service descriptions to an IIIFInfo object. Login service description is the wrapper for all other auth service descriptions so we have nothing unless self.login_uri is specified. If we do then add any other auth services at children. ...
[ "def", "add_services", "(", "self", ",", "info", ")", ":", "if", "(", "self", ".", "login_uri", ")", ":", "svc", "=", "self", ".", "login_service_description", "(", ")", "svcs", "=", "[", "]", "if", "(", "self", ".", "logout_uri", ")", ":", "svcs", ...
Add auth service descriptions to an IIIFInfo object. Login service description is the wrapper for all other auth service descriptions so we have nothing unless self.login_uri is specified. If we do then add any other auth services at children. Exactly the same structure is used...
[ "Add", "auth", "service", "descriptions", "to", "an", "IIIFInfo", "object", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L54-L80
zimeon/iiif
iiif/auth.py
IIIFAuth.login_service_description
def login_service_description(self): """Login service description. The login service description _MUST_ include the token service description. The authentication pattern is indicated via the profile URI which is built using self.auth_pattern. """ label = 'Login to ' + se...
python
def login_service_description(self): """Login service description. The login service description _MUST_ include the token service description. The authentication pattern is indicated via the profile URI which is built using self.auth_pattern. """ label = 'Login to ' + se...
[ "def", "login_service_description", "(", "self", ")", ":", "label", "=", "'Login to '", "+", "self", ".", "name", "if", "(", "self", ".", "auth_type", ")", ":", "label", "=", "label", "+", "' ('", "+", "self", ".", "auth_type", "+", "')'", "desc", "=",...
Login service description. The login service description _MUST_ include the token service description. The authentication pattern is indicated via the profile URI which is built using self.auth_pattern.
[ "Login", "service", "description", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L82-L99
zimeon/iiif
iiif/auth.py
IIIFAuth.logout_service_description
def logout_service_description(self): """Logout service description.""" label = 'Logout from ' + self.name if (self.auth_type): label = label + ' (' + self.auth_type + ')' return({"@id": self.logout_uri, "profile": self.profile_base + 'logout', ...
python
def logout_service_description(self): """Logout service description.""" label = 'Logout from ' + self.name if (self.auth_type): label = label + ' (' + self.auth_type + ')' return({"@id": self.logout_uri, "profile": self.profile_base + 'logout', ...
[ "def", "logout_service_description", "(", "self", ")", ":", "label", "=", "'Logout from '", "+", "self", ".", "name", "if", "(", "self", ".", "auth_type", ")", ":", "label", "=", "label", "+", "' ('", "+", "self", ".", "auth_type", "+", "')'", "return", ...
Logout service description.
[ "Logout", "service", "description", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L101-L108
zimeon/iiif
iiif/auth.py
IIIFAuth.access_token_response
def access_token_response(self, token, message_id=None): """Access token response structure. Success if token is set, otherwise (None, empty string) give error response. If message_id is set then an extra messageId attribute is set in the response to handle postMessage() responses. ...
python
def access_token_response(self, token, message_id=None): """Access token response structure. Success if token is set, otherwise (None, empty string) give error response. If message_id is set then an extra messageId attribute is set in the response to handle postMessage() responses. ...
[ "def", "access_token_response", "(", "self", ",", "token", ",", "message_id", "=", "None", ")", ":", "if", "(", "token", ")", ":", "data", "=", "{", "\"accessToken\"", ":", "token", ",", "\"expiresIn\"", ":", "self", ".", "access_token_lifetime", "}", "if"...
Access token response structure. Success if token is set, otherwise (None, empty string) give error response. If message_id is set then an extra messageId attribute is set in the response to handle postMessage() responses.
[ "Access", "token", "response", "structure", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L123-L138
zimeon/iiif
iiif/auth.py
IIIFAuth.scheme_host_port_prefix
def scheme_host_port_prefix(self, scheme='http', host='host', port=None, prefix=None): """Return URI composed of scheme, server, port, and prefix.""" uri = scheme + '://' + host if (port and not ((scheme == 'http' and port == 80) or (sche...
python
def scheme_host_port_prefix(self, scheme='http', host='host', port=None, prefix=None): """Return URI composed of scheme, server, port, and prefix.""" uri = scheme + '://' + host if (port and not ((scheme == 'http' and port == 80) or (sche...
[ "def", "scheme_host_port_prefix", "(", "self", ",", "scheme", "=", "'http'", ",", "host", "=", "'host'", ",", "port", "=", "None", ",", "prefix", "=", "None", ")", ":", "uri", "=", "scheme", "+", "'://'", "+", "host", "if", "(", "port", "and", "not",...
Return URI composed of scheme, server, port, and prefix.
[ "Return", "URI", "composed", "of", "scheme", "server", "port", "and", "prefix", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L178-L187
zimeon/iiif
iiif/auth.py
IIIFAuth._generate_random_string
def _generate_random_string(self, container, length=20): """Generate a random cookie or token string not in container. The cookie or token should be secure in the sense that it should not be likely to be able guess a value. Because it is not derived from anything else, there is no vulne...
python
def _generate_random_string(self, container, length=20): """Generate a random cookie or token string not in container. The cookie or token should be secure in the sense that it should not be likely to be able guess a value. Because it is not derived from anything else, there is no vulne...
[ "def", "_generate_random_string", "(", "self", ",", "container", ",", "length", "=", "20", ")", ":", "while", "True", ":", "s", "=", "''", ".", "join", "(", "[", "random", ".", "SystemRandom", "(", ")", ".", "choice", "(", "string", ".", "digits", "+...
Generate a random cookie or token string not in container. The cookie or token should be secure in the sense that it should not be likely to be able guess a value. Because it is not derived from anything else, there is no vulnerability of the token from computation, or possible leakage ...
[ "Generate", "a", "random", "cookie", "or", "token", "string", "not", "in", "container", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L189-L202
zimeon/iiif
iiif/auth.py
IIIFAuth.access_cookie
def access_cookie(self, account): """Make and store access cookie for a given account. If account is allowed then make a cookie and add it to the dict of accepted access cookies with current timestamp as the value. Return the access cookie. Otherwise return None. """ ...
python
def access_cookie(self, account): """Make and store access cookie for a given account. If account is allowed then make a cookie and add it to the dict of accepted access cookies with current timestamp as the value. Return the access cookie. Otherwise return None. """ ...
[ "def", "access_cookie", "(", "self", ",", "account", ")", ":", "if", "(", "self", ".", "account_allowed", "(", "account", ")", ")", ":", "cookie", "=", "self", ".", "_generate_random_string", "(", "self", ".", "access_cookies", ")", "self", ".", "access_co...
Make and store access cookie for a given account. If account is allowed then make a cookie and add it to the dict of accepted access cookies with current timestamp as the value. Return the access cookie. Otherwise return None.
[ "Make", "and", "store", "access", "cookie", "for", "a", "given", "account", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L213-L227
zimeon/iiif
iiif/auth.py
IIIFAuth.access_cookie_valid
def access_cookie_valid(self, cookie, log_msg): """Check access cookie validity. Returns true if the access cookie is valid. The set of allowed access cookies is stored in self.access_cookies. Uses log_msg as prefix to info level log message of accetance or rejection. "...
python
def access_cookie_valid(self, cookie, log_msg): """Check access cookie validity. Returns true if the access cookie is valid. The set of allowed access cookies is stored in self.access_cookies. Uses log_msg as prefix to info level log message of accetance or rejection. "...
[ "def", "access_cookie_valid", "(", "self", ",", "cookie", ",", "log_msg", ")", ":", "if", "(", "cookie", "in", "self", ".", "access_cookies", ")", ":", "age", "=", "int", "(", "time", ".", "time", "(", ")", ")", "-", "self", ".", "access_cookies", "[...
Check access cookie validity. Returns true if the access cookie is valid. The set of allowed access cookies is stored in self.access_cookies. Uses log_msg as prefix to info level log message of accetance or rejection.
[ "Check", "access", "cookie", "validity", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L229-L255
zimeon/iiif
iiif/auth.py
IIIFAuth.access_token
def access_token(self, cookie): """Make and store access token as proxy for the access cookie. Create an access token to act as a proxy for access cookie, add it to the dict of accepted access tokens with (cookie, current timestamp) as the value. Return the access token. Return None if ...
python
def access_token(self, cookie): """Make and store access token as proxy for the access cookie. Create an access token to act as a proxy for access cookie, add it to the dict of accepted access tokens with (cookie, current timestamp) as the value. Return the access token. Return None if ...
[ "def", "access_token", "(", "self", ",", "cookie", ")", ":", "if", "(", "cookie", ")", ":", "token", "=", "self", ".", "_generate_random_string", "(", "self", ".", "access_tokens", ")", "self", ".", "access_tokens", "[", "token", "]", "=", "(", "cookie",...
Make and store access token as proxy for the access cookie. Create an access token to act as a proxy for access cookie, add it to the dict of accepted access tokens with (cookie, current timestamp) as the value. Return the access token. Return None if cookie is not set.
[ "Make", "and", "store", "access", "token", "as", "proxy", "for", "the", "access", "cookie", "." ]
train
https://github.com/zimeon/iiif/blob/9d10018d01202fa2a76dfa61598dc6eca07b471f/iiif/auth.py#L257-L269