repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
Unidata/siphon | siphon/ncss.py | combine_xml_points | def combine_xml_points(l, units, handle_units):
"""Combine multiple Point tags into an array."""
ret = {}
for item in l:
for key, value in item.items():
ret.setdefault(key, []).append(value)
for key, value in ret.items():
if key != 'date':
ret[key] = handle_units... | python | def combine_xml_points(l, units, handle_units):
"""Combine multiple Point tags into an array."""
ret = {}
for item in l:
for key, value in item.items():
ret.setdefault(key, []).append(value)
for key, value in ret.items():
if key != 'date':
ret[key] = handle_units... | [
"def",
"combine_xml_points",
"(",
"l",
",",
"units",
",",
"handle_units",
")",
":",
"ret",
"=",
"{",
"}",
"for",
"item",
"in",
"l",
":",
"for",
"key",
",",
"value",
"in",
"item",
".",
"items",
"(",
")",
":",
"ret",
".",
"setdefault",
"(",
"key",
... | Combine multiple Point tags into an array. | [
"Combine",
"multiple",
"Point",
"tags",
"into",
"an",
"array",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L334-L345 |
Unidata/siphon | siphon/ncss.py | parse_xml_dataset | def parse_xml_dataset(elem, handle_units):
"""Create a netCDF-like dataset from XML data."""
points, units = zip(*[parse_xml_point(p) for p in elem.findall('point')])
# Group points by the contents of each point
datasets = {}
for p in points:
datasets.setdefault(tuple(p), []).append(p)
... | python | def parse_xml_dataset(elem, handle_units):
"""Create a netCDF-like dataset from XML data."""
points, units = zip(*[parse_xml_point(p) for p in elem.findall('point')])
# Group points by the contents of each point
datasets = {}
for p in points:
datasets.setdefault(tuple(p), []).append(p)
... | [
"def",
"parse_xml_dataset",
"(",
"elem",
",",
"handle_units",
")",
":",
"points",
",",
"units",
"=",
"zip",
"(",
"*",
"[",
"parse_xml_point",
"(",
"p",
")",
"for",
"p",
"in",
"elem",
".",
"findall",
"(",
"'point'",
")",
"]",
")",
"# Group points by the c... | Create a netCDF-like dataset from XML data. | [
"Create",
"a",
"netCDF",
"-",
"like",
"dataset",
"from",
"XML",
"data",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L348-L357 |
Unidata/siphon | siphon/ncss.py | parse_csv_response | def parse_csv_response(data, unit_handler):
"""Handle CSV-formatted HTTP responses."""
return squish([parse_csv_dataset(d, unit_handler) for d in data.split(b'\n\n')]) | python | def parse_csv_response(data, unit_handler):
"""Handle CSV-formatted HTTP responses."""
return squish([parse_csv_dataset(d, unit_handler) for d in data.split(b'\n\n')]) | [
"def",
"parse_csv_response",
"(",
"data",
",",
"unit_handler",
")",
":",
"return",
"squish",
"(",
"[",
"parse_csv_dataset",
"(",
"d",
",",
"unit_handler",
")",
"for",
"d",
"in",
"data",
".",
"split",
"(",
"b'\\n\\n'",
")",
"]",
")"
] | Handle CSV-formatted HTTP responses. | [
"Handle",
"CSV",
"-",
"formatted",
"HTTP",
"responses",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L403-L405 |
Unidata/siphon | siphon/ncss.py | parse_csv_header | def parse_csv_header(line):
"""Parse the CSV header returned by TDS."""
units = {}
names = []
for var in line.split(','):
start = var.find('[')
if start < 0:
names.append(str(var))
continue
else:
names.append(str(var[:start]))
end = var... | python | def parse_csv_header(line):
"""Parse the CSV header returned by TDS."""
units = {}
names = []
for var in line.split(','):
start = var.find('[')
if start < 0:
names.append(str(var))
continue
else:
names.append(str(var[:start]))
end = var... | [
"def",
"parse_csv_header",
"(",
"line",
")",
":",
"units",
"=",
"{",
"}",
"names",
"=",
"[",
"]",
"for",
"var",
"in",
"line",
".",
"split",
"(",
"','",
")",
":",
"start",
"=",
"var",
".",
"find",
"(",
"'['",
")",
"if",
"start",
"<",
"0",
":",
... | Parse the CSV header returned by TDS. | [
"Parse",
"the",
"CSV",
"header",
"returned",
"by",
"TDS",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L408-L425 |
Unidata/siphon | siphon/ncss.py | parse_csv_dataset | def parse_csv_dataset(data, handle_units):
"""Parse CSV data into a netCDF-like dataset."""
fobj = BytesIO(data)
names, units = parse_csv_header(fobj.readline().decode('utf-8'))
arrs = np.genfromtxt(fobj, dtype=None, names=names, delimiter=',', unpack=True,
converters={'date': l... | python | def parse_csv_dataset(data, handle_units):
"""Parse CSV data into a netCDF-like dataset."""
fobj = BytesIO(data)
names, units = parse_csv_header(fobj.readline().decode('utf-8'))
arrs = np.genfromtxt(fobj, dtype=None, names=names, delimiter=',', unpack=True,
converters={'date': l... | [
"def",
"parse_csv_dataset",
"(",
"data",
",",
"handle_units",
")",
":",
"fobj",
"=",
"BytesIO",
"(",
"data",
")",
"names",
",",
"units",
"=",
"parse_csv_header",
"(",
"fobj",
".",
"readline",
"(",
")",
".",
"decode",
"(",
"'utf-8'",
")",
")",
"arrs",
"... | Parse CSV data into a netCDF-like dataset. | [
"Parse",
"CSV",
"data",
"into",
"a",
"netCDF",
"-",
"like",
"dataset",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L428-L440 |
Unidata/siphon | siphon/ncss.py | NCSS.validate_query | def validate_query(self, query):
"""Validate a query.
Determines whether `query` is well-formed. This includes checking for all
required parameters, as well as checking parameters for valid values.
Parameters
----------
query : NCSSQuery
The query to validat... | python | def validate_query(self, query):
"""Validate a query.
Determines whether `query` is well-formed. This includes checking for all
required parameters, as well as checking parameters for valid values.
Parameters
----------
query : NCSSQuery
The query to validat... | [
"def",
"validate_query",
"(",
"self",
",",
"query",
")",
":",
"# Make sure all variables are in the dataset",
"return",
"bool",
"(",
"query",
".",
"var",
")",
"and",
"all",
"(",
"var",
"in",
"self",
".",
"variables",
"for",
"var",
"in",
"query",
".",
"var",
... | Validate a query.
Determines whether `query` is well-formed. This includes checking for all
required parameters, as well as checking parameters for valid values.
Parameters
----------
query : NCSSQuery
The query to validate
Returns
-------
v... | [
"Validate",
"a",
"query",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L73-L91 |
Unidata/siphon | siphon/ncss.py | NCSS.get_data | def get_data(self, query):
"""Fetch parsed data from a THREDDS server using NCSS.
Requests data from the NCSS endpoint given the parameters in `query` and
handles parsing of the returned content based on the mimetype.
Parameters
----------
query : NCSSQuery
... | python | def get_data(self, query):
"""Fetch parsed data from a THREDDS server using NCSS.
Requests data from the NCSS endpoint given the parameters in `query` and
handles parsing of the returned content based on the mimetype.
Parameters
----------
query : NCSSQuery
... | [
"def",
"get_data",
"(",
"self",
",",
"query",
")",
":",
"resp",
"=",
"self",
".",
"get_query",
"(",
"query",
")",
"return",
"response_handlers",
"(",
"resp",
",",
"self",
".",
"unit_handler",
")"
] | Fetch parsed data from a THREDDS server using NCSS.
Requests data from the NCSS endpoint given the parameters in `query` and
handles parsing of the returned content based on the mimetype.
Parameters
----------
query : NCSSQuery
The parameters to send to the NCSS end... | [
"Fetch",
"parsed",
"data",
"from",
"a",
"THREDDS",
"server",
"using",
"NCSS",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L93-L115 |
Unidata/siphon | siphon/ncss.py | NCSSQuery.projection_box | def projection_box(self, min_x, min_y, max_x, max_y):
"""Add a bounding box in projected (native) coordinates to the query.
This adds a request for a spatial bounding box, bounded by (`min_x`, `max_x`) for
x direction and (`min_y`, `max_y`) for the y direction. This modifies the query
i... | python | def projection_box(self, min_x, min_y, max_x, max_y):
"""Add a bounding box in projected (native) coordinates to the query.
This adds a request for a spatial bounding box, bounded by (`min_x`, `max_x`) for
x direction and (`min_y`, `max_y`) for the y direction. This modifies the query
i... | [
"def",
"projection_box",
"(",
"self",
",",
"min_x",
",",
"min_y",
",",
"max_x",
",",
"max_y",
")",
":",
"self",
".",
"_set_query",
"(",
"self",
".",
"spatial_query",
",",
"minx",
"=",
"min_x",
",",
"miny",
"=",
"min_y",
",",
"maxx",
"=",
"max_x",
","... | Add a bounding box in projected (native) coordinates to the query.
This adds a request for a spatial bounding box, bounded by (`min_x`, `max_x`) for
x direction and (`min_y`, `max_y`) for the y direction. This modifies the query
in-place, but returns ``self`` so that multiple queries can be cha... | [
"Add",
"a",
"bounding",
"box",
"in",
"projected",
"(",
"native",
")",
"coordinates",
"to",
"the",
"query",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L148-L177 |
Unidata/siphon | siphon/ncss.py | NCSSQuery.strides | def strides(self, time=None, spatial=None):
"""Set time and/or spatial (horizontal) strides.
This is only used on grid requests. Used to skip points in the returned data.
This modifies the query in-place, but returns `self` so that multiple queries
can be chained together on one line.
... | python | def strides(self, time=None, spatial=None):
"""Set time and/or spatial (horizontal) strides.
This is only used on grid requests. Used to skip points in the returned data.
This modifies the query in-place, but returns `self` so that multiple queries
can be chained together on one line.
... | [
"def",
"strides",
"(",
"self",
",",
"time",
"=",
"None",
",",
"spatial",
"=",
"None",
")",
":",
"if",
"time",
":",
"self",
".",
"add_query_parameter",
"(",
"timeStride",
"=",
"time",
")",
"if",
"spatial",
":",
"self",
".",
"add_query_parameter",
"(",
"... | Set time and/or spatial (horizontal) strides.
This is only used on grid requests. Used to skip points in the returned data.
This modifies the query in-place, but returns `self` so that multiple queries
can be chained together on one line.
Parameters
----------
time : in... | [
"Set",
"time",
"and",
"/",
"or",
"spatial",
"(",
"horizontal",
")",
"strides",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L218-L242 |
Unidata/siphon | siphon/ncss.py | ResponseRegistry.register | def register(self, mimetype):
"""Register a function to handle a particular mimetype."""
def dec(func):
self._reg[mimetype] = func
return func
return dec | python | def register(self, mimetype):
"""Register a function to handle a particular mimetype."""
def dec(func):
self._reg[mimetype] = func
return func
return dec | [
"def",
"register",
"(",
"self",
",",
"mimetype",
")",
":",
"def",
"dec",
"(",
"func",
")",
":",
"self",
".",
"_reg",
"[",
"mimetype",
"]",
"=",
"func",
"return",
"func",
"return",
"dec"
] | Register a function to handle a particular mimetype. | [
"Register",
"a",
"function",
"to",
"handle",
"a",
"particular",
"mimetype",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss.py#L279-L284 |
Unidata/siphon | siphon/ncss_dataset.py | _Types.handle_typed_values | def handle_typed_values(val, type_name, value_type):
"""Translate typed values into the appropriate python object.
Takes an element name, value, and type and returns a list
with the string value(s) properly converted to a python type.
TypedValues are handled in ucar.ma2.DataType in net... | python | def handle_typed_values(val, type_name, value_type):
"""Translate typed values into the appropriate python object.
Takes an element name, value, and type and returns a list
with the string value(s) properly converted to a python type.
TypedValues are handled in ucar.ma2.DataType in net... | [
"def",
"handle_typed_values",
"(",
"val",
",",
"type_name",
",",
"value_type",
")",
":",
"if",
"value_type",
"in",
"[",
"'byte'",
",",
"'short'",
",",
"'int'",
",",
"'long'",
"]",
":",
"try",
":",
"val",
"=",
"[",
"int",
"(",
"v",
")",
"for",
"v",
... | Translate typed values into the appropriate python object.
Takes an element name, value, and type and returns a list
with the string value(s) properly converted to a python type.
TypedValues are handled in ucar.ma2.DataType in netcdfJava
in the DataType enum. Possibilities are:
... | [
"Translate",
"typed",
"values",
"into",
"the",
"appropriate",
"python",
"object",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/ncss_dataset.py#L26-L114 |
Unidata/siphon | siphon/simplewebservice/wyoming.py | WyomingUpperAir._get_data | def _get_data(self, time, site_id):
r"""Download and parse upper air observations from an online archive.
Parameters
----------
time : datetime
The date and time of the desired observation.
site_id : str
The three letter ICAO identifier of the station fo... | python | def _get_data(self, time, site_id):
r"""Download and parse upper air observations from an online archive.
Parameters
----------
time : datetime
The date and time of the desired observation.
site_id : str
The three letter ICAO identifier of the station fo... | [
"def",
"_get_data",
"(",
"self",
",",
"time",
",",
"site_id",
")",
":",
"raw_data",
"=",
"self",
".",
"_get_data_raw",
"(",
"time",
",",
"site_id",
")",
"soup",
"=",
"BeautifulSoup",
"(",
"raw_data",
",",
"'html.parser'",
")",
"tabular_data",
"=",
"StringI... | r"""Download and parse upper air observations from an online archive.
Parameters
----------
time : datetime
The date and time of the desired observation.
site_id : str
The three letter ICAO identifier of the station for which data should be
downloade... | [
"r",
"Download",
"and",
"parse",
"upper",
"air",
"observations",
"from",
"an",
"online",
"archive",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/simplewebservice/wyoming.py#L52-L119 |
Unidata/siphon | siphon/simplewebservice/wyoming.py | WyomingUpperAir._get_data_raw | def _get_data_raw(self, time, site_id):
"""Download data from the University of Wyoming's upper air archive.
Parameters
----------
time : datetime
Date and time for which data should be downloaded
site_id : str
Site id for which data should be downloaded
... | python | def _get_data_raw(self, time, site_id):
"""Download data from the University of Wyoming's upper air archive.
Parameters
----------
time : datetime
Date and time for which data should be downloaded
site_id : str
Site id for which data should be downloaded
... | [
"def",
"_get_data_raw",
"(",
"self",
",",
"time",
",",
"site_id",
")",
":",
"path",
"=",
"(",
"'?region=naconf&TYPE=TEXT%3ALIST'",
"'&YEAR={time:%Y}&MONTH={time:%m}&FROM={time:%d%H}&TO={time:%d%H}'",
"'&STNM={stid}'",
")",
".",
"format",
"(",
"time",
"=",
"time",
",",
... | Download data from the University of Wyoming's upper air archive.
Parameters
----------
time : datetime
Date and time for which data should be downloaded
site_id : str
Site id for which data should be downloaded
Returns
-------
text of th... | [
"Download",
"data",
"from",
"the",
"University",
"of",
"Wyoming",
"s",
"upper",
"air",
"archive",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/simplewebservice/wyoming.py#L121-L147 |
Unidata/siphon | siphon/cdmr/ncstream.py | read_ncstream_data | def read_ncstream_data(fobj):
"""Handle reading an NcStream v1 data block from a file-like object."""
data = read_proto_object(fobj, stream.Data)
if data.dataType in (stream.STRING, stream.OPAQUE) or data.vdata:
log.debug('Reading string/opaque/vlen')
num_obj = read_var_int(fobj)
log... | python | def read_ncstream_data(fobj):
"""Handle reading an NcStream v1 data block from a file-like object."""
data = read_proto_object(fobj, stream.Data)
if data.dataType in (stream.STRING, stream.OPAQUE) or data.vdata:
log.debug('Reading string/opaque/vlen')
num_obj = read_var_int(fobj)
log... | [
"def",
"read_ncstream_data",
"(",
"fobj",
")",
":",
"data",
"=",
"read_proto_object",
"(",
"fobj",
",",
"stream",
".",
"Data",
")",
"if",
"data",
".",
"dataType",
"in",
"(",
"stream",
".",
"STRING",
",",
"stream",
".",
"OPAQUE",
")",
"or",
"data",
".",... | Handle reading an NcStream v1 data block from a file-like object. | [
"Handle",
"reading",
"an",
"NcStream",
"v1",
"data",
"block",
"from",
"a",
"file",
"-",
"like",
"object",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L35-L91 |
Unidata/siphon | siphon/cdmr/ncstream.py | read_ncstream_err | def read_ncstream_err(fobj):
"""Handle reading an NcStream error from a file-like object and raise as error."""
err = read_proto_object(fobj, stream.Error)
raise RuntimeError(err.message) | python | def read_ncstream_err(fobj):
"""Handle reading an NcStream error from a file-like object and raise as error."""
err = read_proto_object(fobj, stream.Error)
raise RuntimeError(err.message) | [
"def",
"read_ncstream_err",
"(",
"fobj",
")",
":",
"err",
"=",
"read_proto_object",
"(",
"fobj",
",",
"stream",
".",
"Error",
")",
"raise",
"RuntimeError",
"(",
"err",
".",
"message",
")"
] | Handle reading an NcStream error from a file-like object and raise as error. | [
"Handle",
"reading",
"an",
"NcStream",
"error",
"from",
"a",
"file",
"-",
"like",
"object",
"and",
"raise",
"as",
"error",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L100-L103 |
Unidata/siphon | siphon/cdmr/ncstream.py | read_messages | def read_messages(fobj, magic_table):
"""Read messages from a file-like object until stream is exhausted."""
messages = []
while True:
magic = read_magic(fobj)
if not magic:
break
func = magic_table.get(magic)
if func is not None:
messages.append(fun... | python | def read_messages(fobj, magic_table):
"""Read messages from a file-like object until stream is exhausted."""
messages = []
while True:
magic = read_magic(fobj)
if not magic:
break
func = magic_table.get(magic)
if func is not None:
messages.append(fun... | [
"def",
"read_messages",
"(",
"fobj",
",",
"magic_table",
")",
":",
"messages",
"=",
"[",
"]",
"while",
"True",
":",
"magic",
"=",
"read_magic",
"(",
"fobj",
")",
"if",
"not",
"magic",
":",
"break",
"func",
"=",
"magic_table",
".",
"get",
"(",
"magic",
... | Read messages from a file-like object until stream is exhausted. | [
"Read",
"messages",
"from",
"a",
"file",
"-",
"like",
"object",
"until",
"stream",
"is",
"exhausted",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L134-L150 |
Unidata/siphon | siphon/cdmr/ncstream.py | read_proto_object | def read_proto_object(fobj, klass):
"""Read a block of data and parse using the given protobuf object."""
log.debug('%s chunk', klass.__name__)
obj = klass()
obj.ParseFromString(read_block(fobj))
log.debug('Header: %s', str(obj))
return obj | python | def read_proto_object(fobj, klass):
"""Read a block of data and parse using the given protobuf object."""
log.debug('%s chunk', klass.__name__)
obj = klass()
obj.ParseFromString(read_block(fobj))
log.debug('Header: %s', str(obj))
return obj | [
"def",
"read_proto_object",
"(",
"fobj",
",",
"klass",
")",
":",
"log",
".",
"debug",
"(",
"'%s chunk'",
",",
"klass",
".",
"__name__",
")",
"obj",
"=",
"klass",
"(",
")",
"obj",
".",
"ParseFromString",
"(",
"read_block",
"(",
"fobj",
")",
")",
"log",
... | Read a block of data and parse using the given protobuf object. | [
"Read",
"a",
"block",
"of",
"data",
"and",
"parse",
"using",
"the",
"given",
"protobuf",
"object",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L153-L159 |
Unidata/siphon | siphon/cdmr/ncstream.py | read_block | def read_block(fobj):
"""Read a block.
Reads a block from a file object by first reading the number of bytes to read, which must
be encoded as a variable-byte length integer.
Parameters
----------
fobj : file-like object
The file to read from.
Returns
-------
bytes
... | python | def read_block(fobj):
"""Read a block.
Reads a block from a file object by first reading the number of bytes to read, which must
be encoded as a variable-byte length integer.
Parameters
----------
fobj : file-like object
The file to read from.
Returns
-------
bytes
... | [
"def",
"read_block",
"(",
"fobj",
")",
":",
"num",
"=",
"read_var_int",
"(",
"fobj",
")",
"log",
".",
"debug",
"(",
"'Next block: %d bytes'",
",",
"num",
")",
"return",
"fobj",
".",
"read",
"(",
"num",
")"
] | Read a block.
Reads a block from a file object by first reading the number of bytes to read, which must
be encoded as a variable-byte length integer.
Parameters
----------
fobj : file-like object
The file to read from.
Returns
-------
bytes
block of bytes read | [
"Read",
"a",
"block",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L179-L198 |
Unidata/siphon | siphon/cdmr/ncstream.py | process_vlen | def process_vlen(data_header, array):
"""Process vlen coming back from NCStream v2.
This takes the array of values and slices into an object array, with entries containing
the appropriate pieces of the original array. Sizes are controlled by the passed in
`data_header`.
Parameters
----------
... | python | def process_vlen(data_header, array):
"""Process vlen coming back from NCStream v2.
This takes the array of values and slices into an object array, with entries containing
the appropriate pieces of the original array. Sizes are controlled by the passed in
`data_header`.
Parameters
----------
... | [
"def",
"process_vlen",
"(",
"data_header",
",",
"array",
")",
":",
"source",
"=",
"iter",
"(",
"array",
")",
"return",
"np",
".",
"array",
"(",
"[",
"np",
".",
"fromiter",
"(",
"itertools",
".",
"islice",
"(",
"source",
",",
"size",
")",
",",
"dtype"... | Process vlen coming back from NCStream v2.
This takes the array of values and slices into an object array, with entries containing
the appropriate pieces of the original array. Sizes are controlled by the passed in
`data_header`.
Parameters
----------
data_header : Header
array : :class:`n... | [
"Process",
"vlen",
"coming",
"back",
"from",
"NCStream",
"v2",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L201-L221 |
Unidata/siphon | siphon/cdmr/ncstream.py | datacol_to_array | def datacol_to_array(datacol):
"""Convert DataCol from NCStream v2 into an array with appropriate type.
Depending on the data type specified, this extracts data from the appropriate members
and packs into a :class:`numpy.ndarray`, recursing as necessary for compound data types.
Parameters
--------... | python | def datacol_to_array(datacol):
"""Convert DataCol from NCStream v2 into an array with appropriate type.
Depending on the data type specified, this extracts data from the appropriate members
and packs into a :class:`numpy.ndarray`, recursing as necessary for compound data types.
Parameters
--------... | [
"def",
"datacol_to_array",
"(",
"datacol",
")",
":",
"if",
"datacol",
".",
"dataType",
"==",
"stream",
".",
"STRING",
":",
"arr",
"=",
"np",
".",
"array",
"(",
"datacol",
".",
"stringdata",
",",
"dtype",
"=",
"np",
".",
"object",
")",
"elif",
"datacol"... | Convert DataCol from NCStream v2 into an array with appropriate type.
Depending on the data type specified, this extracts data from the appropriate members
and packs into a :class:`numpy.ndarray`, recursing as necessary for compound data types.
Parameters
----------
datacol : DataCol
Returns
... | [
"Convert",
"DataCol",
"from",
"NCStream",
"v2",
"into",
"an",
"array",
"with",
"appropriate",
"type",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L224-L278 |
Unidata/siphon | siphon/cdmr/ncstream.py | reshape_array | def reshape_array(data_header, array):
"""Extract the appropriate array shape from the header.
Can handle taking a data header and either bytes containing data or a StructureData
instance, which will have binary data as well as some additional information.
Parameters
----------
array : :class:... | python | def reshape_array(data_header, array):
"""Extract the appropriate array shape from the header.
Can handle taking a data header and either bytes containing data or a StructureData
instance, which will have binary data as well as some additional information.
Parameters
----------
array : :class:... | [
"def",
"reshape_array",
"(",
"data_header",
",",
"array",
")",
":",
"shape",
"=",
"tuple",
"(",
"r",
".",
"size",
"for",
"r",
"in",
"data_header",
".",
"section",
".",
"range",
")",
"if",
"shape",
":",
"return",
"array",
".",
"reshape",
"(",
"*",
"sh... | Extract the appropriate array shape from the header.
Can handle taking a data header and either bytes containing data or a StructureData
instance, which will have binary data as well as some additional information.
Parameters
----------
array : :class:`numpy.ndarray`
data_header : Data | [
"Extract",
"the",
"appropriate",
"array",
"shape",
"from",
"the",
"header",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L281-L297 |
Unidata/siphon | siphon/cdmr/ncstream.py | data_type_to_numpy | def data_type_to_numpy(datatype, unsigned=False):
"""Convert an ncstream datatype to a numpy one."""
basic_type = _dtypeLookup[datatype]
if datatype in (stream.STRING, stream.OPAQUE):
return np.dtype(basic_type)
if unsigned:
basic_type = basic_type.replace('i', 'u')
return np.dtype... | python | def data_type_to_numpy(datatype, unsigned=False):
"""Convert an ncstream datatype to a numpy one."""
basic_type = _dtypeLookup[datatype]
if datatype in (stream.STRING, stream.OPAQUE):
return np.dtype(basic_type)
if unsigned:
basic_type = basic_type.replace('i', 'u')
return np.dtype... | [
"def",
"data_type_to_numpy",
"(",
"datatype",
",",
"unsigned",
"=",
"False",
")",
":",
"basic_type",
"=",
"_dtypeLookup",
"[",
"datatype",
"]",
"if",
"datatype",
"in",
"(",
"stream",
".",
"STRING",
",",
"stream",
".",
"OPAQUE",
")",
":",
"return",
"np",
... | Convert an ncstream datatype to a numpy one. | [
"Convert",
"an",
"ncstream",
"datatype",
"to",
"a",
"numpy",
"one",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L310-L319 |
Unidata/siphon | siphon/cdmr/ncstream.py | struct_to_dtype | def struct_to_dtype(struct):
"""Convert a Structure specification to a numpy structured dtype."""
# str() around name necessary because protobuf gives unicode names, but dtype doesn't
# support them on Python 2
fields = [(str(var.name), data_type_to_numpy(var.dataType, var.unsigned))
for v... | python | def struct_to_dtype(struct):
"""Convert a Structure specification to a numpy structured dtype."""
# str() around name necessary because protobuf gives unicode names, but dtype doesn't
# support them on Python 2
fields = [(str(var.name), data_type_to_numpy(var.dataType, var.unsigned))
for v... | [
"def",
"struct_to_dtype",
"(",
"struct",
")",
":",
"# str() around name necessary because protobuf gives unicode names, but dtype doesn't",
"# support them on Python 2",
"fields",
"=",
"[",
"(",
"str",
"(",
"var",
".",
"name",
")",
",",
"data_type_to_numpy",
"(",
"var",
"... | Convert a Structure specification to a numpy structured dtype. | [
"Convert",
"a",
"Structure",
"specification",
"to",
"a",
"numpy",
"structured",
"dtype",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L322-L333 |
Unidata/siphon | siphon/cdmr/ncstream.py | unpack_variable | def unpack_variable(var):
"""Unpack an NCStream Variable into information we can use."""
# If we actually get a structure instance, handle turning that into a variable
if var.dataType == stream.STRUCTURE:
return None, struct_to_dtype(var), 'Structure'
elif var.dataType == stream.SEQUENCE:
... | python | def unpack_variable(var):
"""Unpack an NCStream Variable into information we can use."""
# If we actually get a structure instance, handle turning that into a variable
if var.dataType == stream.STRUCTURE:
return None, struct_to_dtype(var), 'Structure'
elif var.dataType == stream.SEQUENCE:
... | [
"def",
"unpack_variable",
"(",
"var",
")",
":",
"# If we actually get a structure instance, handle turning that into a variable",
"if",
"var",
".",
"dataType",
"==",
"stream",
".",
"STRUCTURE",
":",
"return",
"None",
",",
"struct_to_dtype",
"(",
"var",
")",
",",
"'Str... | Unpack an NCStream Variable into information we can use. | [
"Unpack",
"an",
"NCStream",
"Variable",
"into",
"information",
"we",
"can",
"use",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L336-L362 |
Unidata/siphon | siphon/cdmr/ncstream.py | unpack_attribute | def unpack_attribute(att):
"""Unpack an embedded attribute into a python or numpy object."""
if att.unsigned:
log.warning('Unsupported unsigned attribute!')
# TDS 5.0 now has a dataType attribute that takes precedence
if att.len == 0: # Empty
val = None
elif att.dataType == stream.... | python | def unpack_attribute(att):
"""Unpack an embedded attribute into a python or numpy object."""
if att.unsigned:
log.warning('Unsupported unsigned attribute!')
# TDS 5.0 now has a dataType attribute that takes precedence
if att.len == 0: # Empty
val = None
elif att.dataType == stream.... | [
"def",
"unpack_attribute",
"(",
"att",
")",
":",
"if",
"att",
".",
"unsigned",
":",
"log",
".",
"warning",
"(",
"'Unsupported unsigned attribute!'",
")",
"# TDS 5.0 now has a dataType attribute that takes precedence",
"if",
"att",
".",
"len",
"==",
"0",
":",
"# Empt... | Unpack an embedded attribute into a python or numpy object. | [
"Unpack",
"an",
"embedded",
"attribute",
"into",
"a",
"python",
"or",
"numpy",
"object",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L373-L397 |
Unidata/siphon | siphon/cdmr/ncstream.py | read_var_int | def read_var_int(file_obj):
"""Read a variable-length integer.
Parameters
----------
file_obj : file-like object
The file to read from.
Returns
-------
int
the variable-length value read
"""
# Read all bytes from here, stopping with the first one that does not have... | python | def read_var_int(file_obj):
"""Read a variable-length integer.
Parameters
----------
file_obj : file-like object
The file to read from.
Returns
-------
int
the variable-length value read
"""
# Read all bytes from here, stopping with the first one that does not have... | [
"def",
"read_var_int",
"(",
"file_obj",
")",
":",
"# Read all bytes from here, stopping with the first one that does not have",
"# the MSB set. Save the lower 7 bits, and keep stacking to the *left*.",
"val",
"=",
"0",
"shift",
"=",
"0",
"while",
"True",
":",
"# Read next byte",
... | Read a variable-length integer.
Parameters
----------
file_obj : file-like object
The file to read from.
Returns
-------
int
the variable-length value read | [
"Read",
"a",
"variable",
"-",
"length",
"integer",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/ncstream.py#L400-L426 |
Unidata/siphon | siphon/cdmr/cdmremote.py | CDMRemote.fetch_data | def fetch_data(self, **var):
"""Retrieve data from CDMRemote for one or more variables."""
varstr = ','.join(name + self._convert_indices(ind)
for name, ind in var.items())
query = self.query().add_query_parameter(req='data', var=varstr)
return self._fetch(query... | python | def fetch_data(self, **var):
"""Retrieve data from CDMRemote for one or more variables."""
varstr = ','.join(name + self._convert_indices(ind)
for name, ind in var.items())
query = self.query().add_query_parameter(req='data', var=varstr)
return self._fetch(query... | [
"def",
"fetch_data",
"(",
"self",
",",
"*",
"*",
"var",
")",
":",
"varstr",
"=",
"','",
".",
"join",
"(",
"name",
"+",
"self",
".",
"_convert_indices",
"(",
"ind",
")",
"for",
"name",
",",
"ind",
"in",
"var",
".",
"items",
"(",
")",
")",
"query",... | Retrieve data from CDMRemote for one or more variables. | [
"Retrieve",
"data",
"from",
"CDMRemote",
"for",
"one",
"or",
"more",
"variables",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/cdmremote.py#L31-L36 |
Unidata/siphon | siphon/cdmr/cdmremote.py | CDMRemote.query | def query(self):
"""Generate a new query for CDMRemote.
This handles turning on compression if necessary.
Returns
-------
HTTPQuery
The created query.
"""
q = super(CDMRemote, self).query()
# Turn on compression if it's been set on the obje... | python | def query(self):
"""Generate a new query for CDMRemote.
This handles turning on compression if necessary.
Returns
-------
HTTPQuery
The created query.
"""
q = super(CDMRemote, self).query()
# Turn on compression if it's been set on the obje... | [
"def",
"query",
"(",
"self",
")",
":",
"q",
"=",
"super",
"(",
"CDMRemote",
",",
"self",
")",
".",
"query",
"(",
")",
"# Turn on compression if it's been set on the object",
"if",
"self",
".",
"deflate",
":",
"q",
".",
"add_query_parameter",
"(",
"deflate",
... | Generate a new query for CDMRemote.
This handles turning on compression if necessary.
Returns
-------
HTTPQuery
The created query. | [
"Generate",
"a",
"new",
"query",
"for",
"CDMRemote",
"."
] | train | https://github.com/Unidata/siphon/blob/53fb0d84fbce1c18c8e81c9e68bc81620ee0a6ac/siphon/cdmr/cdmremote.py#L46-L63 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | check_token | def check_token(func):
"""检查 access token 是否有效."""
@wraps(func)
def wrapper(*args, **kwargs):
response = func(*args, **kwargs)
if response.status_code == 401:
raise InvalidToken('Access token invalid or no longer valid')
else:
return response
return wrappe... | python | def check_token(func):
"""检查 access token 是否有效."""
@wraps(func)
def wrapper(*args, **kwargs):
response = func(*args, **kwargs)
if response.status_code == 401:
raise InvalidToken('Access token invalid or no longer valid')
else:
return response
return wrappe... | [
"def",
"check_token",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"response",
"=",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"response",
".",
... | 检查 access token 是否有效. | [
"检查",
"access",
"token",
"是否有效",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L22-L31 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.upload | def upload(self, remote_path, file_content, ondup=None, **kwargs):
"""上传单个文件(<2G).
| 百度PCS服务目前支持最大2G的单个文件上传。
| 如需支持超大文件(>2G)的断点续传,请参考下面的“分片文件上传”方法。
:param remote_path: 网盘中文件的保存路径(包含文件名)。
必须以 /apps/ 开头。
.. warning::
... | python | def upload(self, remote_path, file_content, ondup=None, **kwargs):
"""上传单个文件(<2G).
| 百度PCS服务目前支持最大2G的单个文件上传。
| 如需支持超大文件(>2G)的断点续传,请参考下面的“分片文件上传”方法。
:param remote_path: 网盘中文件的保存路径(包含文件名)。
必须以 /apps/ 开头。
.. warning::
... | [
"def",
"upload",
"(",
"self",
",",
"remote_path",
",",
"file_content",
",",
"ondup",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
",",
"'ondup'",
":",
"ondup",
"}",
"files",
"=",
"{",
"'file'",
":"... | 上传单个文件(<2G).
| 百度PCS服务目前支持最大2G的单个文件上传。
| 如需支持超大文件(>2G)的断点续传,请参考下面的“分片文件上传”方法。
:param remote_path: 网盘中文件的保存路径(包含文件名)。
必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:... | [
"上传单个文件(<2G)",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L103-L135 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.upload_tmpfile | def upload_tmpfile(self, file_content, **kwargs):
"""分片上传—文件分片及上传.
百度 PCS 服务支持每次直接上传最大2G的单个文件。
如需支持上传超大文件(>2G),则可以通过组合调用分片文件上传的
``upload_tmpfile`` 方法和 ``upload_superfile`` 方法实现:
1. 首先,将超大文件分割为2G以内的单文件,并调用 ``upload_tmpfile``
将分片文件依次上传;
2. 其次,调用 ``upload_super... | python | def upload_tmpfile(self, file_content, **kwargs):
"""分片上传—文件分片及上传.
百度 PCS 服务支持每次直接上传最大2G的单个文件。
如需支持上传超大文件(>2G),则可以通过组合调用分片文件上传的
``upload_tmpfile`` 方法和 ``upload_superfile`` 方法实现:
1. 首先,将超大文件分割为2G以内的单文件,并调用 ``upload_tmpfile``
将分片文件依次上传;
2. 其次,调用 ``upload_super... | [
"def",
"upload_tmpfile",
"(",
"self",
",",
"file_content",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'type'",
":",
"'tmpfile'",
"}",
"files",
"=",
"{",
"'file'",
":",
"(",
"'file'",
",",
"file_content",
",",
"''",
")",
"}",
"url",
"=",
... | 分片上传—文件分片及上传.
百度 PCS 服务支持每次直接上传最大2G的单个文件。
如需支持上传超大文件(>2G),则可以通过组合调用分片文件上传的
``upload_tmpfile`` 方法和 ``upload_superfile`` 方法实现:
1. 首先,将超大文件分割为2G以内的单文件,并调用 ``upload_tmpfile``
将分片文件依次上传;
2. 其次,调用 ``upload_superfile`` ,完成分片文件的重组。
除此之外,如果应用中需要支持断点续传的功能,
也可... | [
"分片上传—文件分片及上传",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L137-L163 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.upload_superfile | def upload_superfile(self, remote_path, block_list, ondup=None, **kwargs):
"""分片上传—合并分片文件.
与分片文件上传的 ``upload_tmpfile`` 方法配合使用,
可实现超大文件(>2G)上传,同时也可用于断点续传的场景。
:param remote_path: 网盘中文件的保存路径(包含文件名)。
必须以 /apps/ 开头。
.. warning::
... | python | def upload_superfile(self, remote_path, block_list, ondup=None, **kwargs):
"""分片上传—合并分片文件.
与分片文件上传的 ``upload_tmpfile`` 方法配合使用,
可实现超大文件(>2G)上传,同时也可用于断点续传的场景。
:param remote_path: 网盘中文件的保存路径(包含文件名)。
必须以 /apps/ 开头。
.. warning::
... | [
"def",
"upload_superfile",
"(",
"self",
",",
"remote_path",
",",
"block_list",
",",
"ondup",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
",",
"'ondup'",
":",
"ondup",
"}",
"data",
"=",
"{",
"'param'... | 分片上传—合并分片文件.
与分片文件上传的 ``upload_tmpfile`` 方法配合使用,
可实现超大文件(>2G)上传,同时也可用于断点续传的场景。
:param remote_path: 网盘中文件的保存路径(包含文件名)。
必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符... | [
"分片上传—合并分片文件",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L165-L198 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.mkdir | def mkdir(self, remote_path, **kwargs):
"""为当前用户创建一个目录.
:param remote_path: 网盘中目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾... | python | def mkdir(self, remote_path, **kwargs):
"""为当前用户创建一个目录.
:param remote_path: 网盘中目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾... | [
"def",
"mkdir",
"(",
"self",
",",
"remote_path",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'path'",
":",
"remote_path",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",
",",
"'mkdir'",
",",
"data",
"=",
"data",
",",
"*",
"*",
"kwa... | 为当前用户创建一个目录.
:param remote_path: 网盘中目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
或空白字符,空... | [
"为当前用户创建一个目录",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L232-L249 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.meta | def meta(self, remote_path, **kwargs):
"""获取单个文件或目录的元信息.
:param remote_path: 网盘中文件/目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名... | python | def meta(self, remote_path, **kwargs):
"""获取单个文件或目录的元信息.
:param remote_path: 网盘中文件/目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名... | [
"def",
"meta",
"(",
"self",
",",
"remote_path",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",
",",
"'meta'",
",",
"extra_params",
"=",
"params",
",",
"*",
"... | 获取单个文件或目录的元信息.
:param remote_path: 网盘中文件/目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
或空... | [
"获取单个文件或目录的元信息",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L251-L268 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.list_files | def list_files(self, remote_path, by=None, order=None,
limit=None, **kwargs):
"""获取目录下的文件列表.
:param remote_path: 网盘中目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " ... | python | def list_files(self, remote_path, by=None, order=None,
limit=None, **kwargs):
"""获取目录下的文件列表.
:param remote_path: 网盘中目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " ... | [
"def",
"list_files",
"(",
"self",
",",
"remote_path",
",",
"by",
"=",
"None",
",",
"order",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
",",
"'by'",
":",
"by",
",",
... | 获取目录下的文件列表.
:param remote_path: 网盘中目录的路径,必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
或空白字符,空白... | [
"获取目录下的文件列表",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L292-L326 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.move | def move(self, from_path, to_path, **kwargs):
"""移动单个文件或目录.
:param from_path: 源文件/目录在网盘中的路径(包括文件名)。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.`... | python | def move(self, from_path, to_path, **kwargs):
"""移动单个文件或目录.
:param from_path: 源文件/目录在网盘中的路径(包括文件名)。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.`... | [
"def",
"move",
"(",
"self",
",",
"from_path",
",",
"to_path",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'from'",
":",
"from_path",
",",
"'to'",
":",
"to_path",
",",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",
",",
"'move'",
"... | 移动单个文件或目录.
:param from_path: 源文件/目录在网盘中的路径(包括文件名)。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
或空白字符,空白字符包括:
... | [
"移动单个文件或目录",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L328-L354 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.multi_move | def multi_move(self, path_list, **kwargs):
"""批量移动文件或目录.
:param path_list: 源文件地址和目标文件地址对列表:
>>> path_list = [
... ('/apps/test_sdk/test.txt', # 源文件
... '/apps/test_sdk/testmkdir/b.txt' # 目标文件
... | python | def multi_move(self, path_list, **kwargs):
"""批量移动文件或目录.
:param path_list: 源文件地址和目标文件地址对列表:
>>> path_list = [
... ('/apps/test_sdk/test.txt', # 源文件
... '/apps/test_sdk/testmkdir/b.txt' # 目标文件
... | [
"def",
"multi_move",
"(",
"self",
",",
"path_list",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'param'",
":",
"json",
".",
"dumps",
"(",
"{",
"'list'",
":",
"[",
"{",
"'from'",
":",
"x",
"[",
"0",
"]",
",",
"'to'",
":",
"x",
"[",
"... | 批量移动文件或目录.
:param path_list: 源文件地址和目标文件地址对列表:
>>> path_list = [
... ('/apps/test_sdk/test.txt', # 源文件
... '/apps/test_sdk/testmkdir/b.txt' # 目标文件
... ),
... ('/apps/test... | [
"批量移动文件或目录",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L356-L385 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.copy | def copy(self, from_path, to_path, **kwargs):
"""拷贝文件或目录.
:param from_path: 源文件/目录在网盘中的路径(包括文件名)。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
... | python | def copy(self, from_path, to_path, **kwargs):
"""拷贝文件或目录.
:param from_path: 源文件/目录在网盘中的路径(包括文件名)。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
... | [
"def",
"copy",
"(",
"self",
",",
"from_path",
",",
"to_path",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'from'",
":",
"from_path",
",",
"'to'",
":",
"to_path",
",",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",
",",
"'copy'",
"... | 拷贝文件或目录.
:param from_path: 源文件/目录在网盘中的路径(包括文件名)。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
或空白字符,空白字符包括:
... | [
"拷贝文件或目录",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L387-L417 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.delete | def delete(self, remote_path, **kwargs):
"""删除单个文件或目录.
.. warning::
* 文件/目录删除后默认临时存放在回收站内,删除文件或目录的临时存放
不占用用户的空间配额;
* 存放有效期为10天,10天内可还原回原路径下,10天后则永久删除。
:param remote_path: 网盘中文件/目录的路径,路径必须以 /apps/ 开头。
.. warning::
... | python | def delete(self, remote_path, **kwargs):
"""删除单个文件或目录.
.. warning::
* 文件/目录删除后默认临时存放在回收站内,删除文件或目录的临时存放
不占用用户的空间配额;
* 存放有效期为10天,10天内可还原回原路径下,10天后则永久删除。
:param remote_path: 网盘中文件/目录的路径,路径必须以 /apps/ 开头。
.. warning::
... | [
"def",
"delete",
"(",
"self",
",",
"remote_path",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'path'",
":",
"remote_path",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",
",",
"'delete'",
",",
"data",
"=",
"data",
",",
"*",
"*",
"k... | 删除单个文件或目录.
.. warning::
* 文件/目录删除后默认临时存放在回收站内,删除文件或目录的临时存放
不占用用户的空间配额;
* 存放有效期为10天,10天内可还原回原路径下,10天后则永久删除。
:param remote_path: 网盘中文件/目录的路径,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
... | [
"删除单个文件或目录",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L450-L473 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.multi_delete | def multi_delete(self, path_list, **kwargs):
"""批量删除文件或目录.
.. warning::
* 文件/目录删除后默认临时存放在回收站内,删除文件或目录的临时存放
不占用用户的空间配额;
* 存放有效期为10天,10天内可还原回原路径下,10天后则永久删除。
:param path_list: 网盘中文件/目录的路径列表,路径必须以 /apps/ 开头。
.. warning::
... | python | def multi_delete(self, path_list, **kwargs):
"""批量删除文件或目录.
.. warning::
* 文件/目录删除后默认临时存放在回收站内,删除文件或目录的临时存放
不占用用户的空间配额;
* 存放有效期为10天,10天内可还原回原路径下,10天后则永久删除。
:param path_list: 网盘中文件/目录的路径列表,路径必须以 /apps/ 开头。
.. warning::
... | [
"def",
"multi_delete",
"(",
"self",
",",
"path_list",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'param'",
":",
"json",
".",
"dumps",
"(",
"{",
"'list'",
":",
"[",
"{",
"'path'",
":",
"path",
"}",
"for",
"path",
"in",
"path_list",
"]",
... | 批量删除文件或目录.
.. warning::
* 文件/目录删除后默认临时存放在回收站内,删除文件或目录的临时存放
不占用用户的空间配额;
* 存放有效期为10天,10天内可还原回原路径下,10天后则永久删除。
:param path_list: 网盘中文件/目录的路径列表,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
... | [
"批量删除文件或目录",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L475-L500 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.search | def search(self, remote_path, keyword, recurrent='0', **kwargs):
"""按文件名搜索文件(不支持查找目录).
:param remote_path: 需要检索的目录路径,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
... | python | def search(self, remote_path, keyword, recurrent='0', **kwargs):
"""按文件名搜索文件(不支持查找目录).
:param remote_path: 需要检索的目录路径,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
... | [
"def",
"search",
"(",
"self",
",",
"remote_path",
",",
"keyword",
",",
"recurrent",
"=",
"'0'",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
",",
"'wd'",
":",
"keyword",
",",
"'re'",
":",
"recurrent",
",",
"}",... | 按文件名搜索文件(不支持查找目录).
:param remote_path: 需要检索的目录路径,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
... | [
"按文件名搜索文件(不支持查找目录)",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L502-L529 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.thumbnail | def thumbnail(self, remote_path, height, width, quality=100, **kwargs):
"""获取指定图片文件的缩略图.
:param remote_path: 源图片的路径,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
... | python | def thumbnail(self, remote_path, height, width, quality=100, **kwargs):
"""获取指定图片文件的缩略图.
:param remote_path: 源图片的路径,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
... | [
"def",
"thumbnail",
"(",
"self",
",",
"remote_path",
",",
"height",
",",
"width",
",",
"quality",
"=",
"100",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
",",
"'height'",
":",
"height",
",",
"'width'",
":",
"w... | 获取指定图片文件的缩略图.
:param remote_path: 源图片的路径,路径必须以 /apps/ 开头。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
或空白字符,... | [
"获取指定图片文件的缩略图",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L531-L566 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.diff | def diff(self, cursor='null', **kwargs):
"""文件增量更新操作查询接口.
本接口有数秒延迟,但保证返回结果为最终一致.
:param cursor: 用于标记更新断点。
* 首次调用cursor=null;
* 非首次调用,使用最后一次调用diff接口的返回结果
中的cursor。
:type cursor: str
:return: Response 对象
... | python | def diff(self, cursor='null', **kwargs):
"""文件增量更新操作查询接口.
本接口有数秒延迟,但保证返回结果为最终一致.
:param cursor: 用于标记更新断点。
* 首次调用cursor=null;
* 非首次调用,使用最后一次调用diff接口的返回结果
中的cursor。
:type cursor: str
:return: Response 对象
... | [
"def",
"diff",
"(",
"self",
",",
"cursor",
"=",
"'null'",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'cursor'",
":",
"cursor",
",",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",
",",
"'diff'",
",",
"extra_params",
"=",
"params",... | 文件增量更新操作查询接口.
本接口有数秒延迟,但保证返回结果为最终一致.
:param cursor: 用于标记更新断点。
* 首次调用cursor=null;
* 非首次调用,使用最后一次调用diff接口的返回结果
中的cursor。
:type cursor: str
:return: Response 对象 | [
"文件增量更新操作查询接口",
".",
"本接口有数秒延迟,但保证返回结果为最终一致",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L568-L584 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.video_convert | def video_convert(self, remote_path, video_type, **kwargs):
"""对视频文件进行转码,实现实时观看视频功能.
可下载支持 HLS/M3U8 的 `媒体云播放器 SDK <HLSSDK_>`__ 配合使用.
.. _HLSSDK:
http://developer.baidu.com/wiki/index.php?title=docs/cplat/media/sdk
:param remote_path: 需要下载的视频文件路径,以/开头的绝对路径,
... | python | def video_convert(self, remote_path, video_type, **kwargs):
"""对视频文件进行转码,实现实时观看视频功能.
可下载支持 HLS/M3U8 的 `媒体云播放器 SDK <HLSSDK_>`__ 配合使用.
.. _HLSSDK:
http://developer.baidu.com/wiki/index.php?title=docs/cplat/media/sdk
:param remote_path: 需要下载的视频文件路径,以/开头的绝对路径,
... | [
"def",
"video_convert",
"(",
"self",
",",
"remote_path",
",",
"video_type",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
",",
"'type'",
":",
"video_type",
",",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",... | 对视频文件进行转码,实现实时观看视频功能.
可下载支持 HLS/M3U8 的 `媒体云播放器 SDK <HLSSDK_>`__ 配合使用.
.. _HLSSDK:
http://developer.baidu.com/wiki/index.php?title=docs/cplat/media/sdk
:param remote_path: 需要下载的视频文件路径,以/开头的绝对路径,
需含源文件的文件名。
.. warning::
... | [
"对视频文件进行转码,实现实时观看视频功能",
".",
"可下载支持",
"HLS",
"/",
"M3U8",
"的",
"媒体云播放器",
"SDK",
"<HLSSDK_",
">",
"__",
"配合使用",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L586-L645 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.list_streams | def list_streams(self, file_type, start=0, limit=100,
filter_path=None, **kwargs):
"""以视频、音频、图片及文档四种类型的视图获取所创建应用程序下的
文件列表.
:param file_type: 类型分为video、audio、image及doc四种。
:param start: 返回条目控制起始值,缺省值为0。
:param limit: 返回条目控制长度,缺省为1000,可配置。
:param filter... | python | def list_streams(self, file_type, start=0, limit=100,
filter_path=None, **kwargs):
"""以视频、音频、图片及文档四种类型的视图获取所创建应用程序下的
文件列表.
:param file_type: 类型分为video、audio、image及doc四种。
:param start: 返回条目控制起始值,缺省值为0。
:param limit: 返回条目控制长度,缺省为1000,可配置。
:param filter... | [
"def",
"list_streams",
"(",
"self",
",",
"file_type",
",",
"start",
"=",
"0",
",",
"limit",
"=",
"100",
",",
"filter_path",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'type'",
":",
"file_type",
",",
"'start'",
":",
"start",
... | 以视频、音频、图片及文档四种类型的视图获取所创建应用程序下的
文件列表.
:param file_type: 类型分为video、audio、image及doc四种。
:param start: 返回条目控制起始值,缺省值为0。
:param limit: 返回条目控制长度,缺省为1000,可配置。
:param filter_path: 需要过滤的前缀路径,如:/apps/album
.. warning::
* 路径长度限制为1... | [
"以视频、音频、图片及文档四种类型的视图获取所创建应用程序下的",
"文件列表",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L647-L673 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.download_stream | def download_stream(self, remote_path, **kwargs):
"""为当前用户下载一个流式文件.其参数和返回结果与下载单个文件的相同.
:param remote_path: 需要下载的文件路径,以/开头的绝对路径,含文件名。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
... | python | def download_stream(self, remote_path, **kwargs):
"""为当前用户下载一个流式文件.其参数和返回结果与下载单个文件的相同.
:param remote_path: 需要下载的文件路径,以/开头的绝对路径,含文件名。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
... | [
"def",
"download_stream",
"(",
"self",
",",
"remote_path",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'path'",
":",
"remote_path",
",",
"}",
"url",
"=",
"'https://d.pcs.baidu.com/rest/2.0/pcs/file'",
"return",
"self",
".",
"_request",
"(",
"'strea... | 为当前用户下载一个流式文件.其参数和返回结果与下载单个文件的相同.
:param remote_path: 需要下载的文件路径,以/开头的绝对路径,含文件名。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
... | [
"为当前用户下载一个流式文件",
".",
"其参数和返回结果与下载单个文件的相同",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L675-L694 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.rapid_upload | def rapid_upload(self, remote_path, content_length, content_md5,
content_crc32, slice_md5, ondup=None, **kwargs):
"""秒传一个文件.
.. warning::
* 被秒传文件必须大于256KB(即 256*1024 B)。
* 校验段为文件的前256KB,秒传接口需要提供校验段的MD5。
(非强一致接口,上传后请等待1秒后再读取)
:param remote... | python | def rapid_upload(self, remote_path, content_length, content_md5,
content_crc32, slice_md5, ondup=None, **kwargs):
"""秒传一个文件.
.. warning::
* 被秒传文件必须大于256KB(即 256*1024 B)。
* 校验段为文件的前256KB,秒传接口需要提供校验段的MD5。
(非强一致接口,上传后请等待1秒后再读取)
:param remote... | [
"def",
"rapid_upload",
"(",
"self",
",",
"remote_path",
",",
"content_length",
",",
"content_md5",
",",
"content_crc32",
",",
"slice_md5",
",",
"ondup",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'path'",
":",
"remote_path",
",",
... | 秒传一个文件.
.. warning::
* 被秒传文件必须大于256KB(即 256*1024 B)。
* 校验段为文件的前256KB,秒传接口需要提供校验段的MD5。
(非强一致接口,上传后请等待1秒后再读取)
:param remote_path: 上传文件的全路径名。
.. warning::
* 路径长度限制为1000;
* 径中不能包... | [
"秒传一个文件",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L696-L732 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.add_download_task | def add_download_task(self, source_url, remote_path,
rate_limit=None, timeout=60 * 60,
expires=None, callback='', **kwargs):
"""添加离线下载任务,实现单个文件离线下载.
:param source_url: 源文件的URL。
:param remote_path: 下载后的文件保存路径。
.. wa... | python | def add_download_task(self, source_url, remote_path,
rate_limit=None, timeout=60 * 60,
expires=None, callback='', **kwargs):
"""添加离线下载任务,实现单个文件离线下载.
:param source_url: 源文件的URL。
:param remote_path: 下载后的文件保存路径。
.. wa... | [
"def",
"add_download_task",
"(",
"self",
",",
"source_url",
",",
"remote_path",
",",
"rate_limit",
"=",
"None",
",",
"timeout",
"=",
"60",
"*",
"60",
",",
"expires",
"=",
"None",
",",
"callback",
"=",
"''",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
... | 添加离线下载任务,实现单个文件离线下载.
:param source_url: 源文件的URL。
:param remote_path: 下载后的文件保存路径。
.. warning::
* 路径长度限制为1000;
* 径中不能包含以下字符:``\\\\ ? | " > < : *``;
* 文件名或路径名开头结尾不能是 ``.``
... | [
"添加离线下载任务,实现单个文件离线下载",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L734-L767 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.query_download_tasks | def query_download_tasks(self, task_ids, operate_type=1,
expires=None, **kwargs):
"""根据任务ID号,查询离线下载任务信息及进度信息。
:param task_ids: 要查询的任务ID列表
:type task_ids: list or tuple
:param operate_type:
* 0:查任务信息
* 1... | python | def query_download_tasks(self, task_ids, operate_type=1,
expires=None, **kwargs):
"""根据任务ID号,查询离线下载任务信息及进度信息。
:param task_ids: 要查询的任务ID列表
:type task_ids: list or tuple
:param operate_type:
* 0:查任务信息
* 1... | [
"def",
"query_download_tasks",
"(",
"self",
",",
"task_ids",
",",
"operate_type",
"=",
"1",
",",
"expires",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'task_ids'",
":",
"','",
".",
"join",
"(",
"map",
"(",
"str",
",",
"task_... | 根据任务ID号,查询离线下载任务信息及进度信息。
:param task_ids: 要查询的任务ID列表
:type task_ids: list or tuple
:param operate_type:
* 0:查任务信息
* 1:查进度信息,默认为1
:param expires: 请求失效时间,如果有,则会校验。
:type expires: int
:return: Response 对象 | [
"根据任务ID号,查询离线下载任务信息及进度信息。"
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L769-L789 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.list_download_tasks | def list_download_tasks(self, need_task_info=1, start=0, limit=10, asc=0,
create_time=None, status=None, source_url=None,
remote_path=None, expires=None, **kwargs):
"""查询离线下载任务ID列表及任务信息.
:param need_task_info: 是否需要返回任务信息:
... | python | def list_download_tasks(self, need_task_info=1, start=0, limit=10, asc=0,
create_time=None, status=None, source_url=None,
remote_path=None, expires=None, **kwargs):
"""查询离线下载任务ID列表及任务信息.
:param need_task_info: 是否需要返回任务信息:
... | [
"def",
"list_download_tasks",
"(",
"self",
",",
"need_task_info",
"=",
"1",
",",
"start",
"=",
"0",
",",
"limit",
"=",
"10",
",",
"asc",
"=",
"0",
",",
"create_time",
"=",
"None",
",",
"status",
"=",
"None",
",",
"source_url",
"=",
"None",
",",
"remo... | 查询离线下载任务ID列表及任务信息.
:param need_task_info: 是否需要返回任务信息:
* 0:不需要
* 1:需要,默认为1
:param start: 查询任务起始位置,默认为0。
:param limit: 设定返回任务数量,默认为10。
:param asc:
* 0:降序,默认值
* 1:升序
:param create_... | [
"查询离线下载任务ID列表及任务信息",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L791-L839 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.cancel_download_task | def cancel_download_task(self, task_id, expires=None, **kwargs):
"""取消离线下载任务.
:param task_id: 要取消的任务ID号。
:type task_id: str
:param expires: 请求失效时间,如果有,则会校验。
:type expires: int
:return: Response 对象
"""
data = {
'expires': expires,
... | python | def cancel_download_task(self, task_id, expires=None, **kwargs):
"""取消离线下载任务.
:param task_id: 要取消的任务ID号。
:type task_id: str
:param expires: 请求失效时间,如果有,则会校验。
:type expires: int
:return: Response 对象
"""
data = {
'expires': expires,
... | [
"def",
"cancel_download_task",
"(",
"self",
",",
"task_id",
",",
"expires",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'expires'",
":",
"expires",
",",
"'task_id'",
":",
"task_id",
",",
"}",
"return",
"self",
".",
"_request",
"(... | 取消离线下载任务.
:param task_id: 要取消的任务ID号。
:type task_id: str
:param expires: 请求失效时间,如果有,则会校验。
:type expires: int
:return: Response 对象 | [
"取消离线下载任务",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L841-L856 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.list_recycle_bin | def list_recycle_bin(self, start=0, limit=1000, **kwargs):
"""获取回收站中的文件及目录列表.
:param start: 返回条目的起始值,缺省值为0
:param limit: 返回条目的长度,缺省值为1000
:return: Response 对象
"""
params = {
'start': start,
'limit': limit,
}
return self._request('... | python | def list_recycle_bin(self, start=0, limit=1000, **kwargs):
"""获取回收站中的文件及目录列表.
:param start: 返回条目的起始值,缺省值为0
:param limit: 返回条目的长度,缺省值为1000
:return: Response 对象
"""
params = {
'start': start,
'limit': limit,
}
return self._request('... | [
"def",
"list_recycle_bin",
"(",
"self",
",",
"start",
"=",
"0",
",",
"limit",
"=",
"1000",
",",
"*",
"*",
"kwargs",
")",
":",
"params",
"=",
"{",
"'start'",
":",
"start",
",",
"'limit'",
":",
"limit",
",",
"}",
"return",
"self",
".",
"_request",
"(... | 获取回收站中的文件及目录列表.
:param start: 返回条目的起始值,缺省值为0
:param limit: 返回条目的长度,缺省值为1000
:return: Response 对象 | [
"获取回收站中的文件及目录列表",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L858-L871 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.restore_recycle_bin | def restore_recycle_bin(self, fs_id, **kwargs):
"""还原单个文件或目录(非强一致接口,调用后请sleep 1秒读取).
:param fs_id: 所还原的文件或目录在PCS的临时唯一标识ID。
:type fs_id: str
:return: Response 对象
"""
data = {
'fs_id': fs_id,
}
return self._request('file', 'restore', data=data,... | python | def restore_recycle_bin(self, fs_id, **kwargs):
"""还原单个文件或目录(非强一致接口,调用后请sleep 1秒读取).
:param fs_id: 所还原的文件或目录在PCS的临时唯一标识ID。
:type fs_id: str
:return: Response 对象
"""
data = {
'fs_id': fs_id,
}
return self._request('file', 'restore', data=data,... | [
"def",
"restore_recycle_bin",
"(",
"self",
",",
"fs_id",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'fs_id'",
":",
"fs_id",
",",
"}",
"return",
"self",
".",
"_request",
"(",
"'file'",
",",
"'restore'",
",",
"data",
"=",
"data",
",",
"*",
... | 还原单个文件或目录(非强一致接口,调用后请sleep 1秒读取).
:param fs_id: 所还原的文件或目录在PCS的临时唯一标识ID。
:type fs_id: str
:return: Response 对象 | [
"还原单个文件或目录(非强一致接口,调用后请sleep",
"1秒读取)",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L873-L884 |
mozillazg/baidu-pcs-python-sdk | baidupcs/api.py | PCS.multi_restore_recycle_bin | def multi_restore_recycle_bin(self, fs_ids, **kwargs):
"""批量还原文件或目录(非强一致接口,调用后请sleep1秒 ).
:param fs_ids: 所还原的文件或目录在 PCS 的临时唯一标识 ID 的列表。
:type fs_ids: list or tuple
:return: Response 对象
"""
data = {
'param': json.dumps({
'list': [{'fs_id': fs_... | python | def multi_restore_recycle_bin(self, fs_ids, **kwargs):
"""批量还原文件或目录(非强一致接口,调用后请sleep1秒 ).
:param fs_ids: 所还原的文件或目录在 PCS 的临时唯一标识 ID 的列表。
:type fs_ids: list or tuple
:return: Response 对象
"""
data = {
'param': json.dumps({
'list': [{'fs_id': fs_... | [
"def",
"multi_restore_recycle_bin",
"(",
"self",
",",
"fs_ids",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'param'",
":",
"json",
".",
"dumps",
"(",
"{",
"'list'",
":",
"[",
"{",
"'fs_id'",
":",
"fs_id",
"}",
"for",
"fs_id",
"in",
"fs_ids"... | 批量还原文件或目录(非强一致接口,调用后请sleep1秒 ).
:param fs_ids: 所还原的文件或目录在 PCS 的临时唯一标识 ID 的列表。
:type fs_ids: list or tuple
:return: Response 对象 | [
"批量还原文件或目录(非强一致接口,调用后请sleep1秒",
")",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/api.py#L886-L899 |
mozillazg/baidu-pcs-python-sdk | baidupcs/tools.py | get_new_access_token | def get_new_access_token(refresh_token, client_id, client_secret,
scope=None, **kwargs):
"""使用 Refresh Token 刷新以获得新的 Access Token.
:param refresh_token: 用于刷新 Access Token 用的 Refresh Token;
:param client_id: 应用的 API Key;
:param client_secret: 应用的 Secret Key;
:param scope: 以空... | python | def get_new_access_token(refresh_token, client_id, client_secret,
scope=None, **kwargs):
"""使用 Refresh Token 刷新以获得新的 Access Token.
:param refresh_token: 用于刷新 Access Token 用的 Refresh Token;
:param client_id: 应用的 API Key;
:param client_secret: 应用的 Secret Key;
:param scope: 以空... | [
"def",
"get_new_access_token",
"(",
"refresh_token",
",",
"client_id",
",",
"client_secret",
",",
"scope",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"{",
"'grant_type'",
":",
"'refresh_token'",
",",
"'refresh_token'",
":",
"refresh_token",
"... | 使用 Refresh Token 刷新以获得新的 Access Token.
:param refresh_token: 用于刷新 Access Token 用的 Refresh Token;
:param client_id: 应用的 API Key;
:param client_secret: 应用的 Secret Key;
:param scope: 以空格分隔的权限列表,若不传递此参数,代表请求的数据访问
操作权限与上次获取 Access Token 时一致。通过 Refresh Token
刷新 Access Toke... | [
"使用",
"Refresh",
"Token",
"刷新以获得新的",
"Access",
"Token",
"."
] | train | https://github.com/mozillazg/baidu-pcs-python-sdk/blob/12fe3f13b2ecda8f8bdcc5334c876e934776a5cc/baidupcs/tools.py#L7-L36 |
persandstrom/python-verisure | verisure/session.py | Session.login | def login(self):
""" Login to verisure app api
Login before calling any read or write commands
"""
if os.path.exists(self._cookieFileName):
with open(self._cookieFileName, 'r') as cookieFile:
self._vid = cookieFile.read().strip()
try:
... | python | def login(self):
""" Login to verisure app api
Login before calling any read or write commands
"""
if os.path.exists(self._cookieFileName):
with open(self._cookieFileName, 'r') as cookieFile:
self._vid = cookieFile.read().strip()
try:
... | [
"def",
"login",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"_cookieFileName",
")",
":",
"with",
"open",
"(",
"self",
".",
"_cookieFileName",
",",
"'r'",
")",
"as",
"cookieFile",
":",
"self",
".",
"_vid",
"=",
"... | Login to verisure app api
Login before calling any read or write commands | [
"Login",
"to",
"verisure",
"app",
"api"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L73-L95 |
persandstrom/python-verisure | verisure/session.py | Session._get_installations | def _get_installations(self):
""" Get information about installations """
response = None
for base_url in urls.BASE_URLS:
urls.BASE_URL = base_url
try:
response = requests.get(
urls.get_installations(self._username),
... | python | def _get_installations(self):
""" Get information about installations """
response = None
for base_url in urls.BASE_URLS:
urls.BASE_URL = base_url
try:
response = requests.get(
urls.get_installations(self._username),
... | [
"def",
"_get_installations",
"(",
"self",
")",
":",
"response",
"=",
"None",
"for",
"base_url",
"in",
"urls",
".",
"BASE_URLS",
":",
"urls",
".",
"BASE_URL",
"=",
"base_url",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"get_ins... | Get information about installations | [
"Get",
"information",
"about",
"installations"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L127-L150 |
persandstrom/python-verisure | verisure/session.py | Session.get_overview | def get_overview(self):
""" Get overview for installation """
response = None
try:
response = requests.get(
urls.overview(self._giid),
headers={
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept... | python | def get_overview(self):
""" Get overview for installation """
response = None
try:
response = requests.get(
urls.overview(self._giid),
headers={
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept... | [
"def",
"get_overview",
"(",
"self",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"overview",
"(",
"self",
".",
"_giid",
")",
",",
"headers",
"=",
"{",
"'Accept'",
":",
"'application/json, text/... | Get overview for installation | [
"Get",
"overview",
"for",
"installation"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L160-L174 |
persandstrom/python-verisure | verisure/session.py | Session.set_smartplug_state | def set_smartplug_state(self, device_label, state):
""" Turn on or off smartplug
Args:
device_label (str): Smartplug device label
state (boolean): new status, 'True' or 'False'
"""
response = None
try:
response = requests.post(
... | python | def set_smartplug_state(self, device_label, state):
""" Turn on or off smartplug
Args:
device_label (str): Smartplug device label
state (boolean): new status, 'True' or 'False'
"""
response = None
try:
response = requests.post(
... | [
"def",
"set_smartplug_state",
"(",
"self",
",",
"device_label",
",",
"state",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"urls",
".",
"smartplug",
"(",
"self",
".",
"_giid",
")",
",",
"headers",
"=",
"... | Turn on or off smartplug
Args:
device_label (str): Smartplug device label
state (boolean): new status, 'True' or 'False' | [
"Turn",
"on",
"or",
"off",
"smartplug"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L176-L195 |
persandstrom/python-verisure | verisure/session.py | Session.get_history | def get_history(self, filters=(), pagesize=15, offset=0):
""" Get recent events
Args:
filters (string set): 'ARM', 'DISARM', 'FIRE', 'INTRUSION',
'TECHNICAL', 'SOS', 'WARNING', 'LOCK',
'UNLOCK'
pagesize (int): N... | python | def get_history(self, filters=(), pagesize=15, offset=0):
""" Get recent events
Args:
filters (string set): 'ARM', 'DISARM', 'FIRE', 'INTRUSION',
'TECHNICAL', 'SOS', 'WARNING', 'LOCK',
'UNLOCK'
pagesize (int): N... | [
"def",
"get_history",
"(",
"self",
",",
"filters",
"=",
"(",
")",
",",
"pagesize",
"=",
"15",
",",
"offset",
"=",
"0",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"history",
"(",
"self",... | Get recent events
Args:
filters (string set): 'ARM', 'DISARM', 'FIRE', 'INTRUSION',
'TECHNICAL', 'SOS', 'WARNING', 'LOCK',
'UNLOCK'
pagesize (int): Number of events to display
offset (int): Skip pagesize * o... | [
"Get",
"recent",
"events"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L250-L274 |
persandstrom/python-verisure | verisure/session.py | Session.get_climate | def get_climate(self, device_label):
""" Get climate history
Args:
device_label: device label of climate device
"""
response = None
try:
response = requests.get(
urls.climate(self._giid),
headers={
'Accep... | python | def get_climate(self, device_label):
""" Get climate history
Args:
device_label: device label of climate device
"""
response = None
try:
response = requests.get(
urls.climate(self._giid),
headers={
'Accep... | [
"def",
"get_climate",
"(",
"self",
",",
"device_label",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"climate",
"(",
"self",
".",
"_giid",
")",
",",
"headers",
"=",
"{",
"'Accept'",
":",
"'... | Get climate history
Args:
device_label: device label of climate device | [
"Get",
"climate",
"history",
"Args",
":",
"device_label",
":",
"device",
"label",
"of",
"climate",
"device"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L276-L293 |
persandstrom/python-verisure | verisure/session.py | Session.set_lock_state | def set_lock_state(self, code, device_label, state):
""" Lock or unlock
Args:
code (str): Lock code
device_label (str): device label of lock
state (str): 'lock' or 'unlock'
"""
response = None
try:
response = requests.put(
... | python | def set_lock_state(self, code, device_label, state):
""" Lock or unlock
Args:
code (str): Lock code
device_label (str): device label of lock
state (str): 'lock' or 'unlock'
"""
response = None
try:
response = requests.put(
... | [
"def",
"set_lock_state",
"(",
"self",
",",
"code",
",",
"device_label",
",",
"state",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"put",
"(",
"urls",
".",
"set_lockstate",
"(",
"self",
".",
"_giid",
",",
"device_label... | Lock or unlock
Args:
code (str): Lock code
device_label (str): device label of lock
state (str): 'lock' or 'unlock' | [
"Lock",
"or",
"unlock"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L309-L329 |
persandstrom/python-verisure | verisure/session.py | Session.get_lock_state_transaction | def get_lock_state_transaction(self, transaction_id):
""" Get lock state transaction status
Args:
transaction_id: Transaction ID received from set_lock_state
"""
response = None
try:
response = requests.get(
urls.get_lockstate_transaction(... | python | def get_lock_state_transaction(self, transaction_id):
""" Get lock state transaction status
Args:
transaction_id: Transaction ID received from set_lock_state
"""
response = None
try:
response = requests.get(
urls.get_lockstate_transaction(... | [
"def",
"get_lock_state_transaction",
"(",
"self",
",",
"transaction_id",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"get_lockstate_transaction",
"(",
"self",
".",
"_giid",
",",
"transaction_id",
")... | Get lock state transaction status
Args:
transaction_id: Transaction ID received from set_lock_state | [
"Get",
"lock",
"state",
"transaction",
"status"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L331-L347 |
persandstrom/python-verisure | verisure/session.py | Session.get_lock_config | def get_lock_config(self, device_label):
""" Get lock configuration
Args:
device_label (str): device label of lock
"""
response = None
try:
response = requests.get(
urls.lockconfig(self._giid, device_label),
headers={
... | python | def get_lock_config(self, device_label):
""" Get lock configuration
Args:
device_label (str): device label of lock
"""
response = None
try:
response = requests.get(
urls.lockconfig(self._giid, device_label),
headers={
... | [
"def",
"get_lock_config",
"(",
"self",
",",
"device_label",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"lockconfig",
"(",
"self",
".",
"_giid",
",",
"device_label",
")",
",",
"headers",
"=",
... | Get lock configuration
Args:
device_label (str): device label of lock | [
"Get",
"lock",
"configuration"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L349-L365 |
persandstrom/python-verisure | verisure/session.py | Session.set_lock_config | def set_lock_config(self, device_label, volume=None, voice_level=None,
auto_lock_enabled=None):
""" Set lock configuration
Args:
device_label (str): device label of lock
volume (str): 'SILENCE', 'LOW' or 'HIGH'
voice_level (str): 'ESSENTIAL' o... | python | def set_lock_config(self, device_label, volume=None, voice_level=None,
auto_lock_enabled=None):
""" Set lock configuration
Args:
device_label (str): device label of lock
volume (str): 'SILENCE', 'LOW' or 'HIGH'
voice_level (str): 'ESSENTIAL' o... | [
"def",
"set_lock_config",
"(",
"self",
",",
"device_label",
",",
"volume",
"=",
"None",
",",
"voice_level",
"=",
"None",
",",
"auto_lock_enabled",
"=",
"None",
")",
":",
"response",
"=",
"None",
"data",
"=",
"{",
"}",
"if",
"volume",
":",
"data",
"[",
... | Set lock configuration
Args:
device_label (str): device label of lock
volume (str): 'SILENCE', 'LOW' or 'HIGH'
voice_level (str): 'ESSENTIAL' or 'NORMAL'
auto_lock_enabled (boolean): auto lock enabled | [
"Set",
"lock",
"configuration"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L367-L394 |
persandstrom/python-verisure | verisure/session.py | Session.capture_image | def capture_image(self, device_label):
""" Capture smartcam image
Args:
device_label (str): device label of camera
"""
response = None
try:
response = requests.post(
urls.imagecapture(self._giid, device_label),
headers={
... | python | def capture_image(self, device_label):
""" Capture smartcam image
Args:
device_label (str): device label of camera
"""
response = None
try:
response = requests.post(
urls.imagecapture(self._giid, device_label),
headers={
... | [
"def",
"capture_image",
"(",
"self",
",",
"device_label",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"urls",
".",
"imagecapture",
"(",
"self",
".",
"_giid",
",",
"device_label",
")",
",",
"headers",
"=",... | Capture smartcam image
Args:
device_label (str): device label of camera | [
"Capture",
"smartcam",
"image"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L396-L411 |
persandstrom/python-verisure | verisure/session.py | Session.get_camera_imageseries | def get_camera_imageseries(self, number_of_imageseries=10, offset=0):
""" Get smartcam image series
Args:
number_of_imageseries (int): number of image series to get
offset (int): skip offset amount of image series
"""
response = None
try:
resp... | python | def get_camera_imageseries(self, number_of_imageseries=10, offset=0):
""" Get smartcam image series
Args:
number_of_imageseries (int): number of image series to get
offset (int): skip offset amount of image series
"""
response = None
try:
resp... | [
"def",
"get_camera_imageseries",
"(",
"self",
",",
"number_of_imageseries",
"=",
"10",
",",
"offset",
"=",
"0",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"get_imageseries",
"(",
"self",
".",
... | Get smartcam image series
Args:
number_of_imageseries (int): number of image series to get
offset (int): skip offset amount of image series | [
"Get",
"smartcam",
"image",
"series"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L413-L437 |
persandstrom/python-verisure | verisure/session.py | Session.download_image | def download_image(self, device_label, image_id, file_name):
""" Download image taken by a smartcam
Args:
device_label (str): device label of camera
image_id (str): image id from image series
file_name (str): path to file
"""
response = None
t... | python | def download_image(self, device_label, image_id, file_name):
""" Download image taken by a smartcam
Args:
device_label (str): device label of camera
image_id (str): image id from image series
file_name (str): path to file
"""
response = None
t... | [
"def",
"download_image",
"(",
"self",
",",
"device_label",
",",
"image_id",
",",
"file_name",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"urls",
".",
"download_image",
"(",
"self",
".",
"_giid",
",",
"dev... | Download image taken by a smartcam
Args:
device_label (str): device label of camera
image_id (str): image id from image series
file_name (str): path to file | [
"Download",
"image",
"taken",
"by",
"a",
"smartcam"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L439-L460 |
persandstrom/python-verisure | verisure/session.py | Session.logout | def logout(self):
""" Logout and remove vid """
response = None
try:
response = requests.delete(
urls.login(),
headers={
'Cookie': 'vid={}'.format(self._vid)})
except requests.exceptions.RequestException as ex:
r... | python | def logout(self):
""" Logout and remove vid """
response = None
try:
response = requests.delete(
urls.login(),
headers={
'Cookie': 'vid={}'.format(self._vid)})
except requests.exceptions.RequestException as ex:
r... | [
"def",
"logout",
"(",
"self",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"delete",
"(",
"urls",
".",
"login",
"(",
")",
",",
"headers",
"=",
"{",
"'Cookie'",
":",
"'vid={}'",
".",
"format",
"(",
"self",
".",
"_... | Logout and remove vid | [
"Logout",
"and",
"remove",
"vid"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L503-L513 |
persandstrom/python-verisure | verisure/session.py | Session.set_heat_pump_mode | def set_heat_pump_mode(self, device_label, mode):
""" Set heatpump mode
Args:
mode (str): 'HEAT', 'COOL', 'FAN' or 'AUTO'
"""
response = None
try:
response = requests.put(
urls.set_heatpump_state(self._giid, device_label),
h... | python | def set_heat_pump_mode(self, device_label, mode):
""" Set heatpump mode
Args:
mode (str): 'HEAT', 'COOL', 'FAN' or 'AUTO'
"""
response = None
try:
response = requests.put(
urls.set_heatpump_state(self._giid, device_label),
h... | [
"def",
"set_heat_pump_mode",
"(",
"self",
",",
"device_label",
",",
"mode",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"put",
"(",
"urls",
".",
"set_heatpump_state",
"(",
"self",
".",
"_giid",
",",
"device_label",
")",... | Set heatpump mode
Args:
mode (str): 'HEAT', 'COOL', 'FAN' or 'AUTO' | [
"Set",
"heatpump",
"mode",
"Args",
":",
"mode",
"(",
"str",
")",
":",
"HEAT",
"COOL",
"FAN",
"or",
"AUTO"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L529-L546 |
persandstrom/python-verisure | verisure/session.py | Session.set_heat_pump_feature | def set_heat_pump_feature(self, device_label, feature):
""" Set heatpump mode
Args:
feature: 'QUIET', 'ECONAVI', or 'POWERFUL'
"""
response = None
try:
response = requests.put(
urls.set_heatpump_feature(self._giid, device_label, feature),
... | python | def set_heat_pump_feature(self, device_label, feature):
""" Set heatpump mode
Args:
feature: 'QUIET', 'ECONAVI', or 'POWERFUL'
"""
response = None
try:
response = requests.put(
urls.set_heatpump_feature(self._giid, device_label, feature),
... | [
"def",
"set_heat_pump_feature",
"(",
"self",
",",
"device_label",
",",
"feature",
")",
":",
"response",
"=",
"None",
"try",
":",
"response",
"=",
"requests",
".",
"put",
"(",
"urls",
".",
"set_heatpump_feature",
"(",
"self",
".",
"_giid",
",",
"device_label"... | Set heatpump mode
Args:
feature: 'QUIET', 'ECONAVI', or 'POWERFUL' | [
"Set",
"heatpump",
"mode",
"Args",
":",
"feature",
":",
"QUIET",
"ECONAVI",
"or",
"POWERFUL"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/session.py#L605-L621 |
persandstrom/python-verisure | verisure/__main__.py | print_result | def print_result(overview, *names):
""" Print the result of a verisure request """
if names:
for name in names:
toprint = overview
for part in name.split('/'):
toprint = toprint[part]
print(json.dumps(toprint, indent=4, separators=(',', ': ')))
els... | python | def print_result(overview, *names):
""" Print the result of a verisure request """
if names:
for name in names:
toprint = overview
for part in name.split('/'):
toprint = toprint[part]
print(json.dumps(toprint, indent=4, separators=(',', ': ')))
els... | [
"def",
"print_result",
"(",
"overview",
",",
"*",
"names",
")",
":",
"if",
"names",
":",
"for",
"name",
"in",
"names",
":",
"toprint",
"=",
"overview",
"for",
"part",
"in",
"name",
".",
"split",
"(",
"'/'",
")",
":",
"toprint",
"=",
"toprint",
"[",
... | Print the result of a verisure request | [
"Print",
"the",
"result",
"of",
"a",
"verisure",
"request"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/__main__.py#L22-L31 |
persandstrom/python-verisure | verisure/__main__.py | main | def main():
""" Start verisure command line """
parser = argparse.ArgumentParser(
description='Read or change status of verisure devices')
parser.add_argument(
'username',
help='MyPages username')
parser.add_argument(
'password',
help='MyPages password')
parse... | python | def main():
""" Start verisure command line """
parser = argparse.ArgumentParser(
description='Read or change status of verisure devices')
parser.add_argument(
'username',
help='MyPages username')
parser.add_argument(
'password',
help='MyPages password')
parse... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'Read or change status of verisure devices'",
")",
"parser",
".",
"add_argument",
"(",
"'username'",
",",
"help",
"=",
"'MyPages username'",
")",
"parser",
".... | Start verisure command line | [
"Start",
"verisure",
"command",
"line"
] | train | https://github.com/persandstrom/python-verisure/blob/babd25e7f8fb2b24f12e4109dfa8a04041e8dcb8/verisure/__main__.py#L35-L261 |
django-fluent/django-fluent-contents | fluent_contents/extensions/pluginbase.py | ContentPlugin.type_id | def type_id(self):
"""
Shortcut to retrieving the ContentType id of the model.
"""
try:
return ContentType.objects.get_for_model(self.model, for_concrete_model=False).id
except DatabaseError as e:
raise DatabaseError("Unable to fetch ContentType object, is... | python | def type_id(self):
"""
Shortcut to retrieving the ContentType id of the model.
"""
try:
return ContentType.objects.get_for_model(self.model, for_concrete_model=False).id
except DatabaseError as e:
raise DatabaseError("Unable to fetch ContentType object, is... | [
"def",
"type_id",
"(",
"self",
")",
":",
"try",
":",
"return",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"self",
".",
"model",
",",
"for_concrete_model",
"=",
"False",
")",
".",
"id",
"except",
"DatabaseError",
"as",
"e",
":",
"raise",
"D... | Shortcut to retrieving the ContentType id of the model. | [
"Shortcut",
"to",
"retrieving",
"the",
"ContentType",
"id",
"of",
"the",
"model",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/extensions/pluginbase.py#L291-L298 |
django-fluent/django-fluent-contents | fluent_contents/extensions/pluginbase.py | ContentPlugin.get_output_cache_key | def get_output_cache_key(self, placeholder_name, instance):
"""
.. versionadded:: 0.9
Return the default cache key which is used to store a rendered item.
By default, this function generates the cache key using :func:`get_output_cache_base_key`.
"""
cachekey = self.... | python | def get_output_cache_key(self, placeholder_name, instance):
"""
.. versionadded:: 0.9
Return the default cache key which is used to store a rendered item.
By default, this function generates the cache key using :func:`get_output_cache_base_key`.
"""
cachekey = self.... | [
"def",
"get_output_cache_key",
"(",
"self",
",",
"placeholder_name",
",",
"instance",
")",
":",
"cachekey",
"=",
"self",
".",
"get_output_cache_base_key",
"(",
"placeholder_name",
",",
"instance",
")",
"if",
"self",
".",
"cache_output_per_site",
":",
"cachekey",
"... | .. versionadded:: 0.9
Return the default cache key which is used to store a rendered item.
By default, this function generates the cache key using :func:`get_output_cache_base_key`. | [
"..",
"versionadded",
"::",
"0",
".",
"9",
"Return",
"the",
"default",
"cache",
"key",
"which",
"is",
"used",
"to",
"store",
"a",
"rendered",
"item",
".",
"By",
"default",
"this",
"function",
"generates",
"the",
"cache",
"key",
"using",
":",
"func",
":",... | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/extensions/pluginbase.py#L339-L359 |
django-fluent/django-fluent-contents | fluent_contents/extensions/pluginbase.py | ContentPlugin.get_output_cache_keys | def get_output_cache_keys(self, placeholder_name, instance):
"""
.. versionadded:: 0.9
Return the possible cache keys for a rendered item.
This method should be overwritten when implementing a function :func:`set_cached_output` method
or when implementing a :func:`get_o... | python | def get_output_cache_keys(self, placeholder_name, instance):
"""
.. versionadded:: 0.9
Return the possible cache keys for a rendered item.
This method should be overwritten when implementing a function :func:`set_cached_output` method
or when implementing a :func:`get_o... | [
"def",
"get_output_cache_keys",
"(",
"self",
",",
"placeholder_name",
",",
"instance",
")",
":",
"base_key",
"=",
"self",
".",
"get_output_cache_base_key",
"(",
"placeholder_name",
",",
"instance",
")",
"cachekeys",
"=",
"[",
"base_key",
",",
"]",
"if",
"self",
... | .. versionadded:: 0.9
Return the possible cache keys for a rendered item.
This method should be overwritten when implementing a function :func:`set_cached_output` method
or when implementing a :func:`get_output_cache_key` function.
By default, this function generates the cac... | [
"..",
"versionadded",
"::",
"0",
".",
"9",
"Return",
"the",
"possible",
"cache",
"keys",
"for",
"a",
"rendered",
"item",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/extensions/pluginbase.py#L361-L400 |
django-fluent/django-fluent-contents | fluent_contents/extensions/pluginbase.py | ContentPlugin.get_cached_output | def get_cached_output(self, placeholder_name, instance):
"""
.. versionadded:: 0.9
Return the cached output for a rendered item, or ``None`` if no output is cached.
This method can be overwritten to implement custom caching mechanisms.
By default, this function generate... | python | def get_cached_output(self, placeholder_name, instance):
"""
.. versionadded:: 0.9
Return the cached output for a rendered item, or ``None`` if no output is cached.
This method can be overwritten to implement custom caching mechanisms.
By default, this function generate... | [
"def",
"get_cached_output",
"(",
"self",
",",
"placeholder_name",
",",
"instance",
")",
":",
"cachekey",
"=",
"self",
".",
"get_output_cache_key",
"(",
"placeholder_name",
",",
"instance",
")",
"return",
"cache",
".",
"get",
"(",
"cachekey",
")"
] | .. versionadded:: 0.9
Return the cached output for a rendered item, or ``None`` if no output is cached.
This method can be overwritten to implement custom caching mechanisms.
By default, this function generates the cache key using :func:`get_output_cache_key`
and retrieves t... | [
"..",
"versionadded",
"::",
"0",
".",
"9",
"Return",
"the",
"cached",
"output",
"for",
"a",
"rendered",
"item",
"or",
"None",
"if",
"no",
"output",
"is",
"cached",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/extensions/pluginbase.py#L402-L412 |
django-fluent/django-fluent-contents | fluent_contents/extensions/pluginbase.py | ContentPlugin.set_cached_output | def set_cached_output(self, placeholder_name, instance, output):
"""
.. versionadded:: 0.9
Store the cached output for a rendered item.
This method can be overwritten to implement custom caching mechanisms.
By default, this function generates the cache key using :func:`... | python | def set_cached_output(self, placeholder_name, instance, output):
"""
.. versionadded:: 0.9
Store the cached output for a rendered item.
This method can be overwritten to implement custom caching mechanisms.
By default, this function generates the cache key using :func:`... | [
"def",
"set_cached_output",
"(",
"self",
",",
"placeholder_name",
",",
"instance",
",",
"output",
")",
":",
"cachekey",
"=",
"self",
".",
"get_output_cache_key",
"(",
"placeholder_name",
",",
"instance",
")",
"if",
"self",
".",
"cache_timeout",
"is",
"not",
"D... | .. versionadded:: 0.9
Store the cached output for a rendered item.
This method can be overwritten to implement custom caching mechanisms.
By default, this function generates the cache key using :func:`~fluent_contents.cache.get_rendering_cache_key`
and stores the results in ... | [
"..",
"versionadded",
"::",
"0",
".",
"9",
"Store",
"the",
"cached",
"output",
"for",
"a",
"rendered",
"item",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/extensions/pluginbase.py#L414-L434 |
django-fluent/django-fluent-contents | fluent_contents/extensions/pluginbase.py | ContentPlugin.render | def render(self, request, instance, **kwargs):
"""
The rendering/view function that displays a plugin model instance.
:param instance: An instance of the ``model`` the plugin uses.
:param request: The Django :class:`~django.http.HttpRequest` class containing the request parameters.
... | python | def render(self, request, instance, **kwargs):
"""
The rendering/view function that displays a plugin model instance.
:param instance: An instance of the ``model`` the plugin uses.
:param request: The Django :class:`~django.http.HttpRequest` class containing the request parameters.
... | [
"def",
"render",
"(",
"self",
",",
"request",
",",
"instance",
",",
"*",
"*",
"kwargs",
")",
":",
"render_template",
"=",
"self",
".",
"get_render_template",
"(",
"request",
",",
"instance",
",",
"*",
"*",
"kwargs",
")",
"if",
"not",
"render_template",
"... | The rendering/view function that displays a plugin model instance.
:param instance: An instance of the ``model`` the plugin uses.
:param request: The Django :class:`~django.http.HttpRequest` class containing the request parameters.
:param kwargs: An optional slot for any new parameters.
... | [
"The",
"rendering",
"/",
"view",
"function",
"that",
"displays",
"a",
"plugin",
"model",
"instance",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/extensions/pluginbase.py#L436-L466 |
django-fluent/django-fluent-contents | fluent_contents/extensions/pluginbase.py | ContentPlugin.render_to_string | def render_to_string(self, request, template, context, content_instance=None):
"""
Render a custom template with the :class:`~PluginContext` as context instance.
"""
if not content_instance:
content_instance = PluginContext(request)
content_instance.update(context)
... | python | def render_to_string(self, request, template, context, content_instance=None):
"""
Render a custom template with the :class:`~PluginContext` as context instance.
"""
if not content_instance:
content_instance = PluginContext(request)
content_instance.update(context)
... | [
"def",
"render_to_string",
"(",
"self",
",",
"request",
",",
"template",
",",
"context",
",",
"content_instance",
"=",
"None",
")",
":",
"if",
"not",
"content_instance",
":",
"content_instance",
"=",
"PluginContext",
"(",
"request",
")",
"content_instance",
".",... | Render a custom template with the :class:`~PluginContext` as context instance. | [
"Render",
"a",
"custom",
"template",
"with",
"the",
":",
"class",
":",
"~PluginContext",
"as",
"context",
"instance",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/extensions/pluginbase.py#L468-L476 |
django-fluent/django-fluent-contents | fluent_contents/rendering/media.py | register_frontend_media | def register_frontend_media(request, media):
"""
Add a :class:`~django.forms.Media` class to the current request.
This will be rendered by the ``render_plugin_media`` template tag.
"""
if not hasattr(request, '_fluent_contents_frontend_media'):
request._fluent_contents_frontend_media = Media... | python | def register_frontend_media(request, media):
"""
Add a :class:`~django.forms.Media` class to the current request.
This will be rendered by the ``render_plugin_media`` template tag.
"""
if not hasattr(request, '_fluent_contents_frontend_media'):
request._fluent_contents_frontend_media = Media... | [
"def",
"register_frontend_media",
"(",
"request",
",",
"media",
")",
":",
"if",
"not",
"hasattr",
"(",
"request",
",",
"'_fluent_contents_frontend_media'",
")",
":",
"request",
".",
"_fluent_contents_frontend_media",
"=",
"Media",
"(",
")",
"add_media",
"(",
"requ... | Add a :class:`~django.forms.Media` class to the current request.
This will be rendered by the ``render_plugin_media`` template tag. | [
"Add",
"a",
":",
"class",
":",
"~django",
".",
"forms",
".",
"Media",
"class",
"to",
"the",
"current",
"request",
".",
"This",
"will",
"be",
"rendered",
"by",
"the",
"render_plugin_media",
"template",
"tag",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/rendering/media.py#L6-L14 |
django-fluent/django-fluent-contents | fluent_contents/cache.py | get_rendering_cache_key | def get_rendering_cache_key(placeholder_name, contentitem):
"""
Return a cache key for the content item output.
.. seealso::
The :func:`ContentItem.clear_cache() <fluent_contents.models.ContentItem.clear_cache>` function
can be used to remove the cache keys of a retrieved object.
"""
... | python | def get_rendering_cache_key(placeholder_name, contentitem):
"""
Return a cache key for the content item output.
.. seealso::
The :func:`ContentItem.clear_cache() <fluent_contents.models.ContentItem.clear_cache>` function
can be used to remove the cache keys of a retrieved object.
"""
... | [
"def",
"get_rendering_cache_key",
"(",
"placeholder_name",
",",
"contentitem",
")",
":",
"if",
"not",
"contentitem",
".",
"pk",
":",
"return",
"None",
"return",
"\"contentitem.@{0}.{1}.{2}\"",
".",
"format",
"(",
"placeholder_name",
",",
"contentitem",
".",
"plugin"... | Return a cache key for the content item output.
.. seealso::
The :func:`ContentItem.clear_cache() <fluent_contents.models.ContentItem.clear_cache>` function
can be used to remove the cache keys of a retrieved object. | [
"Return",
"a",
"cache",
"key",
"for",
"the",
"content",
"item",
"output",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/cache.py#L7-L22 |
django-fluent/django-fluent-contents | fluent_contents/cache.py | get_placeholder_cache_key | def get_placeholder_cache_key(placeholder, language_code):
"""
Return a cache key for an existing placeholder object.
This key is used to cache the entire output of a placeholder.
"""
return _get_placeholder_cache_key_for_id(
placeholder.parent_type_id,
placeholder.parent_id,
... | python | def get_placeholder_cache_key(placeholder, language_code):
"""
Return a cache key for an existing placeholder object.
This key is used to cache the entire output of a placeholder.
"""
return _get_placeholder_cache_key_for_id(
placeholder.parent_type_id,
placeholder.parent_id,
... | [
"def",
"get_placeholder_cache_key",
"(",
"placeholder",
",",
"language_code",
")",
":",
"return",
"_get_placeholder_cache_key_for_id",
"(",
"placeholder",
".",
"parent_type_id",
",",
"placeholder",
".",
"parent_id",
",",
"placeholder",
".",
"slot",
",",
"language_code",... | Return a cache key for an existing placeholder object.
This key is used to cache the entire output of a placeholder. | [
"Return",
"a",
"cache",
"key",
"for",
"an",
"existing",
"placeholder",
"object",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/cache.py#L25-L36 |
django-fluent/django-fluent-contents | fluent_contents/cache.py | get_placeholder_cache_key_for_parent | def get_placeholder_cache_key_for_parent(parent_object, placeholder_name, language_code):
"""
Return a cache key for a placeholder.
This key is used to cache the entire output of a placeholder.
"""
parent_type = ContentType.objects.get_for_model(parent_object)
return _get_placeholder_cache_key_... | python | def get_placeholder_cache_key_for_parent(parent_object, placeholder_name, language_code):
"""
Return a cache key for a placeholder.
This key is used to cache the entire output of a placeholder.
"""
parent_type = ContentType.objects.get_for_model(parent_object)
return _get_placeholder_cache_key_... | [
"def",
"get_placeholder_cache_key_for_parent",
"(",
"parent_object",
",",
"placeholder_name",
",",
"language_code",
")",
":",
"parent_type",
"=",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"parent_object",
")",
"return",
"_get_placeholder_cache_key_for_id",
... | Return a cache key for a placeholder.
This key is used to cache the entire output of a placeholder. | [
"Return",
"a",
"cache",
"key",
"for",
"a",
"placeholder",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/cache.py#L39-L51 |
django-fluent/django-fluent-contents | fluent_contents/management/commands/remove_stale_contentitems.py | Command.remove_stale_items | def remove_stale_items(self, stale_cts):
"""
See if there are items that point to a removed model.
"""
stale_ct_ids = list(stale_cts.keys())
items = (ContentItem.objects
.non_polymorphic() # very important, or polymorphic skips them on fetching derived data
... | python | def remove_stale_items(self, stale_cts):
"""
See if there are items that point to a removed model.
"""
stale_ct_ids = list(stale_cts.keys())
items = (ContentItem.objects
.non_polymorphic() # very important, or polymorphic skips them on fetching derived data
... | [
"def",
"remove_stale_items",
"(",
"self",
",",
"stale_cts",
")",
":",
"stale_ct_ids",
"=",
"list",
"(",
"stale_cts",
".",
"keys",
"(",
")",
")",
"items",
"=",
"(",
"ContentItem",
".",
"objects",
".",
"non_polymorphic",
"(",
")",
"# very important, or polymorph... | See if there are items that point to a removed model. | [
"See",
"if",
"there",
"are",
"items",
"that",
"point",
"to",
"a",
"removed",
"model",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/management/commands/remove_stale_contentitems.py#L39-L68 |
django-fluent/django-fluent-contents | fluent_contents/management/commands/remove_stale_contentitems.py | Command.remove_unreferenced_items | def remove_unreferenced_items(self, stale_cts):
"""
See if there are items that no longer point to an existing parent.
"""
stale_ct_ids = list(stale_cts.keys())
parent_types = (ContentItem.objects.order_by()
.exclude(polymorphic_ctype__in=stale_ct_ids)
... | python | def remove_unreferenced_items(self, stale_cts):
"""
See if there are items that no longer point to an existing parent.
"""
stale_ct_ids = list(stale_cts.keys())
parent_types = (ContentItem.objects.order_by()
.exclude(polymorphic_ctype__in=stale_ct_ids)
... | [
"def",
"remove_unreferenced_items",
"(",
"self",
",",
"stale_cts",
")",
":",
"stale_ct_ids",
"=",
"list",
"(",
"stale_cts",
".",
"keys",
"(",
")",
")",
"parent_types",
"=",
"(",
"ContentItem",
".",
"objects",
".",
"order_by",
"(",
")",
".",
"exclude",
"(",... | See if there are items that no longer point to an existing parent. | [
"See",
"if",
"there",
"are",
"items",
"that",
"no",
"longer",
"point",
"to",
"an",
"existing",
"parent",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/management/commands/remove_stale_contentitems.py#L70-L110 |
django-fluent/django-fluent-contents | fluent_contents/admin/genericextensions.py | BaseInitialGenericInlineFormSet.__initial_minus_queryset | def __initial_minus_queryset(self):
"""
Gives all elements from self._initial having a slot value that is not already
in self.get_queryset()
"""
queryset = self.get_queryset()
def initial_not_in_queryset(initial):
for x in queryset:
if x.slot ... | python | def __initial_minus_queryset(self):
"""
Gives all elements from self._initial having a slot value that is not already
in self.get_queryset()
"""
queryset = self.get_queryset()
def initial_not_in_queryset(initial):
for x in queryset:
if x.slot ... | [
"def",
"__initial_minus_queryset",
"(",
"self",
")",
":",
"queryset",
"=",
"self",
".",
"get_queryset",
"(",
")",
"def",
"initial_not_in_queryset",
"(",
"initial",
")",
":",
"for",
"x",
"in",
"queryset",
":",
"if",
"x",
".",
"slot",
"==",
"initial",
"[",
... | Gives all elements from self._initial having a slot value that is not already
in self.get_queryset() | [
"Gives",
"all",
"elements",
"from",
"self",
".",
"_initial",
"having",
"a",
"slot",
"value",
"that",
"is",
"not",
"already",
"in",
"self",
".",
"get_queryset",
"()"
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/admin/genericextensions.py#L60-L74 |
django-fluent/django-fluent-contents | fluent_contents/templatetags/fluent_contents_tags.py | _get_placeholder_arg | def _get_placeholder_arg(arg_name, placeholder):
"""
Validate and return the Placeholder object that the template variable points to.
"""
if placeholder is None:
raise RuntimeWarning(u"placeholder object is None")
elif isinstance(placeholder, Placeholder):
return placeholder
elif... | python | def _get_placeholder_arg(arg_name, placeholder):
"""
Validate and return the Placeholder object that the template variable points to.
"""
if placeholder is None:
raise RuntimeWarning(u"placeholder object is None")
elif isinstance(placeholder, Placeholder):
return placeholder
elif... | [
"def",
"_get_placeholder_arg",
"(",
"arg_name",
",",
"placeholder",
")",
":",
"if",
"placeholder",
"is",
"None",
":",
"raise",
"RuntimeWarning",
"(",
"u\"placeholder object is None\"",
")",
"elif",
"isinstance",
"(",
"placeholder",
",",
"Placeholder",
")",
":",
"r... | Validate and return the Placeholder object that the template variable points to. | [
"Validate",
"and",
"return",
"the",
"Placeholder",
"object",
"that",
"the",
"template",
"variable",
"points",
"to",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/templatetags/fluent_contents_tags.py#L287-L310 |
django-fluent/django-fluent-contents | fluent_contents/templatetags/fluent_contents_tags.py | _split_js | def _split_js(media, domain):
"""
Extract the local or external URLs from a Media object.
"""
# Read internal property without creating new Media instance.
if not media._js:
return ImmutableMedia.empty_instance
needs_local = domain == 'local'
new_js = []
for url in media._js:
... | python | def _split_js(media, domain):
"""
Extract the local or external URLs from a Media object.
"""
# Read internal property without creating new Media instance.
if not media._js:
return ImmutableMedia.empty_instance
needs_local = domain == 'local'
new_js = []
for url in media._js:
... | [
"def",
"_split_js",
"(",
"media",
",",
"domain",
")",
":",
"# Read internal property without creating new Media instance.",
"if",
"not",
"media",
".",
"_js",
":",
"return",
"ImmutableMedia",
".",
"empty_instance",
"needs_local",
"=",
"domain",
"==",
"'local'",
"new_js... | Extract the local or external URLs from a Media object. | [
"Extract",
"the",
"local",
"or",
"external",
"URLs",
"from",
"a",
"Media",
"object",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/templatetags/fluent_contents_tags.py#L382-L399 |
django-fluent/django-fluent-contents | fluent_contents/templatetags/fluent_contents_tags.py | _split_css | def _split_css(media, domain):
"""
Extract the local or external URLs from a Media object.
"""
# Read internal property without creating new Media instance.
if not media._css:
return ImmutableMedia.empty_instance
needs_local = domain == 'local'
new_css = {}
for medium, url in si... | python | def _split_css(media, domain):
"""
Extract the local or external URLs from a Media object.
"""
# Read internal property without creating new Media instance.
if not media._css:
return ImmutableMedia.empty_instance
needs_local = domain == 'local'
new_css = {}
for medium, url in si... | [
"def",
"_split_css",
"(",
"media",
",",
"domain",
")",
":",
"# Read internal property without creating new Media instance.",
"if",
"not",
"media",
".",
"_css",
":",
"return",
"ImmutableMedia",
".",
"empty_instance",
"needs_local",
"=",
"domain",
"==",
"'local'",
"new_... | Extract the local or external URLs from a Media object. | [
"Extract",
"the",
"local",
"or",
"external",
"URLs",
"from",
"a",
"Media",
"object",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/templatetags/fluent_contents_tags.py#L402-L419 |
django-fluent/django-fluent-contents | fluent_contents/templatetags/fluent_contents_tags.py | PagePlaceholderNode.parse | def parse(cls, parser, token):
"""
Parse the node syntax:
.. code-block:: html+django
{% page_placeholder parentobj slotname title="test" role="m" %}
"""
bits, as_var = parse_as_var(parser, token)
tag_name, args, kwargs = parse_token_kwargs(parser, bits, all... | python | def parse(cls, parser, token):
"""
Parse the node syntax:
.. code-block:: html+django
{% page_placeholder parentobj slotname title="test" role="m" %}
"""
bits, as_var = parse_as_var(parser, token)
tag_name, args, kwargs = parse_token_kwargs(parser, bits, all... | [
"def",
"parse",
"(",
"cls",
",",
"parser",
",",
"token",
")",
":",
"bits",
",",
"as_var",
"=",
"parse_as_var",
"(",
"parser",
",",
"token",
")",
"tag_name",
",",
"args",
",",
"kwargs",
"=",
"parse_token_kwargs",
"(",
"parser",
",",
"bits",
",",
"allowe... | Parse the node syntax:
.. code-block:: html+django
{% page_placeholder parentobj slotname title="test" role="m" %} | [
"Parse",
"the",
"node",
"syntax",
":"
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/templatetags/fluent_contents_tags.py#L114-L143 |
django-fluent/django-fluent-contents | fluent_contents/templatetags/fluent_contents_tags.py | PagePlaceholderNode.get_title | def get_title(self):
"""
Return the string literal that is used in the template.
The title is used in the admin screens.
"""
try:
return extract_literal(self.meta_kwargs['title'])
except KeyError:
slot = self.get_slot()
if slot is not N... | python | def get_title(self):
"""
Return the string literal that is used in the template.
The title is used in the admin screens.
"""
try:
return extract_literal(self.meta_kwargs['title'])
except KeyError:
slot = self.get_slot()
if slot is not N... | [
"def",
"get_title",
"(",
"self",
")",
":",
"try",
":",
"return",
"extract_literal",
"(",
"self",
".",
"meta_kwargs",
"[",
"'title'",
"]",
")",
"except",
"KeyError",
":",
"slot",
"=",
"self",
".",
"get_slot",
"(",
")",
"if",
"slot",
"is",
"not",
"None",... | Return the string literal that is used in the template.
The title is used in the admin screens. | [
"Return",
"the",
"string",
"literal",
"that",
"is",
"used",
"in",
"the",
"template",
".",
"The",
"title",
"is",
"used",
"in",
"the",
"admin",
"screens",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/templatetags/fluent_contents_tags.py#L152-L164 |
django-fluent/django-fluent-contents | fluent_contents/utils/templatetags.py | extract_literal | def extract_literal(templatevar):
"""
See if a template FilterExpression holds a literal value.
:type templatevar: django.template.FilterExpression
:rtype: bool|None
"""
# FilterExpression contains another 'var' that either contains a Variable or SafeData object.
if hasattr(templatevar, 'va... | python | def extract_literal(templatevar):
"""
See if a template FilterExpression holds a literal value.
:type templatevar: django.template.FilterExpression
:rtype: bool|None
"""
# FilterExpression contains another 'var' that either contains a Variable or SafeData object.
if hasattr(templatevar, 'va... | [
"def",
"extract_literal",
"(",
"templatevar",
")",
":",
"# FilterExpression contains another 'var' that either contains a Variable or SafeData object.",
"if",
"hasattr",
"(",
"templatevar",
",",
"'var'",
")",
":",
"templatevar",
"=",
"templatevar",
".",
"var",
"if",
"isinst... | See if a template FilterExpression holds a literal value.
:type templatevar: django.template.FilterExpression
:rtype: bool|None | [
"See",
"if",
"a",
"template",
"FilterExpression",
"holds",
"a",
"literal",
"value",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/utils/templatetags.py#L11-L31 |
django-fluent/django-fluent-contents | fluent_contents/utils/templatetags.py | extract_literal_bool | def extract_literal_bool(templatevar):
"""
See if a template FilterExpression holds a literal boolean value.
:type templatevar: django.template.FilterExpression
:rtype: bool|None
"""
# FilterExpression contains another 'var' that either contains a Variable or SafeData object.
if hasattr(tem... | python | def extract_literal_bool(templatevar):
"""
See if a template FilterExpression holds a literal boolean value.
:type templatevar: django.template.FilterExpression
:rtype: bool|None
"""
# FilterExpression contains another 'var' that either contains a Variable or SafeData object.
if hasattr(tem... | [
"def",
"extract_literal_bool",
"(",
"templatevar",
")",
":",
"# FilterExpression contains another 'var' that either contains a Variable or SafeData object.",
"if",
"hasattr",
"(",
"templatevar",
",",
"'var'",
")",
":",
"templatevar",
"=",
"templatevar",
".",
"var",
"if",
"i... | See if a template FilterExpression holds a literal boolean value.
:type templatevar: django.template.FilterExpression
:rtype: bool|None | [
"See",
"if",
"a",
"template",
"FilterExpression",
"holds",
"a",
"literal",
"boolean",
"value",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/utils/templatetags.py#L34-L51 |
django-fluent/django-fluent-contents | fluent_contents/plugins/markup/content_plugins.py | _create_markup_plugin | def _create_markup_plugin(language, model):
"""
Create a new MarkupPlugin class that represents the plugin type.
"""
form = type("{0}MarkupItemForm".format(language.capitalize()), (MarkupItemForm,), {
'default_language': language,
})
classname = "{0}MarkupPlugin".format(language.capital... | python | def _create_markup_plugin(language, model):
"""
Create a new MarkupPlugin class that represents the plugin type.
"""
form = type("{0}MarkupItemForm".format(language.capitalize()), (MarkupItemForm,), {
'default_language': language,
})
classname = "{0}MarkupPlugin".format(language.capital... | [
"def",
"_create_markup_plugin",
"(",
"language",
",",
"model",
")",
":",
"form",
"=",
"type",
"(",
"\"{0}MarkupItemForm\"",
".",
"format",
"(",
"language",
".",
"capitalize",
"(",
")",
")",
",",
"(",
"MarkupItemForm",
",",
")",
",",
"{",
"'default_language'"... | Create a new MarkupPlugin class that represents the plugin type. | [
"Create",
"a",
"new",
"MarkupPlugin",
"class",
"that",
"represents",
"the",
"plugin",
"type",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/plugins/markup/content_plugins.py#L43-L57 |
django-fluent/django-fluent-contents | fluent_contents/models/managers.py | get_parent_lookup_kwargs | def get_parent_lookup_kwargs(parent_object):
"""
Return lookup arguments for the generic ``parent_type`` / ``parent_id`` fields.
:param parent_object: The parent object.
:type parent_object: :class:`~django.db.models.Model`
"""
if parent_object is None:
return dict(
parent_t... | python | def get_parent_lookup_kwargs(parent_object):
"""
Return lookup arguments for the generic ``parent_type`` / ``parent_id`` fields.
:param parent_object: The parent object.
:type parent_object: :class:`~django.db.models.Model`
"""
if parent_object is None:
return dict(
parent_t... | [
"def",
"get_parent_lookup_kwargs",
"(",
"parent_object",
")",
":",
"if",
"parent_object",
"is",
"None",
":",
"return",
"dict",
"(",
"parent_type__isnull",
"=",
"True",
",",
"parent_id",
"=",
"0",
")",
"elif",
"isinstance",
"(",
"parent_object",
",",
"models",
... | Return lookup arguments for the generic ``parent_type`` / ``parent_id`` fields.
:param parent_object: The parent object.
:type parent_object: :class:`~django.db.models.Model` | [
"Return",
"lookup",
"arguments",
"for",
"the",
"generic",
"parent_type",
"/",
"parent_id",
"fields",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/models/managers.py#L201-L219 |
django-fluent/django-fluent-contents | fluent_contents/models/managers.py | get_parent_active_language_choices | def get_parent_active_language_choices(parent_object, exclude_current=False):
"""
.. versionadded:: 1.0
Get the currently active languages of an parent object.
Note: if there is no content at the page, the language won't be returned.
"""
assert parent_object is not None, "Missing parent_object... | python | def get_parent_active_language_choices(parent_object, exclude_current=False):
"""
.. versionadded:: 1.0
Get the currently active languages of an parent object.
Note: if there is no content at the page, the language won't be returned.
"""
assert parent_object is not None, "Missing parent_object... | [
"def",
"get_parent_active_language_choices",
"(",
"parent_object",
",",
"exclude_current",
"=",
"False",
")",
":",
"assert",
"parent_object",
"is",
"not",
"None",
",",
"\"Missing parent_object!\"",
"from",
".",
"db",
"import",
"ContentItem",
"qs",
"=",
"ContentItem",
... | .. versionadded:: 1.0
Get the currently active languages of an parent object.
Note: if there is no content at the page, the language won't be returned. | [
"..",
"versionadded",
"::",
"1",
".",
"0"
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/models/managers.py#L248-L282 |
django-fluent/django-fluent-contents | fluent_contents/models/managers.py | PlaceholderManager.get_by_slot | def get_by_slot(self, parent_object, slot):
"""
Return a placeholder by key.
"""
placeholder = self.parent(parent_object).get(slot=slot)
placeholder.parent = parent_object # fill the reverse cache
return placeholder | python | def get_by_slot(self, parent_object, slot):
"""
Return a placeholder by key.
"""
placeholder = self.parent(parent_object).get(slot=slot)
placeholder.parent = parent_object # fill the reverse cache
return placeholder | [
"def",
"get_by_slot",
"(",
"self",
",",
"parent_object",
",",
"slot",
")",
":",
"placeholder",
"=",
"self",
".",
"parent",
"(",
"parent_object",
")",
".",
"get",
"(",
"slot",
"=",
"slot",
")",
"placeholder",
".",
"parent",
"=",
"parent_object",
"# fill the... | Return a placeholder by key. | [
"Return",
"a",
"placeholder",
"by",
"key",
"."
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/models/managers.py#L28-L34 |
django-fluent/django-fluent-contents | fluent_contents/models/managers.py | PlaceholderManager.create_for_object | def create_for_object(self, parent_object, slot, role='m', title=None):
"""
Create a placeholder with the given parameters
"""
from .db import Placeholder
parent_attrs = get_parent_lookup_kwargs(parent_object)
obj = self.create(
slot=slot,
role=rol... | python | def create_for_object(self, parent_object, slot, role='m', title=None):
"""
Create a placeholder with the given parameters
"""
from .db import Placeholder
parent_attrs = get_parent_lookup_kwargs(parent_object)
obj = self.create(
slot=slot,
role=rol... | [
"def",
"create_for_object",
"(",
"self",
",",
"parent_object",
",",
"slot",
",",
"role",
"=",
"'m'",
",",
"title",
"=",
"None",
")",
":",
"from",
".",
"db",
"import",
"Placeholder",
"parent_attrs",
"=",
"get_parent_lookup_kwargs",
"(",
"parent_object",
")",
... | Create a placeholder with the given parameters | [
"Create",
"a",
"placeholder",
"with",
"the",
"given",
"parameters"
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/models/managers.py#L36-L49 |
django-fluent/django-fluent-contents | fluent_contents/models/managers.py | ContentItemQuerySet.translated | def translated(self, *language_codes):
"""
.. versionadded:: 1.0
Only return translated objects which of the given languages.
When no language codes are given, only the currently active language is returned.
"""
# this API has the same semantics as django-parler's .tran... | python | def translated(self, *language_codes):
"""
.. versionadded:: 1.0
Only return translated objects which of the given languages.
When no language codes are given, only the currently active language is returned.
"""
# this API has the same semantics as django-parler's .tran... | [
"def",
"translated",
"(",
"self",
",",
"*",
"language_codes",
")",
":",
"# this API has the same semantics as django-parler's .translated() for familiarity.",
"# However, since this package doesn't filter in a related field, the ORM limitations don't apply.",
"if",
"not",
"language_codes",... | .. versionadded:: 1.0
Only return translated objects which of the given languages.
When no language codes are given, only the currently active language is returned. | [
"..",
"versionadded",
"::",
"1",
".",
"0"
] | train | https://github.com/django-fluent/django-fluent-contents/blob/896f14add58471b98d7aa295b2c9e6abedec9003/fluent_contents/models/managers.py#L57-L78 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.