id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
43,800 | havardgulldahl/jottalib | src/jottalib/JFS.py | JFSDevice.new_mountpoint | def new_mountpoint(self, name):
"""Create a new mountpoint"""
url = posixpath.join(self.path, name)
r = self._jfs.post(url, extra_headers={'content-type': 'application/x-www-form-urlencoded'})
return r | python | def new_mountpoint(self, name):
"""Create a new mountpoint"""
url = posixpath.join(self.path, name)
r = self._jfs.post(url, extra_headers={'content-type': 'application/x-www-form-urlencoded'})
return r | [
"def",
"new_mountpoint",
"(",
"self",
",",
"name",
")",
":",
"url",
"=",
"posixpath",
".",
"join",
"(",
"self",
".",
"path",
",",
"name",
")",
"r",
"=",
"self",
".",
"_jfs",
".",
"post",
"(",
"url",
",",
"extra_headers",
"=",
"{",
"'content-type'",
... | Create a new mountpoint | [
"Create",
"a",
"new",
"mountpoint"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L848-L852 |
43,801 | havardgulldahl/jottalib | src/jottalib/JFS.py | JFSenableSharing.sharedFiles | def sharedFiles(self):
'iterate over shared files and get their public URI'
for f in self.sharing.files.iterchildren():
yield (f.attrib['name'], f.attrib['uuid'],
'https://www.jottacloud.com/p/%s/%s' % (self.jfs.username, f.publicURI.text)) | python | def sharedFiles(self):
'iterate over shared files and get their public URI'
for f in self.sharing.files.iterchildren():
yield (f.attrib['name'], f.attrib['uuid'],
'https://www.jottacloud.com/p/%s/%s' % (self.jfs.username, f.publicURI.text)) | [
"def",
"sharedFiles",
"(",
"self",
")",
":",
"for",
"f",
"in",
"self",
".",
"sharing",
".",
"files",
".",
"iterchildren",
"(",
")",
":",
"yield",
"(",
"f",
".",
"attrib",
"[",
"'name'",
"]",
",",
"f",
".",
"attrib",
"[",
"'uuid'",
"]",
",",
"'htt... | iterate over shared files and get their public URI | [
"iterate",
"over",
"shared",
"files",
"and",
"get",
"their",
"public",
"URI"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L904-L908 |
43,802 | havardgulldahl/jottalib | src/jottalib/JFS.py | JFSsearchresult.files | def files(self):
'iterate over found files'
for _f in self.searchresult.files.iterchildren():
yield ProtoFile.factory(_f, jfs=self.jfs, parentpath=unicode(_f.abspath)) | python | def files(self):
'iterate over found files'
for _f in self.searchresult.files.iterchildren():
yield ProtoFile.factory(_f, jfs=self.jfs, parentpath=unicode(_f.abspath)) | [
"def",
"files",
"(",
"self",
")",
":",
"for",
"_f",
"in",
"self",
".",
"searchresult",
".",
"files",
".",
"iterchildren",
"(",
")",
":",
"yield",
"ProtoFile",
".",
"factory",
"(",
"_f",
",",
"jfs",
"=",
"self",
".",
"jfs",
",",
"parentpath",
"=",
"... | iterate over found files | [
"iterate",
"over",
"found",
"files"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L940-L943 |
43,803 | havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.request | def request(self, url, extra_headers=None, params=None):
'Make a GET request for url, with or without caching'
if not url.startswith('http'):
# relative url
url = self.rootpath + url
log.debug("getting url: %r, extra_headers=%r, params=%r", url, extra_headers, params)
... | python | def request(self, url, extra_headers=None, params=None):
'Make a GET request for url, with or without caching'
if not url.startswith('http'):
# relative url
url = self.rootpath + url
log.debug("getting url: %r, extra_headers=%r, params=%r", url, extra_headers, params)
... | [
"def",
"request",
"(",
"self",
",",
"url",
",",
"extra_headers",
"=",
"None",
",",
"params",
"=",
"None",
")",
":",
"if",
"not",
"url",
".",
"startswith",
"(",
"'http'",
")",
":",
"# relative url",
"url",
"=",
"self",
".",
"rootpath",
"+",
"url",
"lo... | Make a GET request for url, with or without caching | [
"Make",
"a",
"GET",
"request",
"for",
"url",
"with",
"or",
"without",
"caching"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L973-L984 |
43,804 | havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.raw | def raw(self, url, extra_headers=None, params=None):
'Make a GET request for url and return whatever content we get'
r = self.request(url, extra_headers=extra_headers, params=params)
# uncomment to dump raw xml
# with open('/tmp/%s.xml' % time.time(), 'wb') as f:
# f.write(r.... | python | def raw(self, url, extra_headers=None, params=None):
'Make a GET request for url and return whatever content we get'
r = self.request(url, extra_headers=extra_headers, params=params)
# uncomment to dump raw xml
# with open('/tmp/%s.xml' % time.time(), 'wb') as f:
# f.write(r.... | [
"def",
"raw",
"(",
"self",
",",
"url",
",",
"extra_headers",
"=",
"None",
",",
"params",
"=",
"None",
")",
":",
"r",
"=",
"self",
".",
"request",
"(",
"url",
",",
"extra_headers",
"=",
"extra_headers",
",",
"params",
"=",
"params",
")",
"# uncomment to... | Make a GET request for url and return whatever content we get | [
"Make",
"a",
"GET",
"request",
"for",
"url",
"and",
"return",
"whatever",
"content",
"we",
"get"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L986-L996 |
43,805 | havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.get | def get(self, url, params=None):
'Make a GET request for url and return the response content as a generic lxml.objectify object'
url = self.escapeUrl(url)
content = six.BytesIO(self.raw(url, params=params))
# We need to make sure that the xml fits in available memory before we parse
... | python | def get(self, url, params=None):
'Make a GET request for url and return the response content as a generic lxml.objectify object'
url = self.escapeUrl(url)
content = six.BytesIO(self.raw(url, params=params))
# We need to make sure that the xml fits in available memory before we parse
... | [
"def",
"get",
"(",
"self",
",",
"url",
",",
"params",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"escapeUrl",
"(",
"url",
")",
"content",
"=",
"six",
".",
"BytesIO",
"(",
"self",
".",
"raw",
"(",
"url",
",",
"params",
"=",
"params",
")",
"... | Make a GET request for url and return the response content as a generic lxml.objectify object | [
"Make",
"a",
"GET",
"request",
"for",
"url",
"and",
"return",
"the",
"response",
"content",
"as",
"a",
"generic",
"lxml",
".",
"objectify",
"object"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L998-L1022 |
43,806 | havardgulldahl/jottalib | src/jottalib/JFS.py | JFS.devices | def devices(self):
'return generator of configured devices'
return self.fs is not None and [JFSDevice(d, self, parentpath=self.rootpath) for d in self.fs.devices.iterchildren()] or [x for x in []] | python | def devices(self):
'return generator of configured devices'
return self.fs is not None and [JFSDevice(d, self, parentpath=self.rootpath) for d in self.fs.devices.iterchildren()] or [x for x in []] | [
"def",
"devices",
"(",
"self",
")",
":",
"return",
"self",
".",
"fs",
"is",
"not",
"None",
"and",
"[",
"JFSDevice",
"(",
"d",
",",
"self",
",",
"parentpath",
"=",
"self",
".",
"rootpath",
")",
"for",
"d",
"in",
"self",
".",
"fs",
".",
"devices",
... | return generator of configured devices | [
"return",
"generator",
"of",
"configured",
"devices"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/JFS.py#L1194-L1196 |
43,807 | astropy/pyregion | pyregion/core.py | parse | def parse(region_string):
"""Parse DS9 region string into a ShapeList.
Parameters
----------
region_string : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(region_string)
sss1 = rp.conve... | python | def parse(region_string):
"""Parse DS9 region string into a ShapeList.
Parameters
----------
region_string : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(region_string)
sss1 = rp.conve... | [
"def",
"parse",
"(",
"region_string",
")",
":",
"rp",
"=",
"RegionParser",
"(",
")",
"ss",
"=",
"rp",
".",
"parse",
"(",
"region_string",
")",
"sss1",
"=",
"rp",
".",
"convert_attr",
"(",
"ss",
")",
"sss2",
"=",
"_check_wcs",
"(",
"sss1",
")",
"shape... | Parse DS9 region string into a ShapeList.
Parameters
----------
region_string : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape` | [
"Parse",
"DS9",
"region",
"string",
"into",
"a",
"ShapeList",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L223-L242 |
43,808 | astropy/pyregion | pyregion/core.py | open | def open(fname):
"""Open, read and parse DS9 region file.
Parameters
----------
fname : str
Filename
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
with _builtin_open(fname) as fh:
region_string = fh.read()
return parse(region_string) | python | def open(fname):
"""Open, read and parse DS9 region file.
Parameters
----------
fname : str
Filename
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
with _builtin_open(fname) as fh:
region_string = fh.read()
return parse(region_string) | [
"def",
"open",
"(",
"fname",
")",
":",
"with",
"_builtin_open",
"(",
"fname",
")",
"as",
"fh",
":",
"region_string",
"=",
"fh",
".",
"read",
"(",
")",
"return",
"parse",
"(",
"region_string",
")"
] | Open, read and parse DS9 region file.
Parameters
----------
fname : str
Filename
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape` | [
"Open",
"read",
"and",
"parse",
"DS9",
"region",
"file",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L245-L260 |
43,809 | astropy/pyregion | pyregion/core.py | read_region | def read_region(s):
"""Read region.
Parameters
----------
s : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(s)
sss1 = rp.convert_attr(ss)
sss2 = _check_wcs(sss1)
shape_list = r... | python | def read_region(s):
"""Read region.
Parameters
----------
s : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape`
"""
rp = RegionParser()
ss = rp.parse(s)
sss1 = rp.convert_attr(ss)
sss2 = _check_wcs(sss1)
shape_list = r... | [
"def",
"read_region",
"(",
"s",
")",
":",
"rp",
"=",
"RegionParser",
"(",
")",
"ss",
"=",
"rp",
".",
"parse",
"(",
"s",
")",
"sss1",
"=",
"rp",
".",
"convert_attr",
"(",
"ss",
")",
"sss2",
"=",
"_check_wcs",
"(",
"sss1",
")",
"shape_list",
"=",
"... | Read region.
Parameters
----------
s : str
Region string
Returns
-------
shapes : `ShapeList`
List of `~pyregion.Shape` | [
"Read",
"region",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L263-L282 |
43,810 | astropy/pyregion | pyregion/core.py | read_region_as_imagecoord | def read_region_as_imagecoord(s, header):
"""Read region as image coordinates.
Parameters
----------
s : str
Region string
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shapes : `~pyregion.ShapeList`
List of `~pyregion.Shape`
"""
rp = Re... | python | def read_region_as_imagecoord(s, header):
"""Read region as image coordinates.
Parameters
----------
s : str
Region string
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shapes : `~pyregion.ShapeList`
List of `~pyregion.Shape`
"""
rp = Re... | [
"def",
"read_region_as_imagecoord",
"(",
"s",
",",
"header",
")",
":",
"rp",
"=",
"RegionParser",
"(",
")",
"ss",
"=",
"rp",
".",
"parse",
"(",
"s",
")",
"sss1",
"=",
"rp",
".",
"convert_attr",
"(",
"ss",
")",
"sss2",
"=",
"_check_wcs",
"(",
"sss1",
... | Read region as image coordinates.
Parameters
----------
s : str
Region string
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shapes : `~pyregion.ShapeList`
List of `~pyregion.Shape` | [
"Read",
"region",
"as",
"image",
"coordinates",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L285-L307 |
43,811 | astropy/pyregion | pyregion/core.py | get_mask | def get_mask(region, hdu, origin=1):
"""Get mask.
Parameters
----------
region : `~pyregion.ShapeList`
List of `~pyregion.Shape`
hdu : `~astropy.io.fits.ImageHDU`
FITS image HDU
origin : float
TODO: document me
Returns
-------
mask : `~numpy.array`
B... | python | def get_mask(region, hdu, origin=1):
"""Get mask.
Parameters
----------
region : `~pyregion.ShapeList`
List of `~pyregion.Shape`
hdu : `~astropy.io.fits.ImageHDU`
FITS image HDU
origin : float
TODO: document me
Returns
-------
mask : `~numpy.array`
B... | [
"def",
"get_mask",
"(",
"region",
",",
"hdu",
",",
"origin",
"=",
"1",
")",
":",
"from",
"pyregion",
".",
"region_to_filter",
"import",
"as_region_filter",
"data",
"=",
"hdu",
".",
"data",
"region_filter",
"=",
"as_region_filter",
"(",
"region",
",",
"origin... | Get mask.
Parameters
----------
region : `~pyregion.ShapeList`
List of `~pyregion.Shape`
hdu : `~astropy.io.fits.ImageHDU`
FITS image HDU
origin : float
TODO: document me
Returns
-------
mask : `~numpy.array`
Boolean mask
Examples
--------
>... | [
"Get",
"mask",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L310-L341 |
43,812 | astropy/pyregion | pyregion/core.py | ShapeList.as_imagecoord | def as_imagecoord(self, header):
"""New shape list in image coordinates.
Parameters
----------
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shape_list : `ShapeList`
New shape list, with coordinates of the each shape
... | python | def as_imagecoord(self, header):
"""New shape list in image coordinates.
Parameters
----------
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shape_list : `ShapeList`
New shape list, with coordinates of the each shape
... | [
"def",
"as_imagecoord",
"(",
"self",
",",
"header",
")",
":",
"comment_list",
"=",
"self",
".",
"_comment_list",
"if",
"comment_list",
"is",
"None",
":",
"comment_list",
"=",
"cycle",
"(",
"[",
"None",
"]",
")",
"r",
"=",
"RegionParser",
".",
"sky_to_image... | New shape list in image coordinates.
Parameters
----------
header : `~astropy.io.fits.Header`
FITS header
Returns
-------
shape_list : `ShapeList`
New shape list, with coordinates of the each shape
converted to the image coordinate us... | [
"New",
"shape",
"list",
"in",
"image",
"coordinates",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L48-L71 |
43,813 | astropy/pyregion | pyregion/core.py | ShapeList.get_mask | def get_mask(self, hdu=None, header=None, shape=None):
"""Create a 2-d mask.
Parameters
----------
hdu : `astropy.io.fits.ImageHDU`
FITS image HDU
header : `~astropy.io.fits.Header`
FITS header
shape : tuple
Image shape
Return... | python | def get_mask(self, hdu=None, header=None, shape=None):
"""Create a 2-d mask.
Parameters
----------
hdu : `astropy.io.fits.ImageHDU`
FITS image HDU
header : `~astropy.io.fits.Header`
FITS header
shape : tuple
Image shape
Return... | [
"def",
"get_mask",
"(",
"self",
",",
"hdu",
"=",
"None",
",",
"header",
"=",
"None",
",",
"shape",
"=",
"None",
")",
":",
"if",
"hdu",
"and",
"header",
"is",
"None",
":",
"header",
"=",
"hdu",
".",
"header",
"if",
"hdu",
"and",
"shape",
"is",
"No... | Create a 2-d mask.
Parameters
----------
hdu : `astropy.io.fits.ImageHDU`
FITS image HDU
header : `~astropy.io.fits.Header`
FITS header
shape : tuple
Image shape
Returns
-------
mask : `numpy.array`
Boolean... | [
"Create",
"a",
"2",
"-",
"d",
"mask",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L126-L158 |
43,814 | astropy/pyregion | pyregion/core.py | ShapeList.write | def write(self, outfile):
"""Write this shape list to a region file.
Parameters
----------
outfile : str
File name
"""
if len(self) < 1:
print("WARNING: The region list is empty. The region file "
"'{:s}' will be empty.".format(o... | python | def write(self, outfile):
"""Write this shape list to a region file.
Parameters
----------
outfile : str
File name
"""
if len(self) < 1:
print("WARNING: The region list is empty. The region file "
"'{:s}' will be empty.".format(o... | [
"def",
"write",
"(",
"self",
",",
"outfile",
")",
":",
"if",
"len",
"(",
"self",
")",
"<",
"1",
":",
"print",
"(",
"\"WARNING: The region list is empty. The region file \"",
"\"'{:s}' will be empty.\"",
".",
"format",
"(",
"outfile",
")",
")",
"try",
":",
"out... | Write this shape list to a region file.
Parameters
----------
outfile : str
File name | [
"Write",
"this",
"shape",
"list",
"to",
"a",
"region",
"file",
"."
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/core.py#L160-L220 |
43,815 | trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | AppConfigFlagHandler | def AppConfigFlagHandler(feature=None):
""" This is the default handler. It checks for feature flags in the current app's configuration.
For example, to have 'unfinished_feature' hidden in production but active in development:
config.py
class ProductionConfig(Config):
FEATURE_FLAGS = {
'unfinished... | python | def AppConfigFlagHandler(feature=None):
""" This is the default handler. It checks for feature flags in the current app's configuration.
For example, to have 'unfinished_feature' hidden in production but active in development:
config.py
class ProductionConfig(Config):
FEATURE_FLAGS = {
'unfinished... | [
"def",
"AppConfigFlagHandler",
"(",
"feature",
"=",
"None",
")",
":",
"if",
"not",
"current_app",
":",
"log",
".",
"warn",
"(",
"u\"Got a request to check for {feature} but we're outside the request context. Returning False\"",
".",
"format",
"(",
"feature",
"=",
"feature... | This is the default handler. It checks for feature flags in the current app's configuration.
For example, to have 'unfinished_feature' hidden in production but active in development:
config.py
class ProductionConfig(Config):
FEATURE_FLAGS = {
'unfinished_feature' : False,
}
class Development... | [
"This",
"is",
"the",
"default",
"handler",
".",
"It",
"checks",
"for",
"feature",
"flags",
"in",
"the",
"current",
"app",
"s",
"configuration",
"."
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L48-L76 |
43,816 | trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | is_active | def is_active(feature):
""" Check if a feature is active """
if current_app:
feature_flagger = current_app.extensions.get(EXTENSION_NAME)
if feature_flagger:
return feature_flagger.check(feature)
else:
raise AssertionError("Oops. This application doesn't have the Flask-FeatureFlag extention... | python | def is_active(feature):
""" Check if a feature is active """
if current_app:
feature_flagger = current_app.extensions.get(EXTENSION_NAME)
if feature_flagger:
return feature_flagger.check(feature)
else:
raise AssertionError("Oops. This application doesn't have the Flask-FeatureFlag extention... | [
"def",
"is_active",
"(",
"feature",
")",
":",
"if",
"current_app",
":",
"feature_flagger",
"=",
"current_app",
".",
"extensions",
".",
"get",
"(",
"EXTENSION_NAME",
")",
"if",
"feature_flagger",
":",
"return",
"feature_flagger",
".",
"check",
"(",
"feature",
"... | Check if a feature is active | [
"Check",
"if",
"a",
"feature",
"is",
"active"
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L150-L162 |
43,817 | trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | is_active_feature | def is_active_feature(feature, redirect_to=None, redirect=None):
"""
Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather.
"""
def _is_active_feature(func):
@wraps(func)
def wrapped(*args, **kwargs):
if not is_active(feature):
url... | python | def is_active_feature(feature, redirect_to=None, redirect=None):
"""
Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather.
"""
def _is_active_feature(func):
@wraps(func)
def wrapped(*args, **kwargs):
if not is_active(feature):
url... | [
"def",
"is_active_feature",
"(",
"feature",
",",
"redirect_to",
"=",
"None",
",",
"redirect",
"=",
"None",
")",
":",
"def",
"_is_active_feature",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
... | Decorator for Flask views. If a feature is off, it can either return a 404 or redirect to a URL if you'd rather. | [
"Decorator",
"for",
"Flask",
"views",
".",
"If",
"a",
"feature",
"is",
"off",
"it",
"can",
"either",
"return",
"a",
"404",
"or",
"redirect",
"to",
"a",
"URL",
"if",
"you",
"d",
"rather",
"."
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L165-L187 |
43,818 | trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | FeatureFlag.init_app | def init_app(self, app):
""" Add ourselves into the app config and setup, and add a jinja function test """
app.config.setdefault(FEATURE_FLAGS_CONFIG, {})
app.config.setdefault(RAISE_ERROR_ON_MISSING_FEATURES, False)
if hasattr(app, "add_template_test"):
# flask 0.10 and higher has a proper hoo... | python | def init_app(self, app):
""" Add ourselves into the app config and setup, and add a jinja function test """
app.config.setdefault(FEATURE_FLAGS_CONFIG, {})
app.config.setdefault(RAISE_ERROR_ON_MISSING_FEATURES, False)
if hasattr(app, "add_template_test"):
# flask 0.10 and higher has a proper hoo... | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"app",
".",
"config",
".",
"setdefault",
"(",
"FEATURE_FLAGS_CONFIG",
",",
"{",
"}",
")",
"app",
".",
"config",
".",
"setdefault",
"(",
"RAISE_ERROR_ON_MISSING_FEATURES",
",",
"False",
")",
"if",
"hasat... | Add ourselves into the app config and setup, and add a jinja function test | [
"Add",
"ourselves",
"into",
"the",
"app",
"config",
"and",
"setup",
"and",
"add",
"a",
"jinja",
"function",
"test"
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L90-L104 |
43,819 | trustrachel/Flask-FeatureFlags | flask_featureflags/__init__.py | FeatureFlag.check | def check(self, feature):
""" Loop through all our feature flag checkers and return true if any of them are true.
The order of handlers matters - we will immediately return True if any handler returns true.
If you want to a handler to return False and stop the chain, raise the StopCheckingFeatureFlags exc... | python | def check(self, feature):
""" Loop through all our feature flag checkers and return true if any of them are true.
The order of handlers matters - we will immediately return True if any handler returns true.
If you want to a handler to return False and stop the chain, raise the StopCheckingFeatureFlags exc... | [
"def",
"check",
"(",
"self",
",",
"feature",
")",
":",
"found",
"=",
"False",
"for",
"handler",
"in",
"self",
".",
"handlers",
":",
"try",
":",
"if",
"handler",
"(",
"feature",
")",
":",
"return",
"True",
"except",
"StopCheckingFeatureFlags",
":",
"retur... | Loop through all our feature flag checkers and return true if any of them are true.
The order of handlers matters - we will immediately return True if any handler returns true.
If you want to a handler to return False and stop the chain, raise the StopCheckingFeatureFlags exception. | [
"Loop",
"through",
"all",
"our",
"feature",
"flag",
"checkers",
"and",
"return",
"true",
"if",
"any",
"of",
"them",
"are",
"true",
"."
] | bf32d07c8ce72adc009619ef04e666c51736f80c | https://github.com/trustrachel/Flask-FeatureFlags/blob/bf32d07c8ce72adc009619ef04e666c51736f80c/flask_featureflags/__init__.py#L121-L147 |
43,820 | havardgulldahl/jottalib | src/jottalib/contrib/mwt.py | Memoize.yank_path | def yank_path(self, path):
"""Clear cache of results from a specific path"""
for func in self._caches:
cache = {}
for key in self._caches[func].keys():
log.debug("cache key %s for func %s", key, func)
if path in key[0]:
log.debu... | python | def yank_path(self, path):
"""Clear cache of results from a specific path"""
for func in self._caches:
cache = {}
for key in self._caches[func].keys():
log.debug("cache key %s for func %s", key, func)
if path in key[0]:
log.debu... | [
"def",
"yank_path",
"(",
"self",
",",
"path",
")",
":",
"for",
"func",
"in",
"self",
".",
"_caches",
":",
"cache",
"=",
"{",
"}",
"for",
"key",
"in",
"self",
".",
"_caches",
"[",
"func",
"]",
".",
"keys",
"(",
")",
":",
"log",
".",
"debug",
"("... | Clear cache of results from a specific path | [
"Clear",
"cache",
"of",
"results",
"from",
"a",
"specific",
"path"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/contrib/mwt.py#L87-L95 |
43,821 | havardgulldahl/jottalib | src/jottalib/jottafuse.py | JottaFuse.release | def release(self, path, fh):
"Run after a read or write operation has finished. This is where we upload on writes"
#print "release! inpath:", path in self.__newfiles.keys()
# if the path exists in self.__newfiles.keys(), we have a new version to upload
try:
f = self.__newfile... | python | def release(self, path, fh):
"Run after a read or write operation has finished. This is where we upload on writes"
#print "release! inpath:", path in self.__newfiles.keys()
# if the path exists in self.__newfiles.keys(), we have a new version to upload
try:
f = self.__newfile... | [
"def",
"release",
"(",
"self",
",",
"path",
",",
"fh",
")",
":",
"#print \"release! inpath:\", path in self.__newfiles.keys()",
"# if the path exists in self.__newfiles.keys(), we have a new version to upload",
"try",
":",
"f",
"=",
"self",
".",
"__newfiles",
"[",
"path",
"... | Run after a read or write operation has finished. This is where we upload on writes | [
"Run",
"after",
"a",
"read",
"or",
"write",
"operation",
"has",
"finished",
".",
"This",
"is",
"where",
"we",
"upload",
"on",
"writes"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottafuse.py#L246-L260 |
43,822 | havardgulldahl/jottalib | src/jottalib/jottafuse.py | JottaFuse.truncate | def truncate(self, path, length, fh=None):
"Download existing path, truncate and reupload"
try:
f = self._getpath(path)
except JFS.JFSError:
raise OSError(errno.ENOENT, '')
if isinstance(f, (JFS.JFSFile, JFS.JFSFolder)) and f.is_deleted():
raise OSErro... | python | def truncate(self, path, length, fh=None):
"Download existing path, truncate and reupload"
try:
f = self._getpath(path)
except JFS.JFSError:
raise OSError(errno.ENOENT, '')
if isinstance(f, (JFS.JFSFile, JFS.JFSFolder)) and f.is_deleted():
raise OSErro... | [
"def",
"truncate",
"(",
"self",
",",
"path",
",",
"length",
",",
"fh",
"=",
"None",
")",
":",
"try",
":",
"f",
"=",
"self",
".",
"_getpath",
"(",
"path",
")",
"except",
"JFS",
".",
"JFSError",
":",
"raise",
"OSError",
"(",
"errno",
".",
"ENOENT",
... | Download existing path, truncate and reupload | [
"Download",
"existing",
"path",
"truncate",
"and",
"reupload"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottafuse.py#L330-L345 |
43,823 | havardgulldahl/jottalib | src/jottalib/cli.py | commandline_text | def commandline_text(bytestring):
'Convert bytestring from command line to unicode, using default file system encoding'
if six.PY3:
return bytestring
unicode_string = bytestring.decode(sys.getfilesystemencoding())
return unicode_string | python | def commandline_text(bytestring):
'Convert bytestring from command line to unicode, using default file system encoding'
if six.PY3:
return bytestring
unicode_string = bytestring.decode(sys.getfilesystemencoding())
return unicode_string | [
"def",
"commandline_text",
"(",
"bytestring",
")",
":",
"if",
"six",
".",
"PY3",
":",
"return",
"bytestring",
"unicode_string",
"=",
"bytestring",
".",
"decode",
"(",
"sys",
".",
"getfilesystemencoding",
"(",
")",
")",
"return",
"unicode_string"
] | Convert bytestring from command line to unicode, using default file system encoding | [
"Convert",
"bytestring",
"from",
"command",
"line",
"to",
"unicode",
"using",
"default",
"file",
"system",
"encoding"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/cli.py#L98-L103 |
43,824 | astropy/pyregion | pyregion/ds9_region_parser.py | RegionParser.sky_to_image | def sky_to_image(shape_list, header):
"""Converts a `ShapeList` into shapes with coordinates in image coordinates
Parameters
----------
shape_list : `pyregion.ShapeList`
The ShapeList to convert
header : `~astropy.io.fits.Header`
Specifies what WCS transf... | python | def sky_to_image(shape_list, header):
"""Converts a `ShapeList` into shapes with coordinates in image coordinates
Parameters
----------
shape_list : `pyregion.ShapeList`
The ShapeList to convert
header : `~astropy.io.fits.Header`
Specifies what WCS transf... | [
"def",
"sky_to_image",
"(",
"shape_list",
",",
"header",
")",
":",
"for",
"shape",
",",
"comment",
"in",
"shape_list",
":",
"if",
"isinstance",
"(",
"shape",
",",
"Shape",
")",
"and",
"(",
"shape",
".",
"coord_format",
"not",
"in",
"image_like_coordformats",... | Converts a `ShapeList` into shapes with coordinates in image coordinates
Parameters
----------
shape_list : `pyregion.ShapeList`
The ShapeList to convert
header : `~astropy.io.fits.Header`
Specifies what WCS transformations to use.
Yields
-------... | [
"Converts",
"a",
"ShapeList",
"into",
"shapes",
"with",
"coordinates",
"in",
"image",
"coordinates"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/ds9_region_parser.py#L162-L209 |
43,825 | havardgulldahl/jottalib | src/jottalib/monitor.py | ArchiveEventHandler._new | def _new(self, src_path, dry_run=False, remove_uploaded=False):
'Code to upload'
# are we getting a symbolic link?
if os.path.islink(src_path):
sourcefile = os.path.normpath(os.path.join(self.topdir, os.readlink(src_path)))
if not os.path.exists(source... | python | def _new(self, src_path, dry_run=False, remove_uploaded=False):
'Code to upload'
# are we getting a symbolic link?
if os.path.islink(src_path):
sourcefile = os.path.normpath(os.path.join(self.topdir, os.readlink(src_path)))
if not os.path.exists(source... | [
"def",
"_new",
"(",
"self",
",",
"src_path",
",",
"dry_run",
"=",
"False",
",",
"remove_uploaded",
"=",
"False",
")",
":",
"# are we getting a symbolic link?",
"if",
"os",
".",
"path",
".",
"islink",
"(",
"src_path",
")",
":",
"sourcefile",
"=",
"os",
".",... | Code to upload | [
"Code",
"to",
"upload"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/monitor.py#L126-L157 |
43,826 | astropy/pyregion | pyregion/wcs_helper.py | _estimate_angle | def _estimate_angle(angle, reg_coordinate_frame, header):
"""Transform an angle into a different frame
Parameters
----------
angle : float, int
The number of degrees, measured from the Y axis in origin's frame
reg_coordinate_frame : str
Coordinate frame in which ``angle`` is define... | python | def _estimate_angle(angle, reg_coordinate_frame, header):
"""Transform an angle into a different frame
Parameters
----------
angle : float, int
The number of degrees, measured from the Y axis in origin's frame
reg_coordinate_frame : str
Coordinate frame in which ``angle`` is define... | [
"def",
"_estimate_angle",
"(",
"angle",
",",
"reg_coordinate_frame",
",",
"header",
")",
":",
"y_axis_rot",
"=",
"_calculate_rotation_angle",
"(",
"reg_coordinate_frame",
",",
"header",
")",
"return",
"angle",
"-",
"y_axis_rot"
] | Transform an angle into a different frame
Parameters
----------
angle : float, int
The number of degrees, measured from the Y axis in origin's frame
reg_coordinate_frame : str
Coordinate frame in which ``angle`` is defined
header : `~astropy.io.fits.Header` instance
Header... | [
"Transform",
"an",
"angle",
"into",
"a",
"different",
"frame"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/wcs_helper.py#L7-L27 |
43,827 | astropy/pyregion | pyregion/wcs_helper.py | _calculate_rotation_angle | def _calculate_rotation_angle(reg_coordinate_frame, header):
"""Calculates the rotation angle from the region to the header's frame
This attempts to be compatible with the implementation used by SAOImage
DS9. In particular, this measures the rotation of the north axis as
measured at the center of the i... | python | def _calculate_rotation_angle(reg_coordinate_frame, header):
"""Calculates the rotation angle from the region to the header's frame
This attempts to be compatible with the implementation used by SAOImage
DS9. In particular, this measures the rotation of the north axis as
measured at the center of the i... | [
"def",
"_calculate_rotation_angle",
"(",
"reg_coordinate_frame",
",",
"header",
")",
":",
"new_wcs",
"=",
"WCS",
"(",
"header",
")",
"region_frame",
"=",
"SkyCoord",
"(",
"'0d 0d'",
",",
"frame",
"=",
"reg_coordinate_frame",
",",
"obstime",
"=",
"'J2000'",
")",
... | Calculates the rotation angle from the region to the header's frame
This attempts to be compatible with the implementation used by SAOImage
DS9. In particular, this measures the rotation of the north axis as
measured at the center of the image, and therefore requires a
`~astropy.io.fits.Header` object ... | [
"Calculates",
"the",
"rotation",
"angle",
"from",
"the",
"region",
"to",
"the",
"header",
"s",
"frame"
] | 913af7ea4917855cb2e43d5086d1c8dd99c31363 | https://github.com/astropy/pyregion/blob/913af7ea4917855cb2e43d5086d1c8dd99c31363/pyregion/wcs_helper.py#L30-L89 |
43,828 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | sf | def sf(f, dirpath, jottapath):
"""Create and return a SyncFile tuple from filename.
localpath will be a byte string with utf8 code points
jottapath will be a unicode string"""
log.debug('Create SyncFile from %s', repr(f))
log.debug('Got encoded filename %r, joining with dirpath %r',... | python | def sf(f, dirpath, jottapath):
"""Create and return a SyncFile tuple from filename.
localpath will be a byte string with utf8 code points
jottapath will be a unicode string"""
log.debug('Create SyncFile from %s', repr(f))
log.debug('Got encoded filename %r, joining with dirpath %r',... | [
"def",
"sf",
"(",
"f",
",",
"dirpath",
",",
"jottapath",
")",
":",
"log",
".",
"debug",
"(",
"'Create SyncFile from %s'",
",",
"repr",
"(",
"f",
")",
")",
"log",
".",
"debug",
"(",
"'Got encoded filename %r, joining with dirpath %r'",
",",
"_encode_filename_to_f... | Create and return a SyncFile tuple from filename.
localpath will be a byte string with utf8 code points
jottapath will be a unicode string | [
"Create",
"and",
"return",
"a",
"SyncFile",
"tuple",
"from",
"filename",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L44-L52 |
43,829 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | get_jottapath | def get_jottapath(localtopdir, dirpath, jottamountpoint):
"""Translate localtopdir to jottapath. Returns unicode string"""
log.debug("get_jottapath %r %r %r", localtopdir, dirpath, jottamountpoint)
normpath = posixpath.normpath(posixpath.join(jottamountpoint, posixpath.basename(localtopdir),
... | python | def get_jottapath(localtopdir, dirpath, jottamountpoint):
"""Translate localtopdir to jottapath. Returns unicode string"""
log.debug("get_jottapath %r %r %r", localtopdir, dirpath, jottamountpoint)
normpath = posixpath.normpath(posixpath.join(jottamountpoint, posixpath.basename(localtopdir),
... | [
"def",
"get_jottapath",
"(",
"localtopdir",
",",
"dirpath",
",",
"jottamountpoint",
")",
":",
"log",
".",
"debug",
"(",
"\"get_jottapath %r %r %r\"",
",",
"localtopdir",
",",
"dirpath",
",",
"jottamountpoint",
")",
"normpath",
"=",
"posixpath",
".",
"normpath",
... | Translate localtopdir to jottapath. Returns unicode string | [
"Translate",
"localtopdir",
"to",
"jottapath",
".",
"Returns",
"unicode",
"string"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L55-L60 |
43,830 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | is_file | def is_file(jottapath, JFS):
"""Check if a file exists on jottacloud"""
log.debug("is_file %r", jottapath)
try:
jf = JFS.getObject(jottapath)
except JFSNotFoundError:
return False
return isinstance(jf, JFSFile) | python | def is_file(jottapath, JFS):
"""Check if a file exists on jottacloud"""
log.debug("is_file %r", jottapath)
try:
jf = JFS.getObject(jottapath)
except JFSNotFoundError:
return False
return isinstance(jf, JFSFile) | [
"def",
"is_file",
"(",
"jottapath",
",",
"JFS",
")",
":",
"log",
".",
"debug",
"(",
"\"is_file %r\"",
",",
"jottapath",
")",
"try",
":",
"jf",
"=",
"JFS",
".",
"getObject",
"(",
"jottapath",
")",
"except",
"JFSNotFoundError",
":",
"return",
"False",
"ret... | Check if a file exists on jottacloud | [
"Check",
"if",
"a",
"file",
"exists",
"on",
"jottacloud"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L63-L70 |
43,831 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | compare | def compare(localtopdir, jottamountpoint, JFS, followlinks=False, exclude_patterns=None):
"""Make a tree of local files and folders and compare it with what's currently on JottaCloud.
For each folder, yields:
dirpath, # byte string, full path
onlylocal, # set(), files that only exist locally, i... | python | def compare(localtopdir, jottamountpoint, JFS, followlinks=False, exclude_patterns=None):
"""Make a tree of local files and folders and compare it with what's currently on JottaCloud.
For each folder, yields:
dirpath, # byte string, full path
onlylocal, # set(), files that only exist locally, i... | [
"def",
"compare",
"(",
"localtopdir",
",",
"jottamountpoint",
",",
"JFS",
",",
"followlinks",
"=",
"False",
",",
"exclude_patterns",
"=",
"None",
")",
":",
"def",
"excluded",
"(",
"unicodepath",
",",
"fname",
")",
":",
"fpath",
"=",
"os",
".",
"path",
".... | Make a tree of local files and folders and compare it with what's currently on JottaCloud.
For each folder, yields:
dirpath, # byte string, full path
onlylocal, # set(), files that only exist locally, i.e. newly added files that don't exist online,
onlyremote, # set(), files that only exist... | [
"Make",
"a",
"tree",
"of",
"local",
"files",
"and",
"folders",
"and",
"compare",
"it",
"with",
"what",
"s",
"currently",
"on",
"JottaCloud",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L94-L147 |
43,832 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | _decode_filename_to_unicode | def _decode_filename_to_unicode(f):
'''Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is'''
log.d... | python | def _decode_filename_to_unicode(f):
'''Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is'''
log.d... | [
"def",
"_decode_filename_to_unicode",
"(",
"f",
")",
":",
"log",
".",
"debug",
"(",
"'_decode_filename_to_unicode(%s)'",
",",
"repr",
"(",
"f",
")",
")",
"if",
"isinstance",
"(",
"f",
",",
"unicode",
")",
":",
"return",
"f",
"try",
":",
"return",
"f",
".... | Get bytestring filename and return unicode.
First, try to decode from default file system encoding
If that fails, use ``chardet`` module to guess encoding.
As a last resort, try to decode as utf-8.
If the argument already is unicode, return as is | [
"Get",
"bytestring",
"filename",
"and",
"return",
"unicode",
".",
"First",
"try",
"to",
"decode",
"from",
"default",
"file",
"system",
"encoding",
"If",
"that",
"fails",
"use",
"chardet",
"module",
"to",
"guess",
"encoding",
".",
"As",
"a",
"last",
"resort",... | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L150-L183 |
43,833 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | _encode_filename_to_filesystem | def _encode_filename_to_filesystem(f):
'''Get a unicode filename and return bytestring, encoded to file system default.
If the argument already is a bytestring, return as is'''
log.debug('_encode_filename_to_filesystem(%s)', repr(f))
if isinstance(f, str):
return f
try:
return f.enc... | python | def _encode_filename_to_filesystem(f):
'''Get a unicode filename and return bytestring, encoded to file system default.
If the argument already is a bytestring, return as is'''
log.debug('_encode_filename_to_filesystem(%s)', repr(f))
if isinstance(f, str):
return f
try:
return f.enc... | [
"def",
"_encode_filename_to_filesystem",
"(",
"f",
")",
":",
"log",
".",
"debug",
"(",
"'_encode_filename_to_filesystem(%s)'",
",",
"repr",
"(",
"f",
")",
")",
"if",
"isinstance",
"(",
"f",
",",
"str",
")",
":",
"return",
"f",
"try",
":",
"return",
"f",
... | Get a unicode filename and return bytestring, encoded to file system default.
If the argument already is a bytestring, return as is | [
"Get",
"a",
"unicode",
"filename",
"and",
"return",
"bytestring",
"encoded",
"to",
"file",
"system",
"default",
"."
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L186-L196 |
43,834 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | resume | def resume(localfile, jottafile, JFS):
"""Continue uploading a new file from local file (already exists on JottaCloud"""
with open(localfile) as lf:
_complete = jottafile.resume(lf)
return _complete | python | def resume(localfile, jottafile, JFS):
"""Continue uploading a new file from local file (already exists on JottaCloud"""
with open(localfile) as lf:
_complete = jottafile.resume(lf)
return _complete | [
"def",
"resume",
"(",
"localfile",
",",
"jottafile",
",",
"JFS",
")",
":",
"with",
"open",
"(",
"localfile",
")",
"as",
"lf",
":",
"_complete",
"=",
"jottafile",
".",
"resume",
"(",
"lf",
")",
"return",
"_complete"
] | Continue uploading a new file from local file (already exists on JottaCloud | [
"Continue",
"uploading",
"a",
"new",
"file",
"from",
"local",
"file",
"(",
"already",
"exists",
"on",
"JottaCloud"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L206-L210 |
43,835 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | replace_if_changed | def replace_if_changed(localfile, jottapath, JFS):
"""Compare md5 hash to determine if contents have changed.
Upload a file from local disk and replace file on JottaCloud if the md5s differ,
or continue uploading if the file is incompletely uploaded.
Returns the JottaFile object"""
jf = JFS.getObje... | python | def replace_if_changed(localfile, jottapath, JFS):
"""Compare md5 hash to determine if contents have changed.
Upload a file from local disk and replace file on JottaCloud if the md5s differ,
or continue uploading if the file is incompletely uploaded.
Returns the JottaFile object"""
jf = JFS.getObje... | [
"def",
"replace_if_changed",
"(",
"localfile",
",",
"jottapath",
",",
"JFS",
")",
":",
"jf",
"=",
"JFS",
".",
"getObject",
"(",
"jottapath",
")",
"lf_hash",
"=",
"getxattrhash",
"(",
"localfile",
")",
"# try to read previous hash, stored in xattr",
"if",
"lf_hash"... | Compare md5 hash to determine if contents have changed.
Upload a file from local disk and replace file on JottaCloud if the md5s differ,
or continue uploading if the file is incompletely uploaded.
Returns the JottaFile object | [
"Compare",
"md5",
"hash",
"to",
"determine",
"if",
"contents",
"have",
"changed",
".",
"Upload",
"a",
"file",
"from",
"local",
"disk",
"and",
"replace",
"file",
"on",
"JottaCloud",
"if",
"the",
"md5s",
"differ",
"or",
"continue",
"uploading",
"if",
"the",
... | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L212-L232 |
43,836 | havardgulldahl/jottalib | src/jottalib/jottacloud.py | iter_tree | def iter_tree(jottapath, JFS):
"""Get a tree of of files and folders. use as an iterator, you get something like os.walk"""
filedirlist = JFS.getObject('%s?mode=list' % jottapath)
log.debug("got tree: %s", filedirlist)
if not isinstance(filedirlist, JFSFileDirList):
yield ( '', tuple(), tuple() ... | python | def iter_tree(jottapath, JFS):
"""Get a tree of of files and folders. use as an iterator, you get something like os.walk"""
filedirlist = JFS.getObject('%s?mode=list' % jottapath)
log.debug("got tree: %s", filedirlist)
if not isinstance(filedirlist, JFSFileDirList):
yield ( '', tuple(), tuple() ... | [
"def",
"iter_tree",
"(",
"jottapath",
",",
"JFS",
")",
":",
"filedirlist",
"=",
"JFS",
".",
"getObject",
"(",
"'%s?mode=list'",
"%",
"jottapath",
")",
"log",
".",
"debug",
"(",
"\"got tree: %s\"",
",",
"filedirlist",
")",
"if",
"not",
"isinstance",
"(",
"f... | Get a tree of of files and folders. use as an iterator, you get something like os.walk | [
"Get",
"a",
"tree",
"of",
"of",
"files",
"and",
"folders",
".",
"use",
"as",
"an",
"iterator",
"you",
"get",
"something",
"like",
"os",
".",
"walk"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/jottalib/jottacloud.py#L252-L259 |
43,837 | havardgulldahl/jottalib | src/duplicity-backend.py | JottaCloudBackend._query | def _query(self, filename):
"""Get size of filename"""
# - Query metadata of one file
# - Return a dict with a 'size' key, and a file size value (-1 for not found)
# - Retried if an exception is thrown
log.Info('Querying size of %s' % filename)
from jottalib.JFS import... | python | def _query(self, filename):
"""Get size of filename"""
# - Query metadata of one file
# - Return a dict with a 'size' key, and a file size value (-1 for not found)
# - Retried if an exception is thrown
log.Info('Querying size of %s' % filename)
from jottalib.JFS import... | [
"def",
"_query",
"(",
"self",
",",
"filename",
")",
":",
"# - Query metadata of one file",
"# - Return a dict with a 'size' key, and a file size value (-1 for not found)",
"# - Retried if an exception is thrown",
"log",
".",
"Info",
"(",
"'Querying size of %s'",
"%",
"filename",... | Get size of filename | [
"Get",
"size",
"of",
"filename"
] | 4d015e4309b1d9055e561ec757363fb2632b4eb7 | https://github.com/havardgulldahl/jottalib/blob/4d015e4309b1d9055e561ec757363fb2632b4eb7/src/duplicity-backend.py#L141-L155 |
43,838 | booktype/python-ooxml | ooxml/parse.py | parse_drawing | def parse_drawing(document, container, elem):
"""Parse drawing element.
We don't do much with drawing element. We can find embeded image but we don't do more than that.
"""
_blip = elem.xpath('.//a:blip', namespaces=NAMESPACES)
if len(_blip) > 0:
blip = _blip[0]
_rid = blip.attrib... | python | def parse_drawing(document, container, elem):
"""Parse drawing element.
We don't do much with drawing element. We can find embeded image but we don't do more than that.
"""
_blip = elem.xpath('.//a:blip', namespaces=NAMESPACES)
if len(_blip) > 0:
blip = _blip[0]
_rid = blip.attrib... | [
"def",
"parse_drawing",
"(",
"document",
",",
"container",
",",
"elem",
")",
":",
"_blip",
"=",
"elem",
".",
"xpath",
"(",
"'.//a:blip'",
",",
"namespaces",
"=",
"NAMESPACES",
")",
"if",
"len",
"(",
"_blip",
")",
">",
"0",
":",
"blip",
"=",
"_blip",
... | Parse drawing element.
We don't do much with drawing element. We can find embeded image but we don't do more than that. | [
"Parse",
"drawing",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L177-L190 |
43,839 | booktype/python-ooxml | ooxml/parse.py | parse_footnote | def parse_footnote(document, container, elem):
"Parse the footnote element."
_rid = elem.attrib[_name('{{{w}}}id')]
foot = doc.Footnote(_rid)
container.elements.append(foot) | python | def parse_footnote(document, container, elem):
"Parse the footnote element."
_rid = elem.attrib[_name('{{{w}}}id')]
foot = doc.Footnote(_rid)
container.elements.append(foot) | [
"def",
"parse_footnote",
"(",
"document",
",",
"container",
",",
"elem",
")",
":",
"_rid",
"=",
"elem",
".",
"attrib",
"[",
"_name",
"(",
"'{{{w}}}id'",
")",
"]",
"foot",
"=",
"doc",
".",
"Footnote",
"(",
"_rid",
")",
"container",
".",
"elements",
".",... | Parse the footnote element. | [
"Parse",
"the",
"footnote",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L193-L198 |
43,840 | booktype/python-ooxml | ooxml/parse.py | parse_text | def parse_text(document, container, element):
"Parse text element."
txt = None
alternate = element.find(_name('{{{mc}}}AlternateContent'))
if alternate is not None:
parse_alternate(document, container, alternate)
br = element.find(_name('{{{w}}}br'))
if br is not None:
if _n... | python | def parse_text(document, container, element):
"Parse text element."
txt = None
alternate = element.find(_name('{{{mc}}}AlternateContent'))
if alternate is not None:
parse_alternate(document, container, alternate)
br = element.find(_name('{{{w}}}br'))
if br is not None:
if _n... | [
"def",
"parse_text",
"(",
"document",
",",
"container",
",",
"element",
")",
":",
"txt",
"=",
"None",
"alternate",
"=",
"element",
".",
"find",
"(",
"_name",
"(",
"'{{{mc}}}AlternateContent'",
")",
")",
"if",
"alternate",
"is",
"not",
"None",
":",
"parse_a... | Parse text element. | [
"Parse",
"text",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L224-L291 |
43,841 | booktype/python-ooxml | ooxml/parse.py | parse_paragraph | def parse_paragraph(document, par):
"""Parse paragraph element.
Some other elements could be found inside of paragraph element (math, links).
"""
paragraph = doc.Paragraph()
paragraph.document = document
for elem in par:
if elem.tag == _name('{{{w}}}pPr'):
parse_paragraph_... | python | def parse_paragraph(document, par):
"""Parse paragraph element.
Some other elements could be found inside of paragraph element (math, links).
"""
paragraph = doc.Paragraph()
paragraph.document = document
for elem in par:
if elem.tag == _name('{{{w}}}pPr'):
parse_paragraph_... | [
"def",
"parse_paragraph",
"(",
"document",
",",
"par",
")",
":",
"paragraph",
"=",
"doc",
".",
"Paragraph",
"(",
")",
"paragraph",
".",
"document",
"=",
"document",
"for",
"elem",
"in",
"par",
":",
"if",
"elem",
".",
"tag",
"==",
"_name",
"(",
"'{{{w}}... | Parse paragraph element.
Some other elements could be found inside of paragraph element (math, links). | [
"Parse",
"paragraph",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L313-L358 |
43,842 | booktype/python-ooxml | ooxml/parse.py | parse_table_properties | def parse_table_properties(doc, table, prop):
"Parse table properties."
if not table:
return
style = prop.find(_name('{{{w}}}tblStyle'))
if style is not None:
table.style_id = style.attrib[_name('{{{w}}}val')]
doc.add_style_as_used(table.style_id) | python | def parse_table_properties(doc, table, prop):
"Parse table properties."
if not table:
return
style = prop.find(_name('{{{w}}}tblStyle'))
if style is not None:
table.style_id = style.attrib[_name('{{{w}}}val')]
doc.add_style_as_used(table.style_id) | [
"def",
"parse_table_properties",
"(",
"doc",
",",
"table",
",",
"prop",
")",
":",
"if",
"not",
"table",
":",
"return",
"style",
"=",
"prop",
".",
"find",
"(",
"_name",
"(",
"'{{{w}}}tblStyle'",
")",
")",
"if",
"style",
"is",
"not",
"None",
":",
"table"... | Parse table properties. | [
"Parse",
"table",
"properties",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L361-L371 |
43,843 | booktype/python-ooxml | ooxml/parse.py | parse_table_column_properties | def parse_table_column_properties(doc, cell, prop):
"Parse table column properties."
if not cell:
return
grid = prop.find(_name('{{{w}}}gridSpan'))
if grid is not None:
cell.grid_span = int(grid.attrib[_name('{{{w}}}val')])
vmerge = prop.find(_name('{{{w}}}vMerge'))
if vmerg... | python | def parse_table_column_properties(doc, cell, prop):
"Parse table column properties."
if not cell:
return
grid = prop.find(_name('{{{w}}}gridSpan'))
if grid is not None:
cell.grid_span = int(grid.attrib[_name('{{{w}}}val')])
vmerge = prop.find(_name('{{{w}}}vMerge'))
if vmerg... | [
"def",
"parse_table_column_properties",
"(",
"doc",
",",
"cell",
",",
"prop",
")",
":",
"if",
"not",
"cell",
":",
"return",
"grid",
"=",
"prop",
".",
"find",
"(",
"_name",
"(",
"'{{{w}}}gridSpan'",
")",
")",
"if",
"grid",
"is",
"not",
"None",
":",
"cel... | Parse table column properties. | [
"Parse",
"table",
"column",
"properties",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L374-L391 |
43,844 | booktype/python-ooxml | ooxml/parse.py | parse_table | def parse_table(document, tbl):
"Parse table element."
def _change(rows, pos_x):
if len(rows) == 1:
return rows
count_x = 1
for x in rows[-1]:
if count_x == pos_x:
x.row_span += 1
count_x += x.grid_span
return rows
tab... | python | def parse_table(document, tbl):
"Parse table element."
def _change(rows, pos_x):
if len(rows) == 1:
return rows
count_x = 1
for x in rows[-1]:
if count_x == pos_x:
x.row_span += 1
count_x += x.grid_span
return rows
tab... | [
"def",
"parse_table",
"(",
"document",
",",
"tbl",
")",
":",
"def",
"_change",
"(",
"rows",
",",
"pos_x",
")",
":",
"if",
"len",
"(",
"rows",
")",
"==",
"1",
":",
"return",
"rows",
"count_x",
"=",
"1",
"for",
"x",
"in",
"rows",
"[",
"-",
"1",
"... | Parse table element. | [
"Parse",
"table",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L394-L443 |
43,845 | booktype/python-ooxml | ooxml/parse.py | parse_document | def parse_document(xmlcontent):
"""Parse document with content.
Content is placed in file 'document.xml'.
"""
document = etree.fromstring(xmlcontent)
body = document.xpath('.//w:body', namespaces=NAMESPACES)[0]
document = doc.Document()
for elem in body:
if elem.tag == _name('{{... | python | def parse_document(xmlcontent):
"""Parse document with content.
Content is placed in file 'document.xml'.
"""
document = etree.fromstring(xmlcontent)
body = document.xpath('.//w:body', namespaces=NAMESPACES)[0]
document = doc.Document()
for elem in body:
if elem.tag == _name('{{... | [
"def",
"parse_document",
"(",
"xmlcontent",
")",
":",
"document",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"body",
"=",
"document",
".",
"xpath",
"(",
"'.//w:body'",
",",
"namespaces",
"=",
"NAMESPACES",
")",
"[",
"0",
"]",
"document",
"=",... | Parse document with content.
Content is placed in file 'document.xml'. | [
"Parse",
"document",
"with",
"content",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L446-L468 |
43,846 | booktype/python-ooxml | ooxml/parse.py | parse_relationship | def parse_relationship(document, xmlcontent, rel_type):
"""Parse relationship document.
Relationships hold information like external or internal references for links.
Relationships are placed in file '_rels/document.xml.rels'.
"""
doc = etree.fromstring(xmlcontent)
for elem in doc:
i... | python | def parse_relationship(document, xmlcontent, rel_type):
"""Parse relationship document.
Relationships hold information like external or internal references for links.
Relationships are placed in file '_rels/document.xml.rels'.
"""
doc = etree.fromstring(xmlcontent)
for elem in doc:
i... | [
"def",
"parse_relationship",
"(",
"document",
",",
"xmlcontent",
",",
"rel_type",
")",
":",
"doc",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"for",
"elem",
"in",
"doc",
":",
"if",
"elem",
".",
"tag",
"==",
"_name",
"(",
"'{{{pr}}}Relationshi... | Parse relationship document.
Relationships hold information like external or internal references for links.
Relationships are placed in file '_rels/document.xml.rels'. | [
"Parse",
"relationship",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L471-L487 |
43,847 | booktype/python-ooxml | ooxml/parse.py | parse_style | def parse_style(document, xmlcontent):
"""Parse styles document.
Styles are defined in file 'styles.xml'.
"""
styles = etree.fromstring(xmlcontent)
_r = styles.xpath('.//w:rPrDefault', namespaces=NAMESPACES)
if len(_r) > 0:
rpr = _r[0].find(_name('{{{w}}}rPr'))
if rpr is not... | python | def parse_style(document, xmlcontent):
"""Parse styles document.
Styles are defined in file 'styles.xml'.
"""
styles = etree.fromstring(xmlcontent)
_r = styles.xpath('.//w:rPrDefault', namespaces=NAMESPACES)
if len(_r) > 0:
rpr = _r[0].find(_name('{{{w}}}rPr'))
if rpr is not... | [
"def",
"parse_style",
"(",
"document",
",",
"xmlcontent",
")",
":",
"styles",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"_r",
"=",
"styles",
".",
"xpath",
"(",
"'.//w:rPrDefault'",
",",
"namespaces",
"=",
"NAMESPACES",
")",
"if",
"len",
"(",... | Parse styles document.
Styles are defined in file 'styles.xml'. | [
"Parse",
"styles",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L490-L545 |
43,848 | booktype/python-ooxml | ooxml/parse.py | parse_comments | def parse_comments(document, xmlcontent):
"""Parse comments document.
Comments are defined in file 'comments.xml'
"""
comments = etree.fromstring(xmlcontent)
document.comments = {}
for comment in comments.xpath('.//w:comment', namespaces=NAMESPACES):
# w:author
# w:id
... | python | def parse_comments(document, xmlcontent):
"""Parse comments document.
Comments are defined in file 'comments.xml'
"""
comments = etree.fromstring(xmlcontent)
document.comments = {}
for comment in comments.xpath('.//w:comment', namespaces=NAMESPACES):
# w:author
# w:id
... | [
"def",
"parse_comments",
"(",
"document",
",",
"xmlcontent",
")",
":",
"comments",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"comments",
"=",
"{",
"}",
"for",
"comment",
"in",
"comments",
".",
"xpath",
"(",
"'.//w:comment'",
... | Parse comments document.
Comments are defined in file 'comments.xml' | [
"Parse",
"comments",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L548-L569 |
43,849 | booktype/python-ooxml | ooxml/parse.py | parse_footnotes | def parse_footnotes(document, xmlcontent):
"""Parse footnotes document.
Footnotes are defined in file 'footnotes.xml'
"""
footnotes = etree.fromstring(xmlcontent)
document.footnotes = {}
for footnote in footnotes.xpath('.//w:footnote', namespaces=NAMESPACES):
_type = footnote.attrib.g... | python | def parse_footnotes(document, xmlcontent):
"""Parse footnotes document.
Footnotes are defined in file 'footnotes.xml'
"""
footnotes = etree.fromstring(xmlcontent)
document.footnotes = {}
for footnote in footnotes.xpath('.//w:footnote', namespaces=NAMESPACES):
_type = footnote.attrib.g... | [
"def",
"parse_footnotes",
"(",
"document",
",",
"xmlcontent",
")",
":",
"footnotes",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"footnotes",
"=",
"{",
"}",
"for",
"footnote",
"in",
"footnotes",
".",
"xpath",
"(",
"'.//w:footnot... | Parse footnotes document.
Footnotes are defined in file 'footnotes.xml' | [
"Parse",
"footnotes",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L572-L590 |
43,850 | booktype/python-ooxml | ooxml/parse.py | parse_endnotes | def parse_endnotes(document, xmlcontent):
"""Parse endnotes document.
Endnotes are defined in file 'endnotes.xml'
"""
endnotes = etree.fromstring(xmlcontent)
document.endnotes = {}
for note in endnotes.xpath('.//w:endnote', namespaces=NAMESPACES):
paragraphs = [parse_paragraph(documen... | python | def parse_endnotes(document, xmlcontent):
"""Parse endnotes document.
Endnotes are defined in file 'endnotes.xml'
"""
endnotes = etree.fromstring(xmlcontent)
document.endnotes = {}
for note in endnotes.xpath('.//w:endnote', namespaces=NAMESPACES):
paragraphs = [parse_paragraph(documen... | [
"def",
"parse_endnotes",
"(",
"document",
",",
"xmlcontent",
")",
":",
"endnotes",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"endnotes",
"=",
"{",
"}",
"for",
"note",
"in",
"endnotes",
".",
"xpath",
"(",
"'.//w:endnote'",
",... | Parse endnotes document.
Endnotes are defined in file 'endnotes.xml' | [
"Parse",
"endnotes",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L593-L605 |
43,851 | booktype/python-ooxml | ooxml/parse.py | parse_numbering | def parse_numbering(document, xmlcontent):
"""Parse numbering document.
Numbering is defined in file 'numbering.xml'.
"""
numbering = etree.fromstring(xmlcontent)
document.abstruct_numbering = {}
document.numbering = {}
for abstruct_num in numbering.xpath('.//w:abstractNum', namespaces=N... | python | def parse_numbering(document, xmlcontent):
"""Parse numbering document.
Numbering is defined in file 'numbering.xml'.
"""
numbering = etree.fromstring(xmlcontent)
document.abstruct_numbering = {}
document.numbering = {}
for abstruct_num in numbering.xpath('.//w:abstractNum', namespaces=N... | [
"def",
"parse_numbering",
"(",
"document",
",",
"xmlcontent",
")",
":",
"numbering",
"=",
"etree",
".",
"fromstring",
"(",
"xmlcontent",
")",
"document",
".",
"abstruct_numbering",
"=",
"{",
"}",
"document",
".",
"numbering",
"=",
"{",
"}",
"for",
"abstruct_... | Parse numbering document.
Numbering is defined in file 'numbering.xml'. | [
"Parse",
"numbering",
"document",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L608-L636 |
43,852 | booktype/python-ooxml | ooxml/parse.py | parse_from_file | def parse_from_file(file_object):
"""Parses existing OOXML file.
:Args:
- file_object (:class:`ooxml.docx.DOCXFile`): OOXML file object
:Returns:
Returns parsed document of type :class:`ooxml.doc.Document`
"""
logger.info('Parsing %s file.', file_object.file_name)
# Read the file... | python | def parse_from_file(file_object):
"""Parses existing OOXML file.
:Args:
- file_object (:class:`ooxml.docx.DOCXFile`): OOXML file object
:Returns:
Returns parsed document of type :class:`ooxml.doc.Document`
"""
logger.info('Parsing %s file.', file_object.file_name)
# Read the file... | [
"def",
"parse_from_file",
"(",
"file_object",
")",
":",
"logger",
".",
"info",
"(",
"'Parsing %s file.'",
",",
"file_object",
".",
"file_name",
")",
"# Read the files",
"doc_content",
"=",
"file_object",
".",
"read_file",
"(",
"'document.xml'",
")",
"# Parse the doc... | Parses existing OOXML file.
:Args:
- file_object (:class:`ooxml.docx.DOCXFile`): OOXML file object
:Returns:
Returns parsed document of type :class:`ooxml.doc.Document` | [
"Parses",
"existing",
"OOXML",
"file",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/parse.py#L639-L705 |
43,853 | booktype/python-ooxml | ooxml/doc.py | StylesCollection.get_by_name | def get_by_name(self, name, style_type = None):
"""Find style by it's descriptive name.
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.name == name:
return st
... | python | def get_by_name(self, name, style_type = None):
"""Find style by it's descriptive name.
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.name == name:
return st
... | [
"def",
"get_by_name",
"(",
"self",
",",
"name",
",",
"style_type",
"=",
"None",
")",
":",
"for",
"st",
"in",
"self",
".",
"styles",
".",
"values",
"(",
")",
":",
"if",
"st",
":",
"if",
"st",
".",
"name",
"==",
"name",
":",
"return",
"st",
"if",
... | Find style by it's descriptive name.
:Returns:
Returns found style of type :class:`ooxml.doc.Style`. | [
"Find",
"style",
"by",
"it",
"s",
"descriptive",
"name",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/doc.py#L55-L68 |
43,854 | booktype/python-ooxml | ooxml/doc.py | StylesCollection.get_by_id | def get_by_id(self, style_id, style_type = None):
"""Find style by it's unique identifier
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.style_id == style_id:
ret... | python | def get_by_id(self, style_id, style_type = None):
"""Find style by it's unique identifier
:Returns:
Returns found style of type :class:`ooxml.doc.Style`.
"""
for st in self.styles.values():
if st:
if st.style_id == style_id:
ret... | [
"def",
"get_by_id",
"(",
"self",
",",
"style_id",
",",
"style_type",
"=",
"None",
")",
":",
"for",
"st",
"in",
"self",
".",
"styles",
".",
"values",
"(",
")",
":",
"if",
"st",
":",
"if",
"st",
".",
"style_id",
"==",
"style_id",
":",
"return",
"st",... | Find style by it's unique identifier
:Returns:
Returns found style of type :class:`ooxml.doc.Style`. | [
"Find",
"style",
"by",
"it",
"s",
"unique",
"identifier"
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/doc.py#L70-L84 |
43,855 | rfk/threading2 | threading2/t2_base.py | process_affinity | def process_affinity(affinity=None):
"""Get or set the CPU affinity set for the current process.
This will affect all future threads spawned by this process. It is
implementation-defined whether it will also affect previously-spawned
threads.
"""
if affinity is not None:
affinity = CPU... | python | def process_affinity(affinity=None):
"""Get or set the CPU affinity set for the current process.
This will affect all future threads spawned by this process. It is
implementation-defined whether it will also affect previously-spawned
threads.
"""
if affinity is not None:
affinity = CPU... | [
"def",
"process_affinity",
"(",
"affinity",
"=",
"None",
")",
":",
"if",
"affinity",
"is",
"not",
"None",
":",
"affinity",
"=",
"CPUSet",
"(",
"affinity",
")",
"if",
"not",
"affinity",
".",
"issubset",
"(",
"system_affinity",
"(",
")",
")",
":",
"raise",... | Get or set the CPU affinity set for the current process.
This will affect all future threads spawned by this process. It is
implementation-defined whether it will also affect previously-spawned
threads. | [
"Get",
"or",
"set",
"the",
"CPU",
"affinity",
"set",
"for",
"the",
"current",
"process",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L610-L621 |
43,856 | rfk/threading2 | threading2/t2_base.py | Lock.acquire | def acquire(self,blocking=True,timeout=None):
"""Attempt to acquire this lock.
If the optional argument "blocking" is True and "timeout" is None,
this methods blocks until is successfully acquires the lock. If
"blocking" is False, it returns immediately if the lock could not
be... | python | def acquire(self,blocking=True,timeout=None):
"""Attempt to acquire this lock.
If the optional argument "blocking" is True and "timeout" is None,
this methods blocks until is successfully acquires the lock. If
"blocking" is False, it returns immediately if the lock could not
be... | [
"def",
"acquire",
"(",
"self",
",",
"blocking",
"=",
"True",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"return",
"self",
".",
"__lock",
".",
"acquire",
"(",
"blocking",
")",
"else",
":",
"# Simulated timeout using progress... | Attempt to acquire this lock.
If the optional argument "blocking" is True and "timeout" is None,
this methods blocks until is successfully acquires the lock. If
"blocking" is False, it returns immediately if the lock could not
be acquired. Otherwise, it blocks for at most "timeout" se... | [
"Attempt",
"to",
"acquire",
"this",
"lock",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L39-L68 |
43,857 | rfk/threading2 | threading2/t2_base.py | Thread.from_thread | def from_thread(cls,thread):
"""Convert a vanilla thread object into an instance of this class.
This method "upgrades" a vanilla thread object to an instance of this
extended class. You might need to call this if you obtain a reference
to a thread by some means other than (a) creating ... | python | def from_thread(cls,thread):
"""Convert a vanilla thread object into an instance of this class.
This method "upgrades" a vanilla thread object to an instance of this
extended class. You might need to call this if you obtain a reference
to a thread by some means other than (a) creating ... | [
"def",
"from_thread",
"(",
"cls",
",",
"thread",
")",
":",
"new_classes",
"=",
"[",
"]",
"for",
"new_cls",
"in",
"cls",
".",
"__mro__",
":",
"if",
"new_cls",
"not",
"in",
"thread",
".",
"__class__",
".",
"__mro__",
":",
"new_classes",
".",
"append",
"(... | Convert a vanilla thread object into an instance of this class.
This method "upgrades" a vanilla thread object to an instance of this
extended class. You might need to call this if you obtain a reference
to a thread by some means other than (a) creating it, or (b) from the
methods of ... | [
"Convert",
"a",
"vanilla",
"thread",
"object",
"into",
"an",
"instance",
"of",
"this",
"class",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L290-L313 |
43,858 | rfk/threading2 | threading2/t2_base.py | SHLock.acquire | def acquire(self,blocking=True,timeout=None,shared=False):
"""Acquire the lock in shared or exclusive mode."""
with self._lock:
if shared:
self._acquire_shared(blocking,timeout)
else:
self._acquire_exclusive(blocking,timeout)
assert not... | python | def acquire(self,blocking=True,timeout=None,shared=False):
"""Acquire the lock in shared or exclusive mode."""
with self._lock:
if shared:
self._acquire_shared(blocking,timeout)
else:
self._acquire_exclusive(blocking,timeout)
assert not... | [
"def",
"acquire",
"(",
"self",
",",
"blocking",
"=",
"True",
",",
"timeout",
"=",
"None",
",",
"shared",
"=",
"False",
")",
":",
"with",
"self",
".",
"_lock",
":",
"if",
"shared",
":",
"self",
".",
"_acquire_shared",
"(",
"blocking",
",",
"timeout",
... | Acquire the lock in shared or exclusive mode. | [
"Acquire",
"the",
"lock",
"in",
"shared",
"or",
"exclusive",
"mode",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/t2_base.py#L450-L457 |
43,859 | booktype/python-ooxml | ooxml/serialize.py | _get_font_size | def _get_font_size(document, style):
"""Get font size defined for this style.
It will try to get font size from it's parent style if it is not defined by original style.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Ret... | python | def _get_font_size(document, style):
"""Get font size defined for this style.
It will try to get font size from it's parent style if it is not defined by original style.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Ret... | [
"def",
"_get_font_size",
"(",
"document",
",",
"style",
")",
":",
"font_size",
"=",
"style",
".",
"get_font_size",
"(",
")",
"if",
"font_size",
"==",
"-",
"1",
":",
"if",
"style",
".",
"based_on",
":",
"based_on",
"=",
"document",
".",
"styles",
".",
"... | Get font size defined for this style.
It will try to get font size from it's parent style if it is not defined by original style.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Returns:
Returns font size as a number. -... | [
"Get",
"font",
"size",
"defined",
"for",
"this",
"style",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L44-L65 |
43,860 | booktype/python-ooxml | ooxml/serialize.py | _get_numbering | def _get_numbering(document, numid, ilvl):
"""Returns type for the list.
:Returns:
Returns type for the list. Returns "bullet" by default or in case of an error.
"""
try:
abs_num = document.numbering[numid]
return document.abstruct_numbering[abs_num][ilvl]['numFmt']
except:
... | python | def _get_numbering(document, numid, ilvl):
"""Returns type for the list.
:Returns:
Returns type for the list. Returns "bullet" by default or in case of an error.
"""
try:
abs_num = document.numbering[numid]
return document.abstruct_numbering[abs_num][ilvl]['numFmt']
except:
... | [
"def",
"_get_numbering",
"(",
"document",
",",
"numid",
",",
"ilvl",
")",
":",
"try",
":",
"abs_num",
"=",
"document",
".",
"numbering",
"[",
"numid",
"]",
"return",
"document",
".",
"abstruct_numbering",
"[",
"abs_num",
"]",
"[",
"ilvl",
"]",
"[",
"'num... | Returns type for the list.
:Returns:
Returns type for the list. Returns "bullet" by default or in case of an error. | [
"Returns",
"type",
"for",
"the",
"list",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L74-L85 |
43,861 | booktype/python-ooxml | ooxml/serialize.py | _get_parent | def _get_parent(root):
"""Returns root element for a list.
:Args:
root (Element): lxml element of current location
:Returns:
lxml element representing list
"""
elem = root
while True:
elem = elem.getparent()
if elem.tag in ['ul', 'ol']:
return e... | python | def _get_parent(root):
"""Returns root element for a list.
:Args:
root (Element): lxml element of current location
:Returns:
lxml element representing list
"""
elem = root
while True:
elem = elem.getparent()
if elem.tag in ['ul', 'ol']:
return e... | [
"def",
"_get_parent",
"(",
"root",
")",
":",
"elem",
"=",
"root",
"while",
"True",
":",
"elem",
"=",
"elem",
".",
"getparent",
"(",
")",
"if",
"elem",
".",
"tag",
"in",
"[",
"'ul'",
",",
"'ol'",
"]",
":",
"return",
"elem"
] | Returns root element for a list.
:Args:
root (Element): lxml element of current location
:Returns:
lxml element representing list | [
"Returns",
"root",
"element",
"for",
"a",
"list",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L104-L120 |
43,862 | booktype/python-ooxml | ooxml/serialize.py | close_list | def close_list(ctx, root):
"""Close already opened list if needed.
This will try to see if it is needed to close already opened list.
:Args:
- ctx (:class:`Context`): Context object
- root (Element): lxml element representing current position.
:Returns:
lxml element where future co... | python | def close_list(ctx, root):
"""Close already opened list if needed.
This will try to see if it is needed to close already opened list.
:Args:
- ctx (:class:`Context`): Context object
- root (Element): lxml element representing current position.
:Returns:
lxml element where future co... | [
"def",
"close_list",
"(",
"ctx",
",",
"root",
")",
":",
"try",
":",
"n",
"=",
"len",
"(",
"ctx",
".",
"in_list",
")",
"if",
"n",
"<=",
"0",
":",
"return",
"root",
"elem",
"=",
"root",
"while",
"n",
">",
"0",
":",
"while",
"True",
":",
"if",
"... | Close already opened list if needed.
This will try to see if it is needed to close already opened list.
:Args:
- ctx (:class:`Context`): Context object
- root (Element): lxml element representing current position.
:Returns:
lxml element where future content should be placed. | [
"Close",
"already",
"opened",
"list",
"if",
"needed",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L123-L157 |
43,863 | booktype/python-ooxml | ooxml/serialize.py | open_list | def open_list(ctx, document, par, root, elem):
"""Open list if it is needed and place current element as first member of a list.
:Args:
- ctx (:class:`Context`): Context object
- document (:class:`ooxml.doc.Document`): Document object
- par (:class:`ooxml.doc.Paragraph`): Paragraph element
... | python | def open_list(ctx, document, par, root, elem):
"""Open list if it is needed and place current element as first member of a list.
:Args:
- ctx (:class:`Context`): Context object
- document (:class:`ooxml.doc.Document`): Document object
- par (:class:`ooxml.doc.Paragraph`): Paragraph element
... | [
"def",
"open_list",
"(",
"ctx",
",",
"document",
",",
"par",
",",
"root",
",",
"elem",
")",
":",
"_ls",
"=",
"None",
"if",
"par",
".",
"ilvl",
"!=",
"ctx",
".",
"ilvl",
"or",
"par",
".",
"numid",
"!=",
"ctx",
".",
"numid",
":",
"# start",
"if",
... | Open list if it is needed and place current element as first member of a list.
:Args:
- ctx (:class:`Context`): Context object
- document (:class:`ooxml.doc.Document`): Document object
- par (:class:`ooxml.doc.Paragraph`): Paragraph element
- root (Element): lxml element of current location... | [
"Open",
"list",
"if",
"it",
"is",
"needed",
"and",
"place",
"current",
"element",
"as",
"first",
"member",
"of",
"a",
"list",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L160-L231 |
43,864 | booktype/python-ooxml | ooxml/serialize.py | serialize_break | def serialize_break(ctx, document, elem, root):
"Serialize break element."
if elem.break_type == u'textWrapping':
_div = etree.SubElement(root, 'br')
else:
_div = etree.SubElement(root, 'span')
if ctx.options['embed_styles']:
_div.set('style', 'page-break-after: always;'... | python | def serialize_break(ctx, document, elem, root):
"Serialize break element."
if elem.break_type == u'textWrapping':
_div = etree.SubElement(root, 'br')
else:
_div = etree.SubElement(root, 'span')
if ctx.options['embed_styles']:
_div.set('style', 'page-break-after: always;'... | [
"def",
"serialize_break",
"(",
"ctx",
",",
"document",
",",
"elem",
",",
"root",
")",
":",
"if",
"elem",
".",
"break_type",
"==",
"u'textWrapping'",
":",
"_div",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'br'",
")",
"else",
":",
"_div",
"=",
... | Serialize break element. | [
"Serialize",
"break",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L238-L250 |
43,865 | booktype/python-ooxml | ooxml/serialize.py | serialize_math | def serialize_math(ctx, document, elem, root):
"""Serialize math element.
Math objects are not supported at the moment. This is wht we only show error message.
"""
_div = etree.SubElement(root, 'span')
if ctx.options['embed_styles']:
_div.set('style', 'border: 1px solid red')
_div.text... | python | def serialize_math(ctx, document, elem, root):
"""Serialize math element.
Math objects are not supported at the moment. This is wht we only show error message.
"""
_div = etree.SubElement(root, 'span')
if ctx.options['embed_styles']:
_div.set('style', 'border: 1px solid red')
_div.text... | [
"def",
"serialize_math",
"(",
"ctx",
",",
"document",
",",
"elem",
",",
"root",
")",
":",
"_div",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'span'",
")",
"if",
"ctx",
".",
"options",
"[",
"'embed_styles'",
"]",
":",
"_div",
".",
"set",
"(",... | Serialize math element.
Math objects are not supported at the moment. This is wht we only show error message. | [
"Serialize",
"math",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L253-L266 |
43,866 | booktype/python-ooxml | ooxml/serialize.py | serialize_link | def serialize_link(ctx, document, elem, root):
"""Serilaze link element.
This works only for external links at the moment.
"""
_a = etree.SubElement(root, 'a')
for el in elem.elements:
_ser = ctx.get_serializer(el)
if _ser:
_td = _ser(ctx, document, el, _a)
el... | python | def serialize_link(ctx, document, elem, root):
"""Serilaze link element.
This works only for external links at the moment.
"""
_a = etree.SubElement(root, 'a')
for el in elem.elements:
_ser = ctx.get_serializer(el)
if _ser:
_td = _ser(ctx, document, el, _a)
el... | [
"def",
"serialize_link",
"(",
"ctx",
",",
"document",
",",
"elem",
",",
"root",
")",
":",
"_a",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'a'",
")",
"for",
"el",
"in",
"elem",
".",
"elements",
":",
"_ser",
"=",
"ctx",
".",
"get_serializer",... | Serilaze link element.
This works only for external links at the moment. | [
"Serilaze",
"link",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L268-L299 |
43,867 | booktype/python-ooxml | ooxml/serialize.py | serialize_image | def serialize_image(ctx, document, elem, root):
"""Serialize image element.
This is not abstract enough.
"""
_img = etree.SubElement(root, 'img')
# make path configurable
if elem.rid in document.relationships[ctx.options['relationship']]:
img_src = document.relationships[ctx.options['... | python | def serialize_image(ctx, document, elem, root):
"""Serialize image element.
This is not abstract enough.
"""
_img = etree.SubElement(root, 'img')
# make path configurable
if elem.rid in document.relationships[ctx.options['relationship']]:
img_src = document.relationships[ctx.options['... | [
"def",
"serialize_image",
"(",
"ctx",
",",
"document",
",",
"elem",
",",
"root",
")",
":",
"_img",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'img'",
")",
"# make path configurable",
"if",
"elem",
".",
"rid",
"in",
"document",
".",
"relationships"... | Serialize image element.
This is not abstract enough. | [
"Serialize",
"image",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L302-L319 |
43,868 | booktype/python-ooxml | ooxml/serialize.py | fire_hooks | def fire_hooks(ctx, document, elem, element, hooks):
"""Fire hooks on newly created element.
For each newly created element we will try to find defined hooks and execute them.
:Args:
- ctx (:class:`Context`): Context object
- document (:class:`ooxml.doc.Document`): Document object
- elem... | python | def fire_hooks(ctx, document, elem, element, hooks):
"""Fire hooks on newly created element.
For each newly created element we will try to find defined hooks and execute them.
:Args:
- ctx (:class:`Context`): Context object
- document (:class:`ooxml.doc.Document`): Document object
- elem... | [
"def",
"fire_hooks",
"(",
"ctx",
",",
"document",
",",
"elem",
",",
"element",
",",
"hooks",
")",
":",
"if",
"not",
"hooks",
":",
"return",
"for",
"hook",
"in",
"hooks",
":",
"hook",
"(",
"ctx",
",",
"document",
",",
"elem",
",",
"element",
")"
] | Fire hooks on newly created element.
For each newly created element we will try to find defined hooks and execute them.
:Args:
- ctx (:class:`Context`): Context object
- document (:class:`ooxml.doc.Document`): Document object
- elem (:class:`ooxml.doc.Element`): Element which we serialized
... | [
"Fire",
"hooks",
"on",
"newly",
"created",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L322-L339 |
43,869 | booktype/python-ooxml | ooxml/serialize.py | has_style | def has_style(node):
"""Tells us if node element has defined styling.
:Args:
- node (:class:`ooxml.doc.Element`): Element
:Returns:
True or False
"""
elements = ['b', 'i', 'u', 'strike', 'color', 'jc', 'sz', 'ind', 'superscript', 'subscript', 'small_caps']
return any([True f... | python | def has_style(node):
"""Tells us if node element has defined styling.
:Args:
- node (:class:`ooxml.doc.Element`): Element
:Returns:
True or False
"""
elements = ['b', 'i', 'u', 'strike', 'color', 'jc', 'sz', 'ind', 'superscript', 'subscript', 'small_caps']
return any([True f... | [
"def",
"has_style",
"(",
"node",
")",
":",
"elements",
"=",
"[",
"'b'",
",",
"'i'",
",",
"'u'",
",",
"'strike'",
",",
"'color'",
",",
"'jc'",
",",
"'sz'",
",",
"'ind'",
",",
"'superscript'",
",",
"'subscript'",
",",
"'small_caps'",
"]",
"return",
"any"... | Tells us if node element has defined styling.
:Args:
- node (:class:`ooxml.doc.Element`): Element
:Returns:
True or False | [
"Tells",
"us",
"if",
"node",
"element",
"has",
"defined",
"styling",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L342-L355 |
43,870 | booktype/python-ooxml | ooxml/serialize.py | get_style_css | def get_style_css(ctx, node, embed=True, fontsize=-1):
"""Returns as string defined CSS for this node.
Defined CSS can be different if it is embeded or no. When it is embeded styling
for bold,italic and underline will not be defined with CSS. In that case we
use defined tags <b>,<i>,<u> from the conte... | python | def get_style_css(ctx, node, embed=True, fontsize=-1):
"""Returns as string defined CSS for this node.
Defined CSS can be different if it is embeded or no. When it is embeded styling
for bold,italic and underline will not be defined with CSS. In that case we
use defined tags <b>,<i>,<u> from the conte... | [
"def",
"get_style_css",
"(",
"ctx",
",",
"node",
",",
"embed",
"=",
"True",
",",
"fontsize",
"=",
"-",
"1",
")",
":",
"style",
"=",
"[",
"]",
"if",
"not",
"node",
":",
"return",
"if",
"fontsize",
"in",
"[",
"-",
"1",
",",
"2",
"]",
":",
"if",
... | Returns as string defined CSS for this node.
Defined CSS can be different if it is embeded or no. When it is embeded styling
for bold,italic and underline will not be defined with CSS. In that case we
use defined tags <b>,<i>,<u> from the content.
:Args:
- ctx (:class:`Context`): Context object... | [
"Returns",
"as",
"string",
"defined",
"CSS",
"for",
"this",
"node",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L375-L454 |
43,871 | booktype/python-ooxml | ooxml/serialize.py | get_all_styles | def get_all_styles(document, style):
"""Returns list of styles on which specified style is based on.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Returns:
List of style objects.
"""
classes = []
while Tru... | python | def get_all_styles(document, style):
"""Returns list of styles on which specified style is based on.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Returns:
List of style objects.
"""
classes = []
while Tru... | [
"def",
"get_all_styles",
"(",
"document",
",",
"style",
")",
":",
"classes",
"=",
"[",
"]",
"while",
"True",
":",
"classes",
".",
"insert",
"(",
"0",
",",
"get_style_name",
"(",
"style",
")",
")",
"if",
"style",
".",
"based_on",
":",
"style",
"=",
"d... | Returns list of styles on which specified style is based on.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Returns:
List of style objects. | [
"Returns",
"list",
"of",
"styles",
"on",
"which",
"specified",
"style",
"is",
"based",
"on",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L481-L502 |
43,872 | booktype/python-ooxml | ooxml/serialize.py | get_css_classes | def get_css_classes(document, style):
"""Returns CSS classes for this style.
This function will check all the styles specified style is based on and return their CSS classes.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
... | python | def get_css_classes(document, style):
"""Returns CSS classes for this style.
This function will check all the styles specified style is based on and return their CSS classes.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
... | [
"def",
"get_css_classes",
"(",
"document",
",",
"style",
")",
":",
"lst",
"=",
"[",
"st",
".",
"lower",
"(",
")",
"for",
"st",
"in",
"get_all_styles",
"(",
"document",
",",
"style",
")",
"[",
"-",
"1",
":",
"]",
"]",
"+",
"[",
"'{}-fontsize'",
".",... | Returns CSS classes for this style.
This function will check all the styles specified style is based on and return their CSS classes.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- style (:class:`ooxml.doc.Style`): Style object
:Returns:
String representing all the C... | [
"Returns",
"CSS",
"classes",
"for",
"this",
"style",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L505-L523 |
43,873 | booktype/python-ooxml | ooxml/serialize.py | serialize_symbol | def serialize_symbol(ctx, document, el, root):
"Serialize special symbols."
span = etree.SubElement(root, 'span')
span.text = el.value()
fire_hooks(ctx, document, el, span, ctx.get_hook('symbol'))
return root | python | def serialize_symbol(ctx, document, el, root):
"Serialize special symbols."
span = etree.SubElement(root, 'span')
span.text = el.value()
fire_hooks(ctx, document, el, span, ctx.get_hook('symbol'))
return root | [
"def",
"serialize_symbol",
"(",
"ctx",
",",
"document",
",",
"el",
",",
"root",
")",
":",
"span",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'span'",
")",
"span",
".",
"text",
"=",
"el",
".",
"value",
"(",
")",
"fire_hooks",
"(",
"ctx",
",... | Serialize special symbols. | [
"Serialize",
"special",
"symbols",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L720-L728 |
43,874 | booktype/python-ooxml | ooxml/serialize.py | serialize_footnote | def serialize_footnote(ctx, document, el, root):
"Serializes footnotes."
footnote_num = el.rid
if el.rid not in ctx.footnote_list:
ctx.footnote_id += 1
ctx.footnote_list[el.rid] = ctx.footnote_id
footnote_num = ctx.footnote_list[el.rid]
note = etree.SubElement(root, 'sup')
li... | python | def serialize_footnote(ctx, document, el, root):
"Serializes footnotes."
footnote_num = el.rid
if el.rid not in ctx.footnote_list:
ctx.footnote_id += 1
ctx.footnote_list[el.rid] = ctx.footnote_id
footnote_num = ctx.footnote_list[el.rid]
note = etree.SubElement(root, 'sup')
li... | [
"def",
"serialize_footnote",
"(",
"ctx",
",",
"document",
",",
"el",
",",
"root",
")",
":",
"footnote_num",
"=",
"el",
".",
"rid",
"if",
"el",
".",
"rid",
"not",
"in",
"ctx",
".",
"footnote_list",
":",
"ctx",
".",
"footnote_id",
"+=",
"1",
"ctx",
"."... | Serializes footnotes. | [
"Serializes",
"footnotes",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L731-L749 |
43,875 | booktype/python-ooxml | ooxml/serialize.py | serialize_comment | def serialize_comment(ctx, document, el, root):
"Serializes comment."
# Check if option is turned on
if el.comment_type == 'end':
ctx.opened_comments.remove(el.cid)
else:
if el.comment_type != 'reference':
ctx.opened_comments.append(el.cid)
if ctx.options['comment_... | python | def serialize_comment(ctx, document, el, root):
"Serializes comment."
# Check if option is turned on
if el.comment_type == 'end':
ctx.opened_comments.remove(el.cid)
else:
if el.comment_type != 'reference':
ctx.opened_comments.append(el.cid)
if ctx.options['comment_... | [
"def",
"serialize_comment",
"(",
"ctx",
",",
"document",
",",
"el",
",",
"root",
")",
":",
"# Check if option is turned on",
"if",
"el",
".",
"comment_type",
"==",
"'end'",
":",
"ctx",
".",
"opened_comments",
".",
"remove",
"(",
"el",
".",
"cid",
")",
"els... | Serializes comment. | [
"Serializes",
"comment",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L752-L773 |
43,876 | booktype/python-ooxml | ooxml/serialize.py | serialize_endnote | def serialize_endnote(ctx, document, el, root):
"Serializes endnotes."
footnote_num = el.rid
if el.rid not in ctx.endnote_list:
ctx.endnote_id += 1
ctx.endnote_list[el.rid] = ctx.endnote_id
footnote_num = ctx.endnote_list[el.rid]
note = etree.SubElement(root, 'sup')
link = et... | python | def serialize_endnote(ctx, document, el, root):
"Serializes endnotes."
footnote_num = el.rid
if el.rid not in ctx.endnote_list:
ctx.endnote_id += 1
ctx.endnote_list[el.rid] = ctx.endnote_id
footnote_num = ctx.endnote_list[el.rid]
note = etree.SubElement(root, 'sup')
link = et... | [
"def",
"serialize_endnote",
"(",
"ctx",
",",
"document",
",",
"el",
",",
"root",
")",
":",
"footnote_num",
"=",
"el",
".",
"rid",
"if",
"el",
".",
"rid",
"not",
"in",
"ctx",
".",
"endnote_list",
":",
"ctx",
".",
"endnote_id",
"+=",
"1",
"ctx",
".",
... | Serializes endnotes. | [
"Serializes",
"endnotes",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L776-L794 |
43,877 | booktype/python-ooxml | ooxml/serialize.py | serialize_smarttag | def serialize_smarttag(ctx, document, el, root):
"Serializes smarttag."
if ctx.options['smarttag_span']:
_span = etree.SubElement(root, 'span', {'class': 'smarttag', 'data-smarttag-element': el.element})
else:
_span = root
for elem in el.elements:
_ser = ctx.get_serializer(elem... | python | def serialize_smarttag(ctx, document, el, root):
"Serializes smarttag."
if ctx.options['smarttag_span']:
_span = etree.SubElement(root, 'span', {'class': 'smarttag', 'data-smarttag-element': el.element})
else:
_span = root
for elem in el.elements:
_ser = ctx.get_serializer(elem... | [
"def",
"serialize_smarttag",
"(",
"ctx",
",",
"document",
",",
"el",
",",
"root",
")",
":",
"if",
"ctx",
".",
"options",
"[",
"'smarttag_span'",
"]",
":",
"_span",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'span'",
",",
"{",
"'class'",
":",
... | Serializes smarttag. | [
"Serializes",
"smarttag",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L797-L825 |
43,878 | booktype/python-ooxml | ooxml/serialize.py | serialize_table | def serialize_table(ctx, document, table, root):
"""Serializes table element.
"""
# What we should check really is why do we pass None as root element
# There is a good chance some content is missing after the import
if root is None:
return root
if ctx.ilvl != None:
root = clo... | python | def serialize_table(ctx, document, table, root):
"""Serializes table element.
"""
# What we should check really is why do we pass None as root element
# There is a good chance some content is missing after the import
if root is None:
return root
if ctx.ilvl != None:
root = clo... | [
"def",
"serialize_table",
"(",
"ctx",
",",
"document",
",",
"table",
",",
"root",
")",
":",
"# What we should check really is why do we pass None as root element",
"# There is a good chance some content is missing after the import",
"if",
"root",
"is",
"None",
":",
"return",
... | Serializes table element. | [
"Serializes",
"table",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L828-L879 |
43,879 | booktype/python-ooxml | ooxml/serialize.py | serialize_textbox | def serialize_textbox(ctx, document, txtbox, root):
"""Serialize textbox element."""
_div = etree.SubElement(root, 'div')
_div.set('class', 'textbox')
for elem in txtbox.elements:
_ser = ctx.get_serializer(elem)
if _ser:
_ser(ctx, document, elem, _div)
fire_hooks(ctx,... | python | def serialize_textbox(ctx, document, txtbox, root):
"""Serialize textbox element."""
_div = etree.SubElement(root, 'div')
_div.set('class', 'textbox')
for elem in txtbox.elements:
_ser = ctx.get_serializer(elem)
if _ser:
_ser(ctx, document, elem, _div)
fire_hooks(ctx,... | [
"def",
"serialize_textbox",
"(",
"ctx",
",",
"document",
",",
"txtbox",
",",
"root",
")",
":",
"_div",
"=",
"etree",
".",
"SubElement",
"(",
"root",
",",
"'div'",
")",
"_div",
".",
"set",
"(",
"'class'",
",",
"'textbox'",
")",
"for",
"elem",
"in",
"t... | Serialize textbox element. | [
"Serialize",
"textbox",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L882-L896 |
43,880 | booktype/python-ooxml | ooxml/serialize.py | serialize_elements | def serialize_elements(document, elements, options=None):
"""Serialize list of elements into HTML string.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- elements (list): List of elements
- options (dict): Optional dictionary with :class:`Context` options
:Returns:
... | python | def serialize_elements(document, elements, options=None):
"""Serialize list of elements into HTML string.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- elements (list): List of elements
- options (dict): Optional dictionary with :class:`Context` options
:Returns:
... | [
"def",
"serialize_elements",
"(",
"document",
",",
"elements",
",",
"options",
"=",
"None",
")",
":",
"ctx",
"=",
"Context",
"(",
"document",
",",
"options",
")",
"tree_root",
"=",
"root",
"=",
"etree",
".",
"Element",
"(",
"'div'",
")",
"for",
"elem",
... | Serialize list of elements into HTML string.
:Args:
- document (:class:`ooxml.doc.Document`): Document object
- elements (list): List of elements
- options (dict): Optional dictionary with :class:`Context` options
:Returns:
Returns HTML representation of the document. | [
"Serialize",
"list",
"of",
"elements",
"into",
"HTML",
"string",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L1215-L1239 |
43,881 | booktype/python-ooxml | ooxml/serialize.py | HeaderContext.is_header | def is_header(self, elem, font_size, node, style=None):
"""Used for checking if specific element is a header or not.
:Returns:
True or False
"""
# This logic has been disabled for now. Mark this as header if it has
# been marked during the parsing or mark.
... | python | def is_header(self, elem, font_size, node, style=None):
"""Used for checking if specific element is a header or not.
:Returns:
True or False
"""
# This logic has been disabled for now. Mark this as header if it has
# been marked during the parsing or mark.
... | [
"def",
"is_header",
"(",
"self",
",",
"elem",
",",
"font_size",
",",
"node",
",",
"style",
"=",
"None",
")",
":",
"# This logic has been disabled for now. Mark this as header if it has",
"# been marked during the parsing or mark.",
"# if hasattr(elem, 'possible_header'):",
"# ... | Used for checking if specific element is a header or not.
:Returns:
True or False | [
"Used",
"for",
"checking",
"if",
"specific",
"element",
"is",
"a",
"header",
"or",
"not",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L955-L1002 |
43,882 | booktype/python-ooxml | ooxml/serialize.py | HeaderContext.get_header | def get_header(self, elem, style, node):
"""Returns HTML tag representing specific header for this element.
:Returns:
String representation of HTML tag.
"""
font_size = style
if hasattr(elem, 'possible_header'):
if elem.possible_header:
ret... | python | def get_header(self, elem, style, node):
"""Returns HTML tag representing specific header for this element.
:Returns:
String representation of HTML tag.
"""
font_size = style
if hasattr(elem, 'possible_header'):
if elem.possible_header:
ret... | [
"def",
"get_header",
"(",
"self",
",",
"elem",
",",
"style",
",",
"node",
")",
":",
"font_size",
"=",
"style",
"if",
"hasattr",
"(",
"elem",
",",
"'possible_header'",
")",
":",
"if",
"elem",
".",
"possible_header",
":",
"return",
"'h1'",
"if",
"not",
"... | Returns HTML tag representing specific header for this element.
:Returns:
String representation of HTML tag. | [
"Returns",
"HTML",
"tag",
"representing",
"specific",
"header",
"for",
"this",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L1005-L1029 |
43,883 | booktype/python-ooxml | ooxml/serialize.py | Context.get_serializer | def get_serializer(self, node):
"""Returns serializer for specific element.
:Args:
- node (:class:`ooxml.doc.Element`): Element object
:Returns:
Returns reference to a function which will be used for serialization.
"""
return self.options['serializers'].ge... | python | def get_serializer(self, node):
"""Returns serializer for specific element.
:Args:
- node (:class:`ooxml.doc.Element`): Element object
:Returns:
Returns reference to a function which will be used for serialization.
"""
return self.options['serializers'].ge... | [
"def",
"get_serializer",
"(",
"self",
",",
"node",
")",
":",
"return",
"self",
".",
"options",
"[",
"'serializers'",
"]",
".",
"get",
"(",
"type",
"(",
"node",
")",
",",
"None",
")",
"if",
"type",
"(",
"node",
")",
"in",
"self",
".",
"options",
"["... | Returns serializer for specific element.
:Args:
- node (:class:`ooxml.doc.Element`): Element object
:Returns:
Returns reference to a function which will be used for serialization. | [
"Returns",
"serializer",
"for",
"specific",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/serialize.py#L1105-L1120 |
43,884 | rfk/threading2 | threading2/__init__.py | ThreadGroup.priority | def priority(self,priority):
"""Set the priority for all threads in this group.
If setting priority fails on any thread, the priority of all threads
is restored to its previous value.
"""
with self.__lock:
old_priorities = {}
try:
for thre... | python | def priority(self,priority):
"""Set the priority for all threads in this group.
If setting priority fails on any thread, the priority of all threads
is restored to its previous value.
"""
with self.__lock:
old_priorities = {}
try:
for thre... | [
"def",
"priority",
"(",
"self",
",",
"priority",
")",
":",
"with",
"self",
".",
"__lock",
":",
"old_priorities",
"=",
"{",
"}",
"try",
":",
"for",
"thread",
"in",
"self",
".",
"__threads",
":",
"old_priorities",
"[",
"thread",
"]",
"=",
"thread",
".",
... | Set the priority for all threads in this group.
If setting priority fails on any thread, the priority of all threads
is restored to its previous value. | [
"Set",
"the",
"priority",
"for",
"all",
"threads",
"in",
"this",
"group",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/__init__.py#L104-L124 |
43,885 | rfk/threading2 | threading2/__init__.py | ThreadGroup.affinity | def affinity(self,affinity):
"""Set the affinity for all threads in this group.
If setting affinity fails on any thread, the affinity of all threads
is restored to its previous value.
"""
with self.__lock:
old_affinities = {}
try:
for thre... | python | def affinity(self,affinity):
"""Set the affinity for all threads in this group.
If setting affinity fails on any thread, the affinity of all threads
is restored to its previous value.
"""
with self.__lock:
old_affinities = {}
try:
for thre... | [
"def",
"affinity",
"(",
"self",
",",
"affinity",
")",
":",
"with",
"self",
".",
"__lock",
":",
"old_affinities",
"=",
"{",
"}",
"try",
":",
"for",
"thread",
"in",
"self",
".",
"__threads",
":",
"old_affinities",
"[",
"thread",
"]",
"=",
"thread",
".",
... | Set the affinity for all threads in this group.
If setting affinity fails on any thread, the affinity of all threads
is restored to its previous value. | [
"Set",
"the",
"affinity",
"for",
"all",
"threads",
"in",
"this",
"group",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/__init__.py#L131-L151 |
43,886 | rfk/threading2 | threading2/__init__.py | ThreadGroup.join | def join(self,timeout=None):
"""Join all threads in this group.
If the optional "timeout" argument is given, give up after that many
seconds. This method returns True is the threads were successfully
joined, False if a timeout occurred.
"""
if timeout is None:
... | python | def join(self,timeout=None):
"""Join all threads in this group.
If the optional "timeout" argument is given, give up after that many
seconds. This method returns True is the threads were successfully
joined, False if a timeout occurred.
"""
if timeout is None:
... | [
"def",
"join",
"(",
"self",
",",
"timeout",
"=",
"None",
")",
":",
"if",
"timeout",
"is",
"None",
":",
"for",
"thread",
"in",
"self",
".",
"__threads",
":",
"thread",
".",
"join",
"(",
")",
"else",
":",
"deadline",
"=",
"_time",
"(",
")",
"+",
"t... | Join all threads in this group.
If the optional "timeout" argument is given, give up after that many
seconds. This method returns True is the threads were successfully
joined, False if a timeout occurred. | [
"Join",
"all",
"threads",
"in",
"this",
"group",
"."
] | 7ec234ddd8c0d7e683b1a5c4a79a3d001143189f | https://github.com/rfk/threading2/blob/7ec234ddd8c0d7e683b1a5c4a79a3d001143189f/threading2/__init__.py#L158-L176 |
43,887 | booktype/python-ooxml | ooxml/importer.py | text_length | def text_length(elem):
"""Returns length of the content in this element.
Return value is not correct but it is **good enough***.
"""
if not elem:
return 0
value = elem.value()
try:
value = len(value)
except:
value = 0
try:
for a in elem.elements:
... | python | def text_length(elem):
"""Returns length of the content in this element.
Return value is not correct but it is **good enough***.
"""
if not elem:
return 0
value = elem.value()
try:
value = len(value)
except:
value = 0
try:
for a in elem.elements:
... | [
"def",
"text_length",
"(",
"elem",
")",
":",
"if",
"not",
"elem",
":",
"return",
"0",
"value",
"=",
"elem",
".",
"value",
"(",
")",
"try",
":",
"value",
"=",
"len",
"(",
"value",
")",
"except",
":",
"value",
"=",
"0",
"try",
":",
"for",
"a",
"i... | Returns length of the content in this element.
Return value is not correct but it is **good enough***. | [
"Returns",
"length",
"of",
"the",
"content",
"in",
"this",
"element",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/importer.py#L21-L43 |
43,888 | booktype/python-ooxml | ooxml/docxfile.py | DOCXFile.reset | def reset(self):
"Resets the values."
self.zf = zipfile.ZipFile(self.file_name, 'r')
self._doc = None | python | def reset(self):
"Resets the values."
self.zf = zipfile.ZipFile(self.file_name, 'r')
self._doc = None | [
"def",
"reset",
"(",
"self",
")",
":",
"self",
".",
"zf",
"=",
"zipfile",
".",
"ZipFile",
"(",
"self",
".",
"file_name",
",",
"'r'",
")",
"self",
".",
"_doc",
"=",
"None"
] | Resets the values. | [
"Resets",
"the",
"values",
"."
] | b56990a5bee2e1bc46839cec5161ff3726dc4d87 | https://github.com/booktype/python-ooxml/blob/b56990a5bee2e1bc46839cec5161ff3726dc4d87/ooxml/docxfile.py#L39-L43 |
43,889 | jazzband/django-ical | django_ical/utils.py | build_rrule | def build_rrule(count=None, interval=None, bysecond=None, byminute=None,
byhour=None, byweekno=None, bymonthday=None, byyearday=None,
bymonth=None, until=None, bysetpos=None, wkst=None, byday=None,
freq=None):
"""
Build rrule dictionary for vRecur class.
:par... | python | def build_rrule(count=None, interval=None, bysecond=None, byminute=None,
byhour=None, byweekno=None, bymonthday=None, byyearday=None,
bymonth=None, until=None, bysetpos=None, wkst=None, byday=None,
freq=None):
"""
Build rrule dictionary for vRecur class.
:par... | [
"def",
"build_rrule",
"(",
"count",
"=",
"None",
",",
"interval",
"=",
"None",
",",
"bysecond",
"=",
"None",
",",
"byminute",
"=",
"None",
",",
"byhour",
"=",
"None",
",",
"byweekno",
"=",
"None",
",",
"bymonthday",
"=",
"None",
",",
"byyearday",
"=",
... | Build rrule dictionary for vRecur class.
:param count: int
:param interval: int
:param bysecond: int
:param byminute: int
:param byhour: int
:param byweekno: int
:param bymonthday: int
:param byyearday: int
:param bymonth: int
:param until: datetime
:param bysetpos: int
... | [
"Build",
"rrule",
"dictionary",
"for",
"vRecur",
"class",
"."
] | 7d616b9e319509b56c3ddab8cac18b0439f33b59 | https://github.com/jazzband/django-ical/blob/7d616b9e319509b56c3ddab8cac18b0439f33b59/django_ical/utils.py#L12-L82 |
43,890 | jazzband/django-ical | django_ical/utils.py | build_rrule_from_recurrences_rrule | def build_rrule_from_recurrences_rrule(rule):
"""
Build rrule dictionary for vRecur class from a django_recurrences rrule.
django_recurrences is a popular implementation for recurrences in django.
https://pypi.org/project/django-recurrence/
this is a shortcut to interface between recurrences and ic... | python | def build_rrule_from_recurrences_rrule(rule):
"""
Build rrule dictionary for vRecur class from a django_recurrences rrule.
django_recurrences is a popular implementation for recurrences in django.
https://pypi.org/project/django-recurrence/
this is a shortcut to interface between recurrences and ic... | [
"def",
"build_rrule_from_recurrences_rrule",
"(",
"rule",
")",
":",
"from",
"recurrence",
"import",
"serialize",
"line",
"=",
"serialize",
"(",
"rule",
")",
"if",
"line",
".",
"startswith",
"(",
"'RRULE:'",
")",
":",
"line",
"=",
"line",
"[",
"6",
":",
"]"... | Build rrule dictionary for vRecur class from a django_recurrences rrule.
django_recurrences is a popular implementation for recurrences in django.
https://pypi.org/project/django-recurrence/
this is a shortcut to interface between recurrences and icalendar. | [
"Build",
"rrule",
"dictionary",
"for",
"vRecur",
"class",
"from",
"a",
"django_recurrences",
"rrule",
"."
] | 7d616b9e319509b56c3ddab8cac18b0439f33b59 | https://github.com/jazzband/django-ical/blob/7d616b9e319509b56c3ddab8cac18b0439f33b59/django_ical/utils.py#L91-L103 |
43,891 | jazzband/django-ical | django_ical/utils.py | build_rrule_from_dateutil_rrule | def build_rrule_from_dateutil_rrule(rule):
"""
Build rrule dictionary for vRecur class from a dateutil rrule.
Dateutils rrule is a popular implementation of rrule in python.
https://pypi.org/project/python-dateutil/
this is a shortcut to interface between dateutil and icalendar.
"""
lines =... | python | def build_rrule_from_dateutil_rrule(rule):
"""
Build rrule dictionary for vRecur class from a dateutil rrule.
Dateutils rrule is a popular implementation of rrule in python.
https://pypi.org/project/python-dateutil/
this is a shortcut to interface between dateutil and icalendar.
"""
lines =... | [
"def",
"build_rrule_from_dateutil_rrule",
"(",
"rule",
")",
":",
"lines",
"=",
"str",
"(",
"rule",
")",
".",
"splitlines",
"(",
")",
"for",
"line",
"in",
"lines",
":",
"if",
"line",
".",
"startswith",
"(",
"'DTSTART:'",
")",
":",
"continue",
"if",
"line"... | Build rrule dictionary for vRecur class from a dateutil rrule.
Dateutils rrule is a popular implementation of rrule in python.
https://pypi.org/project/python-dateutil/
this is a shortcut to interface between dateutil and icalendar. | [
"Build",
"rrule",
"dictionary",
"for",
"vRecur",
"class",
"from",
"a",
"dateutil",
"rrule",
"."
] | 7d616b9e319509b56c3ddab8cac18b0439f33b59 | https://github.com/jazzband/django-ical/blob/7d616b9e319509b56c3ddab8cac18b0439f33b59/django_ical/utils.py#L106-L120 |
43,892 | jazzband/django-ical | django_ical/feedgenerator.py | ICal20Feed.write | def write(self, outfile, encoding):
u"""
Writes the feed to the specified file in the
specified encoding.
"""
cal = Calendar()
cal.add('version', '2.0')
cal.add('calscale', 'GREGORIAN')
for ifield, efield in FEED_FIELD_MAP:
val = self.feed.get... | python | def write(self, outfile, encoding):
u"""
Writes the feed to the specified file in the
specified encoding.
"""
cal = Calendar()
cal.add('version', '2.0')
cal.add('calscale', 'GREGORIAN')
for ifield, efield in FEED_FIELD_MAP:
val = self.feed.get... | [
"def",
"write",
"(",
"self",
",",
"outfile",
",",
"encoding",
")",
":",
"cal",
"=",
"Calendar",
"(",
")",
"cal",
".",
"add",
"(",
"'version'",
",",
"'2.0'",
")",
"cal",
".",
"add",
"(",
"'calscale'",
",",
"'GREGORIAN'",
")",
"for",
"ifield",
",",
"... | u"""
Writes the feed to the specified file in the
specified encoding. | [
"u",
"Writes",
"the",
"feed",
"to",
"the",
"specified",
"file",
"in",
"the",
"specified",
"encoding",
"."
] | 7d616b9e319509b56c3ddab8cac18b0439f33b59 | https://github.com/jazzband/django-ical/blob/7d616b9e319509b56c3ddab8cac18b0439f33b59/django_ical/feedgenerator.py#L80-L99 |
43,893 | jazzband/django-ical | django_ical/feedgenerator.py | ICal20Feed.write_items | def write_items(self, calendar):
"""
Write all events to the calendar
"""
for item in self.items:
event = Event()
for ifield, efield in ITEM_EVENT_FIELD_MAP:
val = item.get(ifield)
if val is not None:
event.add(e... | python | def write_items(self, calendar):
"""
Write all events to the calendar
"""
for item in self.items:
event = Event()
for ifield, efield in ITEM_EVENT_FIELD_MAP:
val = item.get(ifield)
if val is not None:
event.add(e... | [
"def",
"write_items",
"(",
"self",
",",
"calendar",
")",
":",
"for",
"item",
"in",
"self",
".",
"items",
":",
"event",
"=",
"Event",
"(",
")",
"for",
"ifield",
",",
"efield",
"in",
"ITEM_EVENT_FIELD_MAP",
":",
"val",
"=",
"item",
".",
"get",
"(",
"if... | Write all events to the calendar | [
"Write",
"all",
"events",
"to",
"the",
"calendar"
] | 7d616b9e319509b56c3ddab8cac18b0439f33b59 | https://github.com/jazzband/django-ical/blob/7d616b9e319509b56c3ddab8cac18b0439f33b59/django_ical/feedgenerator.py#L101-L111 |
43,894 | barryp/py-amqplib | extras/generate_skeleton_0_8.py | _textlist | def _textlist(self, _addtail=False):
'''Returns a list of text strings contained within an element and its sub-elements.
Helpful for extracting text from prose-oriented XML (such as XHTML or DocBook).
'''
result = []
if (not _addtail) and (self.text is not None):
result.append(self.text)
... | python | def _textlist(self, _addtail=False):
'''Returns a list of text strings contained within an element and its sub-elements.
Helpful for extracting text from prose-oriented XML (such as XHTML or DocBook).
'''
result = []
if (not _addtail) and (self.text is not None):
result.append(self.text)
... | [
"def",
"_textlist",
"(",
"self",
",",
"_addtail",
"=",
"False",
")",
":",
"result",
"=",
"[",
"]",
"if",
"(",
"not",
"_addtail",
")",
"and",
"(",
"self",
".",
"text",
"is",
"not",
"None",
")",
":",
"result",
".",
"append",
"(",
"self",
".",
"text... | Returns a list of text strings contained within an element and its sub-elements.
Helpful for extracting text from prose-oriented XML (such as XHTML or DocBook). | [
"Returns",
"a",
"list",
"of",
"text",
"strings",
"contained",
"within",
"an",
"element",
"and",
"its",
"sub",
"-",
"elements",
"."
] | 2b3a47de34b4712c111d0a55d7ff109dffc2a7b2 | https://github.com/barryp/py-amqplib/blob/2b3a47de34b4712c111d0a55d7ff109dffc2a7b2/extras/generate_skeleton_0_8.py#L39-L51 |
43,895 | barryp/py-amqplib | extras/generate_skeleton_0_8.py | _reindent | def _reindent(s, indent, reformat=True):
"""
Remove the existing indentation from each line of a chunk of
text, s, and then prefix each line with a new indent string.
Also removes trailing whitespace from each line, and leading and
trailing blank lines.
"""
s = textwrap.dedent(s)
s = s... | python | def _reindent(s, indent, reformat=True):
"""
Remove the existing indentation from each line of a chunk of
text, s, and then prefix each line with a new indent string.
Also removes trailing whitespace from each line, and leading and
trailing blank lines.
"""
s = textwrap.dedent(s)
s = s... | [
"def",
"_reindent",
"(",
"s",
",",
"indent",
",",
"reformat",
"=",
"True",
")",
":",
"s",
"=",
"textwrap",
".",
"dedent",
"(",
"s",
")",
"s",
"=",
"s",
".",
"split",
"(",
"'\\n'",
")",
"s",
"=",
"[",
"x",
".",
"rstrip",
"(",
")",
"for",
"x",
... | Remove the existing indentation from each line of a chunk of
text, s, and then prefix each line with a new indent string.
Also removes trailing whitespace from each line, and leading and
trailing blank lines. | [
"Remove",
"the",
"existing",
"indentation",
"from",
"each",
"line",
"of",
"a",
"chunk",
"of",
"text",
"s",
"and",
"then",
"prefix",
"each",
"line",
"with",
"a",
"new",
"indent",
"string",
"."
] | 2b3a47de34b4712c111d0a55d7ff109dffc2a7b2 | https://github.com/barryp/py-amqplib/blob/2b3a47de34b4712c111d0a55d7ff109dffc2a7b2/extras/generate_skeleton_0_8.py#L83-L104 |
43,896 | barryp/py-amqplib | extras/generate_skeleton_0_8.py | generate_docstr | def generate_docstr(element, indent='', wrap=None):
"""
Generate a Python docstr for a given element in the AMQP
XML spec file. The element could be a class or method
The 'wrap' parameter is an optional chunk of text that's
added to the beginning and end of the resulting docstring.
"""
re... | python | def generate_docstr(element, indent='', wrap=None):
"""
Generate a Python docstr for a given element in the AMQP
XML spec file. The element could be a class or method
The 'wrap' parameter is an optional chunk of text that's
added to the beginning and end of the resulting docstring.
"""
re... | [
"def",
"generate_docstr",
"(",
"element",
",",
"indent",
"=",
"''",
",",
"wrap",
"=",
"None",
")",
":",
"result",
"=",
"[",
"]",
"txt",
"=",
"element",
".",
"text",
"and",
"element",
".",
"text",
".",
"rstrip",
"(",
")",
"if",
"txt",
":",
"result",... | Generate a Python docstr for a given element in the AMQP
XML spec file. The element could be a class or method
The 'wrap' parameter is an optional chunk of text that's
added to the beginning and end of the resulting docstring. | [
"Generate",
"a",
"Python",
"docstr",
"for",
"a",
"given",
"element",
"in",
"the",
"AMQP",
"XML",
"spec",
"file",
".",
"The",
"element",
"could",
"be",
"a",
"class",
"or",
"method"
] | 2b3a47de34b4712c111d0a55d7ff109dffc2a7b2 | https://github.com/barryp/py-amqplib/blob/2b3a47de34b4712c111d0a55d7ff109dffc2a7b2/extras/generate_skeleton_0_8.py#L107-L160 |
43,897 | barryp/py-amqplib | extras/generate_skeleton_0_8.py | generate_module | def generate_module(spec, out):
"""
Given an AMQP spec parsed into an xml.etree.ElemenTree,
and a file-like 'out' object to write to, generate
the skeleton of a Python module.
"""
#
# HACK THE SPEC so that 'access' is handled by 'channel' instead of 'connection'
#
for amqp_class in ... | python | def generate_module(spec, out):
"""
Given an AMQP spec parsed into an xml.etree.ElemenTree,
and a file-like 'out' object to write to, generate
the skeleton of a Python module.
"""
#
# HACK THE SPEC so that 'access' is handled by 'channel' instead of 'connection'
#
for amqp_class in ... | [
"def",
"generate_module",
"(",
"spec",
",",
"out",
")",
":",
"#",
"# HACK THE SPEC so that 'access' is handled by 'channel' instead of 'connection'",
"#",
"for",
"amqp_class",
"in",
"spec",
".",
"findall",
"(",
"'class'",
")",
":",
"if",
"amqp_class",
".",
"attrib",
... | Given an AMQP spec parsed into an xml.etree.ElemenTree,
and a file-like 'out' object to write to, generate
the skeleton of a Python module. | [
"Given",
"an",
"AMQP",
"spec",
"parsed",
"into",
"an",
"xml",
".",
"etree",
".",
"ElemenTree",
"and",
"a",
"file",
"-",
"like",
"out",
"object",
"to",
"write",
"to",
"generate",
"the",
"skeleton",
"of",
"a",
"Python",
"module",
"."
] | 2b3a47de34b4712c111d0a55d7ff109dffc2a7b2 | https://github.com/barryp/py-amqplib/blob/2b3a47de34b4712c111d0a55d7ff109dffc2a7b2/extras/generate_skeleton_0_8.py#L257-L320 |
43,898 | barryp/py-amqplib | amqplib/client_0_8/method_framing.py | MethodReader._process_method_frame | def _process_method_frame(self, channel, payload):
"""
Process Method frames
"""
method_sig = unpack('>HH', payload[:4])
args = AMQPReader(payload[4:])
if method_sig in _CONTENT_METHODS:
#
# Save what we've got so far and wait for the content-hea... | python | def _process_method_frame(self, channel, payload):
"""
Process Method frames
"""
method_sig = unpack('>HH', payload[:4])
args = AMQPReader(payload[4:])
if method_sig in _CONTENT_METHODS:
#
# Save what we've got so far and wait for the content-hea... | [
"def",
"_process_method_frame",
"(",
"self",
",",
"channel",
",",
"payload",
")",
":",
"method_sig",
"=",
"unpack",
"(",
"'>HH'",
",",
"payload",
"[",
":",
"4",
"]",
")",
"args",
"=",
"AMQPReader",
"(",
"payload",
"[",
"4",
":",
"]",
")",
"if",
"meth... | Process Method frames | [
"Process",
"Method",
"frames"
] | 2b3a47de34b4712c111d0a55d7ff109dffc2a7b2 | https://github.com/barryp/py-amqplib/blob/2b3a47de34b4712c111d0a55d7ff109dffc2a7b2/amqplib/client_0_8/method_framing.py#L156-L171 |
43,899 | barryp/py-amqplib | amqplib/client_0_8/channel.py | Channel._alert | def _alert(self, args):
"""
This method allows the server to send a non-fatal warning to
the client. This is used for methods that are normally
asynchronous and thus do not have confirmations, and for which
the server may detect errors that need to be reported. Fatal
er... | python | def _alert(self, args):
"""
This method allows the server to send a non-fatal warning to
the client. This is used for methods that are normally
asynchronous and thus do not have confirmations, and for which
the server may detect errors that need to be reported. Fatal
er... | [
"def",
"_alert",
"(",
"self",
",",
"args",
")",
":",
"reply_code",
"=",
"args",
".",
"read_short",
"(",
")",
"reply_text",
"=",
"args",
".",
"read_shortstr",
"(",
")",
"details",
"=",
"args",
".",
"read_table",
"(",
")",
"self",
".",
"alerts",
".",
"... | This method allows the server to send a non-fatal warning to
the client. This is used for methods that are normally
asynchronous and thus do not have confirmations, and for which
the server may detect errors that need to be reported. Fatal
errors are handled as channel or connection ex... | [
"This",
"method",
"allows",
"the",
"server",
"to",
"send",
"a",
"non",
"-",
"fatal",
"warning",
"to",
"the",
"client",
".",
"This",
"is",
"used",
"for",
"methods",
"that",
"are",
"normally",
"asynchronous",
"and",
"thus",
"do",
"not",
"have",
"confirmation... | 2b3a47de34b4712c111d0a55d7ff109dffc2a7b2 | https://github.com/barryp/py-amqplib/blob/2b3a47de34b4712c111d0a55d7ff109dffc2a7b2/amqplib/client_0_8/channel.py#L99-L132 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.