text_prompt stringlengths 100 17.7k ⌀ | code_prompt stringlengths 7 9.86k ⌀ |
|---|---|
<SYSTEM_TASK:>
Spy usage of given `fn`.
<END_TASK>
<USER_TASK:>
Description:
def spy2(fn): # type: (...) -> None
"""Spy usage of given `fn`.
Patches the module, class or object `fn` lives in, so that all
interactions can be recorded; otherwise executes `fn` as before, so
that all side effects happen a... |
if isinstance(fn, str):
answer = get_obj(fn)
else:
answer = fn
when2(fn, Ellipsis).thenAnswer(answer) |
<SYSTEM_TASK:>
Return a list of templates usable by a model.
<END_TASK>
<USER_TASK:>
Description:
def get_templates(model):
""" Return a list of templates usable by a model. """ |
for template_name, template in templates.items():
if issubclass(template.model, model):
yield (template_name, template.layout._meta.verbose_name) |
<SYSTEM_TASK:>
Get required API keys from environment variables.
<END_TASK>
<USER_TASK:>
Description:
def get_api_envs():
"""Get required API keys from environment variables.""" |
client_id = os.environ.get('CLIENT_ID')
user_id = os.environ.get('USER_ID')
if not client_id or not user_id:
raise ValueError('API keys are not found in the environment')
return client_id, user_id |
<SYSTEM_TASK:>
Function checkAndCreate
<END_TASK>
<USER_TASK:>
Description:
def checkAndCreate(self, key, payload, domainId):
""" Function checkAndCreate
Check if a subnet exists and create it if not
@param key: The targeted subnet
@param payload: The targeted subnet description
... |
if key not in self:
self[key] = payload
oid = self[key]['id']
if not oid:
return False
#~ Ensure subnet contains the domain
subnetDomainIds = []
for domain in self[key]['domains']:
subnetDomainIds.append(domain['id'])
if domain... |
<SYSTEM_TASK:>
Function removeDomain
<END_TASK>
<USER_TASK:>
Description:
def removeDomain(self, subnetId, domainId):
""" Function removeDomain
Delete a domain from a subnet
@param subnetId: The subnet Id
@param domainId: The domainId to be attached wiuth the subnet
@return RETU... |
subnetDomainIds = []
for domain in self[subnetId]['domains']:
subnetDomainIds.append(domain['id'])
subnetDomainIds.remove(domainId)
self[subnetId]["domain_ids"] = subnetDomainIds
return len(self[subnetId]["domains"]) is len(subnetDomainIds) |
<SYSTEM_TASK:>
Mark a callable as exclusive
<END_TASK>
<USER_TASK:>
Description:
def exclusive(via=threading.Lock):
"""
Mark a callable as exclusive
:param via: factory for a Lock to guard the callable
Guards the callable against being entered again before completion.
Explicitly raises a :py:exc:`... |
def make_exclusive(fnc):
fnc_guard = via()
@functools.wraps(fnc)
def exclusive_call(*args, **kwargs):
if fnc_guard.acquire(blocking=False):
try:
return fnc(*args, **kwargs)
finally:
fnc_guard.release()
... |
<SYSTEM_TASK:>
r"""
<END_TASK>
<USER_TASK:>
Description:
def service(flavour):
r"""
Mark a class as implementing a Service
Each Service class must have a ``run`` method, which does not take any arguments.
This method is :py:meth:`~.ServiceRunner.adopt`\ ed after the daemon starts, unless
* the Ser... |
def service_unit_decorator(raw_cls):
__new__ = raw_cls.__new__
def __new_service__(cls, *args, **kwargs):
if __new__ is object.__new__:
self = __new__(cls)
else:
self = __new__(cls, *args, **kwargs)
service_unit = ServiceUnit(self... |
<SYSTEM_TASK:>
Synchronously run ``payload`` and provide its output
<END_TASK>
<USER_TASK:>
Description:
def execute(self, payload, *args, flavour: ModuleType, **kwargs):
"""
Synchronously run ``payload`` and provide its output
If ``*args*`` and/or ``**kwargs`` are provided, pass them to ``payl... |
if args or kwargs:
payload = functools.partial(payload, *args, **kwargs)
return self._meta_runner.run_payload(payload, flavour=flavour) |
<SYSTEM_TASK:>
Concurrently run ``payload`` in the background
<END_TASK>
<USER_TASK:>
Description:
def adopt(self, payload, *args, flavour: ModuleType, **kwargs):
"""
Concurrently run ``payload`` in the background
If ``*args*`` and/or ``**kwargs`` are provided, pass them to ``payload`` upon exe... |
if args or kwargs:
payload = functools.partial(payload, *args, **kwargs)
self._meta_runner.register_payload(payload, flavour=flavour) |
<SYSTEM_TASK:>
Start accepting synchronous, asynchronous and service payloads
<END_TASK>
<USER_TASK:>
Description:
def accept(self):
"""
Start accepting synchronous, asynchronous and service payloads
Since services are globally defined, only one :py:class:`ServiceRunner`
may :py:meth:`a... |
if self._meta_runner:
raise RuntimeError('payloads scheduled for %s before being started' % self)
self._must_shutdown = False
self._logger.info('%s starting', self.__class__.__name__)
# force collecting objects so that defunct, migrated and overwritten services are destroyed... |
<SYSTEM_TASK:>
Shutdown the accept loop and stop running payloads
<END_TASK>
<USER_TASK:>
Description:
def shutdown(self):
"""Shutdown the accept loop and stop running payloads""" |
self._must_shutdown = True
self._is_shutdown.wait()
self._meta_runner.stop() |
<SYSTEM_TASK:>
Transform and push a line to the interpreter.
<END_TASK>
<USER_TASK:>
Description:
def push(self, line):
"""Transform and push a line to the interpreter.
The line should not have a trailing newline; it may have
internal newlines. The line is appended to a buffer and the
... |
if transforms.FROM_EXPERIMENTAL.match(line):
transforms.add_transformers(line)
self.buffer.append("\n")
else:
self.buffer.append(line)
add_pass = False
if line.rstrip(' ').endswith(":"):
add_pass = True
source = "\n".join(self.buf... |
<SYSTEM_TASK:>
Write dict object into file
<END_TASK>
<USER_TASK:>
Description:
def dump(obj, f, preserve=False):
"""Write dict object into file
:param obj: the object to be dumped into toml
:param f: the file object
:param preserve: optional flag to preserve the inline table in result
""" |
if not f.write:
raise TypeError('You can only dump an object into a file object')
encoder = Encoder(f, preserve=preserve)
return encoder.write_dict(obj) |
<SYSTEM_TASK:>
Stringifies a dict as toml
<END_TASK>
<USER_TASK:>
Description:
def dumps(obj, preserve=False):
"""Stringifies a dict as toml
:param obj: the object to be dumped into toml
:param preserve: optional flag to preserve the inline table in result
""" |
f = StringIO()
dump(obj, f, preserve)
return f.getvalue() |
<SYSTEM_TASK:>
Loads licenses from the given directory.
<END_TASK>
<USER_TASK:>
Description:
def license_loader(lic_dir=LIC_DIR):
"""Loads licenses from the given directory.""" |
lics = []
for ln in os.listdir(lic_dir):
lp = os.path.join(lic_dir, ln)
with open(lp) as lf:
txt = lf.read()
lic = License(txt)
lics.append(lic)
return lics |
<SYSTEM_TASK:>
Upload application from file.
<END_TASK>
<USER_TASK:>
Description:
def import_app(files, category, overwrite, id, name):
""" Upload application from file.
By default, file name will be used as application name, with "-vXX.YYY" suffix stripped.
Application is looked up by one of these classif... |
platform = _get_platform()
org = platform.get_organization(QUBELL["organization"])
if category:
category = org.categories[category]
regex = re.compile(r"^(.*?)(-v(\d+)|)\.[^.]+$")
if (id or name) and len(files) > 1:
raise Exception("--id and --name are supported only for single-file... |
<SYSTEM_TASK:>
Read the minified CSS file including STATIC_URL in the references
<END_TASK>
<USER_TASK:>
Description:
def _chosen_css(self):
"""Read the minified CSS file including STATIC_URL in the references
to the sprite images.""" |
css = render_to_string(self.css_template, {})
for sprite in self.chosen_sprites: # rewrite path to sprites in the css
css = css.replace(sprite, settings.STATIC_URL + "img/" + sprite)
return css |
<SYSTEM_TASK:>
Embed Chosen.js directly in html of the response.
<END_TASK>
<USER_TASK:>
Description:
def _embed(self, request, response):
"""Embed Chosen.js directly in html of the response.""" |
if self._match(request, response):
# Render the <link> and the <script> tags to include Chosen.
head = render_to_string(
"chosenadmin/_head_css.html",
{"chosen_css": self._chosen_css()}
)
body = render_to_string(
"c... |
<SYSTEM_TASK:>
Writes an 8-bit byte to the specified command register
<END_TASK>
<USER_TASK:>
Description:
def write_byte(self, cmd, value):
"""
Writes an 8-bit byte to the specified command register
""" |
self.bus.write_byte_data(self.address, cmd, value)
self.log.debug(
"write_byte: Wrote 0x%02X to command register 0x%02X" % (
value, cmd
)
) |
<SYSTEM_TASK:>
Writes a 16-bit word to the specified command register
<END_TASK>
<USER_TASK:>
Description:
def write_word(self, cmd, value):
"""
Writes a 16-bit word to the specified command register
""" |
self.bus.write_word_data(self.address, cmd, value)
self.log.debug(
"write_word: Wrote 0x%04X to command register 0x%02X" % (
value, cmd
)
) |
<SYSTEM_TASK:>
Writes an 8-bit byte directly to the bus
<END_TASK>
<USER_TASK:>
Description:
def write_raw_byte(self, value):
"""
Writes an 8-bit byte directly to the bus
""" |
self.bus.write_byte(self.address, value)
self.log.debug("write_raw_byte: Wrote 0x%02X" % value) |
<SYSTEM_TASK:>
Writes a block of bytes to the bus using I2C format to the specified
<END_TASK>
<USER_TASK:>
Description:
def write_block_data(self, cmd, block):
"""
Writes a block of bytes to the bus using I2C format to the specified
command register
""" |
self.bus.write_i2c_block_data(self.address, cmd, block)
self.log.debug(
"write_block_data: Wrote [%s] to command register 0x%02X" % (
', '.join(['0x%02X' % x for x in block]),
cmd
)
) |
<SYSTEM_TASK:>
Read an 8-bit byte directly from the bus
<END_TASK>
<USER_TASK:>
Description:
def read_raw_byte(self):
"""
Read an 8-bit byte directly from the bus
""" |
result = self.bus.read_byte(self.address)
self.log.debug("read_raw_byte: Read 0x%02X from the bus" % result)
return result |
<SYSTEM_TASK:>
Read a block of bytes from the bus from the specified command register
<END_TASK>
<USER_TASK:>
Description:
def read_block_data(self, cmd, length):
"""
Read a block of bytes from the bus from the specified command register
Amount of bytes read in is defined by length
""" |
results = self.bus.read_i2c_block_data(self.address, cmd, length)
self.log.debug(
"read_block_data: Read [%s] from command register 0x%02X" % (
', '.join(['0x%02X' % x for x in results]),
cmd
)
)
return results |
<SYSTEM_TASK:>
Read an unsigned byte from the specified command register
<END_TASK>
<USER_TASK:>
Description:
def read_unsigned_byte(self, cmd):
"""
Read an unsigned byte from the specified command register
""" |
result = self.bus.read_byte_data(self.address, cmd)
self.log.debug(
"read_unsigned_byte: Read 0x%02X from command register 0x%02X" % (
result, cmd
)
)
return result |
<SYSTEM_TASK:>
Read an unsigned word from the specified command register
<END_TASK>
<USER_TASK:>
Description:
def read_unsigned_word(self, cmd, little_endian=True):
"""
Read an unsigned word from the specified command register
We assume the data is in little endian mode, if it is in big endian
... |
result = self.bus.read_word_data(self.address, cmd)
if not little_endian:
result = ((result << 8) & 0xFF00) + (result >> 8)
self.log.debug(
"read_unsigned_word: Read 0x%04X from command register 0x%02X" % (
result, cmd
)
)
re... |
<SYSTEM_TASK:>
Attempt to connect to an I2C bus
<END_TASK>
<USER_TASK:>
Description:
def __connect_to_bus(self, bus):
"""
Attempt to connect to an I2C bus
""" |
def connect(bus_num):
try:
self.log.debug("Attempting to connect to bus %s..." % bus_num)
self.bus = smbus.SMBus(bus_num)
self.log.debug("Success")
except IOError:
self.log.debug("Failed")
raise
# I... |
<SYSTEM_TASK:>
Default user to the current version owner.
<END_TASK>
<USER_TASK:>
Description:
def get_formset(self, request, obj=None, **kwargs):
""" Default user to the current version owner. """ |
data = super().get_formset(request, obj, **kwargs)
if obj:
data.form.base_fields['user'].initial = request.user.id
return data |
<SYSTEM_TASK:>
Function reload
<END_TASK>
<USER_TASK:>
Description:
def reload(self):
""" Function reload
Reload the full object to ensure sync
""" |
realData = self.load()
self.clear()
self.update(realData) |
<SYSTEM_TASK:>
Process actions in the publishing schedule.
<END_TASK>
<USER_TASK:>
Description:
def process_actions(action_ids=None):
"""
Process actions in the publishing schedule.
Returns the number of actions processed.
""" |
actions_taken = 0
action_list = PublishAction.objects.prefetch_related(
'content_object',
).filter(
scheduled_time__lte=timezone.now(),
)
if action_ids is not None:
action_list = action_list.filter(id__in=action_ids)
for action in action_list:
action.process_ac... |
<SYSTEM_TASK:>
Return a boolean if Celery tasks are enabled for this app.
<END_TASK>
<USER_TASK:>
Description:
def celery_enabled():
"""
Return a boolean if Celery tasks are enabled for this app.
If the ``GLITTER_PUBLISHER_CELERY`` setting is ``True`` or ``False`` - then that value will be
used. Howeve... |
enabled = getattr(settings, 'GLITTER_PUBLISHER_CELERY', None)
if enabled is None:
try:
import celery # noqa
enabled = True
except ImportError:
enabled = False
return enabled |
<SYSTEM_TASK:>
Find regexp in activitylog
<END_TASK>
<USER_TASK:>
Description:
def find(self, item, description='', event_type=''):
"""
Find regexp in activitylog
find record as if type are in description.
""" |
# TODO: should be refactored, dumb logic
if ': ' in item:
splited = item.split(': ', 1)
if splited[0] in self.TYPES:
description = item.split(': ')[1]
event_type = item.split(': ')[0]
else:
description = item
el... |
<SYSTEM_TASK:>
Currently a small stub to create an instance of Checker for the passed
<END_TASK>
<USER_TASK:>
Description:
def do_command_line(infile: typing.IO[str]) -> int:
"""
Currently a small stub to create an instance of Checker for the passed
``infile`` and run its test functions through linting.
... |
lines = infile.readlines()
tree = ast.parse(''.join(lines))
checker = Checker(tree, lines, infile.name)
checker.load()
errors = [] # type: typing.List[AAAError]
for func in checker.all_funcs(skip_noqa=True):
try:
errors = list(func.check_all())
except ValidationErro... |
<SYSTEM_TASK:>
Iterate through multiple lists or arrays of equal size
<END_TASK>
<USER_TASK:>
Description:
def _izip(*iterables):
""" Iterate through multiple lists or arrays of equal size """ |
# This izip routine is from itertools
# izip('ABCD', 'xy') --> Ax By
iterators = map(iter, iterables)
while iterators:
yield tuple(map(next, iterators)) |
<SYSTEM_TASK:>
Check and convert any input scalar or array to numpy array
<END_TASK>
<USER_TASK:>
Description:
def _checkinput(zi, Mi, z=False, verbose=None):
""" Check and convert any input scalar or array to numpy array """ |
# How many halo redshifts provided?
zi = np.array(zi, ndmin=1, dtype=float)
# How many halo masses provided?
Mi = np.array(Mi, ndmin=1, dtype=float)
# Check the input sizes for zi and Mi make sense, if not then exit unless
# one axis is length one, then replicate values to the size of the oth... |
<SYSTEM_TASK:>
Find cosmological parameters for named cosmo in cosmology.py list
<END_TASK>
<USER_TASK:>
Description:
def getcosmo(cosmology):
""" Find cosmological parameters for named cosmo in cosmology.py list """ |
defaultcosmologies = {'dragons': cg.DRAGONS(), 'wmap1': cg.WMAP1_Mill(),
'wmap3': cg.WMAP3_ML(), 'wmap5': cg.WMAP5_mean(),
'wmap7': cg.WMAP7_ML(), 'wmap9': cg.WMAP9_ML(),
'wmap1_lss': cg.WMAP1_2dF_mean(),
'wmap... |
<SYSTEM_TASK:>
Output the cosmology to a string for writing to file
<END_TASK>
<USER_TASK:>
Description:
def _getcosmoheader(cosmo):
""" Output the cosmology to a string for writing to file """ |
cosmoheader = ("# Cosmology (flat) Om:{0:.3f}, Ol:{1:.3f}, h:{2:.2f}, "
"sigma8:{3:.3f}, ns:{4:.2f}".format(
cosmo['omega_M_0'], cosmo['omega_lambda_0'], cosmo['h'],
cosmo['sigma_8'], cosmo['n']))
return(cosmoheader) |
<SYSTEM_TASK:>
NFW conc from Duffy 08 Table 1 for halo mass and redshift
<END_TASK>
<USER_TASK:>
Description:
def cduffy(z, M, vir='200crit', relaxed=True):
""" NFW conc from Duffy 08 Table 1 for halo mass and redshift""" |
if(vir == '200crit'):
if relaxed:
params = [6.71, -0.091, -0.44]
else:
params = [5.71, -0.084, -0.47]
elif(vir == 'tophat'):
if relaxed:
params = [9.23, -0.090, -0.69]
else:
params = [7.85, -0.081, -0.71]
elif(vir == '200mean'... |
<SYSTEM_TASK:>
Returns integral of the linear growth factor from z=200 to z=z
<END_TASK>
<USER_TASK:>
Description:
def _int_growth(z, **cosmo):
""" Returns integral of the linear growth factor from z=200 to z=z """ |
zmax = 200
if hasattr(z, "__len__"):
for zval in z:
assert(zval < zmax)
else:
assert(z < zmax)
y, yerr = scipy.integrate.quad(
lambda z: (1 + z)/(cosmo['omega_M_0']*(1 + z)**3 +
cosmo['omega_lambda_0'])**(1.5),
z, zmax)
retu... |
<SYSTEM_TASK:>
Returns linear growth factor at a given redshift, normalised to z=0
<END_TASK>
<USER_TASK:>
Description:
def growthfactor(z, norm=True, **cosmo):
""" Returns linear growth factor at a given redshift, normalised to z=0
by default, for a given cosmology
Parameters
----------
z : f... |
H = np.sqrt(cosmo['omega_M_0'] * (1 + z)**3 +
cosmo['omega_lambda_0'])
growthval = H * _int_growth(z, **cosmo)
if norm:
growthval /= _int_growth(0, **cosmo)
return(growthval) |
<SYSTEM_TASK:>
Calculate growth rate indices a_tilde and b_tilde
<END_TASK>
<USER_TASK:>
Description:
def calc_ab(zi, Mi, **cosmo):
""" Calculate growth rate indices a_tilde and b_tilde
Parameters
----------
zi : float
Redshift
Mi : float
Halo mass at redshift 'zi'
cosmo : dict
... |
# When zi = 0, the a_tilde becomes alpha and b_tilde becomes beta
# Eqn 23 of Correa et al 2015a (analytically solve from Eqn 16 and 17)
# Arbitray formation redshift, z_-2 in COM is more physically motivated
zf = -0.0064 * (np.log10(Mi))**2 + 0.0237 * (np.log10(Mi)) + 1.8837
# Eqn 22 of Correa ... |
<SYSTEM_TASK:>
Calculate accretion rate and mass history of a halo at any
<END_TASK>
<USER_TASK:>
Description:
def acc_rate(z, zi, Mi, **cosmo):
""" Calculate accretion rate and mass history of a halo at any
redshift 'z' with mass 'Mi' at a lower redshift 'z'
Parameters
----------
z : float
... |
# Find parameters a_tilde and b_tilde for initial redshift
# use Eqn 9 and 10 of Correa et al. (2015c)
a_tilde, b_tilde = calc_ab(zi, Mi, **cosmo)
# Halo mass at z, in Msol
# use Eqn 8 in Correa et al. (2015c)
Mz = Mi * ((1 + z - zi)**a_tilde) * (np.exp(b_tilde * (z - zi)))
# Accretion ra... |
<SYSTEM_TASK:>
Calculate mass accretion history by looping function acc_rate
<END_TASK>
<USER_TASK:>
Description:
def MAH(z, zi, Mi, **cosmo):
""" Calculate mass accretion history by looping function acc_rate
over redshift steps 'z' for halo of mass 'Mi' at redshift 'zi'
Parameters
----------
z... |
# Ensure that z is a 1D NumPy array
z = np.array(z, ndmin=1, dtype=float)
# Create a full array
dMdt_array = np.empty_like(z)
Mz_array = np.empty_like(z)
for i_ind, zval in enumerate(z):
# Solve the accretion rate and halo mass at each redshift step
dMdt, Mz = acc_rate(zval, ... |
<SYSTEM_TASK:>
Calculate concentration for halo of mass 'M' at redshift 'z'
<END_TASK>
<USER_TASK:>
Description:
def COM(z, M, **cosmo):
""" Calculate concentration for halo of mass 'M' at redshift 'z'
Parameters
----------
z : float / numpy array
Redshift to find concentration of halo
M : ... |
# Check that z and M are arrays
z = np.array(z, ndmin=1, dtype=float)
M = np.array(M, ndmin=1, dtype=float)
# Create array
c_array = np.empty_like(z)
sig_array = np.empty_like(z)
nu_array = np.empty_like(z)
zf_array = np.empty_like(z)
for i_ind, (zval, Mval) in enumerate(_izip(z, ... |
<SYSTEM_TASK:>
Load a configuration and keep it alive for the given context
<END_TASK>
<USER_TASK:>
Description:
def load(config_path: str):
"""
Load a configuration and keep it alive for the given context
:param config_path: path to a configuration file
""" |
# we bind the config to _ to keep it alive
if os.path.splitext(config_path)[1] in ('.yaml', '.yml'):
_ = load_yaml_configuration(config_path, translator=PipelineTranslator())
elif os.path.splitext(config_path)[1] == '.py':
_ = load_python_configuration(config_path)
else:
raise V... |
<SYSTEM_TASK:>
Assets for a given release
<END_TASK>
<USER_TASK:>
Description:
def release_assets(self, release):
"""Assets for a given release
""" |
release = self.as_id(release)
return self.get_list(url='%s/%s/assets' % (self, release)) |
<SYSTEM_TASK:>
Upload a file to a release
<END_TASK>
<USER_TASK:>
Description:
def upload(self, release, filename, content_type=None):
"""Upload a file to a release
:param filename: filename to upload
:param content_type: optional content type
:return: json object from github
""... |
release = self.as_id(release)
name = os.path.basename(filename)
if not content_type:
content_type, _ = mimetypes.guess_type(name)
if not content_type:
raise ValueError('content_type not known')
inputs = {'name': name}
url = '%s%s/%s/assets' % (sel... |
<SYSTEM_TASK:>
Validate ``tag_name`` with the latest tag from github
<END_TASK>
<USER_TASK:>
Description:
def validate_tag(self, tag_name, prefix=None):
"""Validate ``tag_name`` with the latest tag from github
If ``tag_name`` is a valid candidate, return the latest tag from github
""" |
new_version = semantic_version(tag_name)
current = self.latest()
if current:
tag_name = current['tag_name']
if prefix:
tag_name = tag_name[len(prefix):]
tag_name = semantic_version(tag_name)
if tag_name >= new_version:
... |
<SYSTEM_TASK:>
Return the full reddit URL associated with the usernote.
<END_TASK>
<USER_TASK:>
Description:
def full_url(self):
"""Return the full reddit URL associated with the usernote.
Arguments:
subreddit: the subreddit name for the note (PRAW Subreddit object)
""" |
if self.link == '':
return None
else:
return Note._expand_url(self.link, self.subreddit) |
<SYSTEM_TASK:>
Convert a reddit URL into the short-hand used by usernotes.
<END_TASK>
<USER_TASK:>
Description:
def _compress_url(link):
"""Convert a reddit URL into the short-hand used by usernotes.
Arguments:
link: a link to a comment, submission, or message (str)
Returns a Strin... |
comment_re = re.compile(r'/comments/([A-Za-z\d]{2,})(?:/[^\s]+/([A-Za-z\d]+))?')
message_re = re.compile(r'/message/messages/([A-Za-z\d]+)')
matches = re.findall(comment_re, link)
if len(matches) == 0:
matches = re.findall(message_re, link)
if len(matches) == 0... |
<SYSTEM_TASK:>
Convert a usernote's URL short-hand into a full reddit URL.
<END_TASK>
<USER_TASK:>
Description:
def _expand_url(short_link, subreddit=None):
"""Convert a usernote's URL short-hand into a full reddit URL.
Arguments:
subreddit: the subreddit the URL is for (PRAW Subreddit obje... |
# Some URL structures for notes
message_scheme = 'https://reddit.com/message/messages/{}'
comment_scheme = 'https://reddit.com/r/{}/comments/{}/-/{}'
post_scheme = 'https://reddit.com/r/{}/comments/{}/'
if short_link == '':
return None
else:
part... |
<SYSTEM_TASK:>
Get the JSON stored on the usernotes wiki page.
<END_TASK>
<USER_TASK:>
Description:
def get_json(self):
"""Get the JSON stored on the usernotes wiki page.
Returns a dict representation of the usernotes (with the notes BLOB
decoded).
Raises:
RuntimeError if t... |
try:
usernotes = self.subreddit.wiki[self.page_name].content_md
notes = json.loads(usernotes)
except NotFound:
self._init_notes()
else:
if notes['ver'] != self.schema:
raise RuntimeError(
'Usernotes schema is v{... |
<SYSTEM_TASK:>
Set up the UserNotes page with the initial JSON schema.
<END_TASK>
<USER_TASK:>
Description:
def _init_notes(self):
"""Set up the UserNotes page with the initial JSON schema.""" |
self.cached_json = {
'ver': self.schema,
'users': {},
'constants': {
'users': [x.name for x in self.subreddit.moderator()],
'warnings': Note.warnings
}
}
self.set_json('Initializing JSON via puni', True) |
<SYSTEM_TASK:>
Send the JSON from the cache to the usernotes wiki page.
<END_TASK>
<USER_TASK:>
Description:
def set_json(self, reason='', new_page=False):
"""Send the JSON from the cache to the usernotes wiki page.
Arguments:
reason: the change reason that will be posted to the wiki change... |
compressed_json = json.dumps(self._compress_json(self.cached_json))
if len(compressed_json) > self.max_page_size:
raise OverflowError(
'Usernotes page is too large (>{0} characters)'.
format(self.max_page_size)
)
if new_page:
... |
<SYSTEM_TASK:>
Return a list of Note objects for the given user.
<END_TASK>
<USER_TASK:>
Description:
def get_notes(self, user):
"""Return a list of Note objects for the given user.
Return an empty list if no notes are found.
Arguments:
user: the user to search for in the usernotes... |
# Try to search for all notes on a user, return an empty list if none
# are found.
try:
users_notes = []
for note in self.cached_json['users'][user]['ns']:
users_notes.append(Note(
user=user,
note=note['n'],
... |
<SYSTEM_TASK:>
Decompress the BLOB portion of the usernotes.
<END_TASK>
<USER_TASK:>
Description:
def _expand_json(self, j):
"""Decompress the BLOB portion of the usernotes.
Arguments:
j: the JSON returned from the wiki page (dict)
Returns a Dict with the 'blob' key removed and a '... |
decompressed_json = copy.copy(j)
decompressed_json.pop('blob', None) # Remove BLOB portion of JSON
# Decode and decompress JSON
compressed_data = base64.b64decode(j['blob'])
original_json = zlib.decompress(compressed_data).decode('utf-8')
decompressed_json['users'] = ... |
<SYSTEM_TASK:>
Compress the BLOB data portion of the usernotes.
<END_TASK>
<USER_TASK:>
Description:
def _compress_json(self, j):
"""Compress the BLOB data portion of the usernotes.
Arguments:
j: the JSON in Schema v5 format (dict)
Returns a dict with the 'users' key removed and 'b... |
compressed_json = copy.copy(j)
compressed_json.pop('users', None)
compressed_data = zlib.compress(
json.dumps(j['users']).encode('utf-8'),
self.zlib_compression_strength
)
b64_data = base64.b64encode(compressed_data).decode('utf-8')
compressed_j... |
<SYSTEM_TASK:>
Add a note to the usernotes wiki page.
<END_TASK>
<USER_TASK:>
Description:
def add_note(self, note):
"""Add a note to the usernotes wiki page.
Arguments:
note: the note to be added (Note)
Returns the update message for the usernotes wiki
Raises:
... |
notes = self.cached_json
if not note.moderator:
note.moderator = self.r.user.me().name
# Get index of moderator in mod list from usernotes
# Add moderator to list if not already there
try:
mod_index = notes['constants']['users'].index(note.moderator)
... |
<SYSTEM_TASK:>
Remove a single usernote from the usernotes.
<END_TASK>
<USER_TASK:>
Description:
def remove_note(self, username, index):
"""Remove a single usernote from the usernotes.
Arguments:
username: the user that for whom you're removing a note (str)
index: the index of t... |
self.cached_json['users'][username]['ns'].pop(index)
# Go ahead and remove the user's entry if they have no more notes left
if len(self.cached_json['users'][username]['ns']) == 0:
del self.cached_json['users'][username]
return '"delete note #{} on user {}" via puni'.format... |
<SYSTEM_TASK:>
Return the first matching target application in this version range.
<END_TASK>
<USER_TASK:>
Description:
def get_related_targetApplication(vR, app_id, app_ver):
"""Return the first matching target application in this version range.
Returns None if there are no target applications or no matching o... |
targetApplication = vR.get('targetApplication')
if not targetApplication:
return None
for tA in targetApplication:
guid = tA.get('guid')
if not guid or guid == app_id:
if not app_ver:
return tA
# We purposefully use maxVersion only, so that t... |
<SYSTEM_TASK:>
Generate the addons blocklists.
<END_TASK>
<USER_TASK:>
Description:
def write_addons_items(xml_tree, records, app_id, api_ver=3, app_ver=None):
"""Generate the addons blocklists.
<emItem blockID="i372" id="5nc3QHFgcb@r06Ws9gvNNVRfH.com">
<versionRange minVersion="0" maxVersion="*" severit... |
if not records:
return
emItems = etree.SubElement(xml_tree, 'emItems')
groupby = {}
for item in records:
if is_related_to(item, app_id, app_ver):
if item['guid'] in groupby:
emItem = groupby[item['guid']]
# When creating new records from the ... |
<SYSTEM_TASK:>
Create or update a label
<END_TASK>
<USER_TASK:>
Description:
def label(self, name, color, update=True):
"""Create or update a label
""" |
url = '%s/labels' % self
data = dict(name=name, color=color)
response = self.http.post(
url, json=data, auth=self.auth, headers=self.headers
)
if response.status_code == 201:
return True
elif response.status_code == 422 and update:
url... |
<SYSTEM_TASK:>
Check a plaintext password against a hashed password.
<END_TASK>
<USER_TASK:>
Description:
def check_password(password: str, encrypted: str) -> bool:
""" Check a plaintext password against a hashed password. """ |
# some old passwords have {crypt} in lower case, and passlib wants it to be
# in upper case.
if encrypted.startswith("{crypt}"):
encrypted = "{CRYPT}" + encrypted[7:]
return pwd_context.verify(password, encrypted) |
<SYSTEM_TASK:>
Check if version of repository is semantic
<END_TASK>
<USER_TASK:>
Description:
def validate(ctx, sandbox):
"""Check if version of repository is semantic
""" |
m = RepoManager(ctx.obj['agile'])
if not sandbox or m.can_release('sandbox'):
click.echo(m.validate_version()) |
<SYSTEM_TASK:>
Reset transaction back to original state, discarding all
<END_TASK>
<USER_TASK:>
Description:
def reset(self, force_flush_cache: bool = False) -> None:
"""
Reset transaction back to original state, discarding all
uncompleted transactions.
""" |
super(LDAPwrapper, self).reset()
if len(self._transactions) == 0:
raise RuntimeError("reset called outside a transaction.")
self._transactions[-1] = [] |
<SYSTEM_TASK:>
Object state is cached. When an update is required the update will be
<END_TASK>
<USER_TASK:>
Description:
def _cache_get_for_dn(self, dn: str) -> Dict[str, bytes]:
"""
Object state is cached. When an update is required the update will be
simulated on this cache, so that rollback ... |
# no cached item, retrieve from ldap
self._do_with_retry(
lambda obj: obj.search(
dn,
'(objectclass=*)',
ldap3.BASE,
attributes=['*', '+']))
results = self._obj.response
if len(results) < 1:
raise N... |
<SYSTEM_TASK:>
Attempt to commit all changes to LDAP database. i.e. forget all
<END_TASK>
<USER_TASK:>
Description:
def commit(self) -> None:
"""
Attempt to commit all changes to LDAP database. i.e. forget all
rollbacks. However stay inside transaction management.
""" |
if len(self._transactions) == 0:
raise RuntimeError("commit called outside transaction")
# If we have nested transactions, we don't actually commit, but push
# rollbacks up to previous transaction.
if len(self._transactions) > 1:
for on_rollback in reversed(self... |
<SYSTEM_TASK:>
Roll back to previous database state. However stay inside transaction
<END_TASK>
<USER_TASK:>
Description:
def rollback(self) -> None:
"""
Roll back to previous database state. However stay inside transaction
management.
""" |
if len(self._transactions) == 0:
raise RuntimeError("rollback called outside transaction")
_debug("rollback:", self._transactions[-1])
# if something goes wrong here, nothing we can do about it, leave
# database as is.
try:
# for every rollback action ..... |
<SYSTEM_TASK:>
for testing purposes only. always fail in commit
<END_TASK>
<USER_TASK:>
Description:
def fail(self) -> None:
""" for testing purposes only. always fail in commit """ |
_debug("fail")
# on commit carry out action; on rollback reverse rename
def on_commit(_obj):
raise_testfailure("commit")
def on_rollback(_obj):
raise_testfailure("rollback")
return self._process(on_commit, on_rollback) |
<SYSTEM_TASK:>
Spits out the timedelta in days.
<END_TASK>
<USER_TASK:>
Description:
def get_interval_timedelta(self):
""" Spits out the timedelta in days. """ |
now_datetime = timezone.now()
current_month_days = monthrange(now_datetime.year, now_datetime.month)[1]
# Two weeks
if self.interval == reminders_choices.INTERVAL_2_WEEKS:
interval_timedelta = datetime.timedelta(days=14)
# One month
elif self.interval == r... |
<SYSTEM_TASK:>
Execute a runner without blocking the event loop
<END_TASK>
<USER_TASK:>
Description:
async def awaitable_runner(runner: BaseRunner):
"""Execute a runner without blocking the event loop""" |
runner_thread = CapturingThread(target=runner.run)
runner_thread.start()
delay = 0.0
while not runner_thread.join(timeout=0):
await asyncio.sleep(delay)
delay = min(delay + 0.1, 1.0) |
<SYSTEM_TASK:>
Create an ``asyncio`` event loop running in the main thread and watching runners
<END_TASK>
<USER_TASK:>
Description:
def asyncio_main_run(root_runner: BaseRunner):
"""
Create an ``asyncio`` event loop running in the main thread and watching runners
Using ``asyncio`` to handle suprocesses re... |
assert threading.current_thread() == threading.main_thread(), 'only main thread can accept asyncio subprocesses'
if sys.platform == 'win32':
event_loop = asyncio.ProactorEventLoop()
asyncio.set_event_loop(event_loop)
else:
event_loop = asyncio.get_event_loop()
asyncio.get_ch... |
<SYSTEM_TASK:>
Dump initialized object structure to yaml
<END_TASK>
<USER_TASK:>
Description:
def dump(node):
""" Dump initialized object structure to yaml
""" |
from qubell.api.private.platform import Auth, QubellPlatform
from qubell.api.private.organization import Organization
from qubell.api.private.application import Application
from qubell.api.private.instance import Instance
from qubell.api.private.revision import Revision
from qubell.api.private... |
<SYSTEM_TASK:>
Function list
<END_TASK>
<USER_TASK:>
Description:
def list(self, obj, filter=False, only_id=False, limit=20):
""" Function list
Get the list of an object
@param obj: object name ('hosts', 'puppetclasses'...)
@param filter: filter for objects
@param only_id: boole... |
self.url = '{}{}/?per_page={}'.format(self.base_url, obj, limit)
self.method = 'GET'
if filter:
self.url += '&search={}'.format(filter)
self.resp = requests.get(url=self.url, auth=self.auth,
headers=self.headers, cert=self.ca_cert)
if... |
<SYSTEM_TASK:>
Function get
<END_TASK>
<USER_TASK:>
Description:
def get(self, obj, id, sub_object=None):
""" Function get
Get an object by id
@param obj: object name ('hosts', 'puppetclasses'...)
@param id: the id of the object (name or id)
@return RETURN: the targeted object
... |
self.url = '{}{}/{}'.format(self.base_url, obj, id)
self.method = 'GET'
if sub_object:
self.url += '/' + sub_object
self.resp = requests.get(url=self.url, auth=self.auth,
headers=self.headers, cert=self.ca_cert)
if self.__process_resp... |
<SYSTEM_TASK:>
Function get_id_by_name
<END_TASK>
<USER_TASK:>
Description:
def get_id_by_name(self, obj, name):
""" Function get_id_by_name
Get the id of an object
@param obj: object name ('hosts', 'puppetclasses'...)
@param id: the id of the object (name or id)
@return RETURN:... |
list = self.list(obj, filter='name = "{}"'.format(name),
only_id=True, limit=1)
return list[name] if name in list.keys() else False |
<SYSTEM_TASK:>
Function set
<END_TASK>
<USER_TASK:>
Description:
def set(self, obj, id, payload, action='', async=False):
""" Function set
Set an object by id
@param obj: object name ('hosts', 'puppetclasses'...)
@param id: the id of the object (name or id)
@param action: specif... |
self.url = '{}{}/{}'.format(self.base_url, obj, id)
self.method = 'PUT'
if action:
self.url += '/{}'.format(action)
self.payload = json.dumps(payload)
if async:
session = FuturesSession()
return session.put(url=self.url, auth=self.auth,
... |
<SYSTEM_TASK:>
Function create
<END_TASK>
<USER_TASK:>
Description:
def create(self, obj, payload, async=False):
""" Function create
Create an new object
@param obj: object name ('hosts', 'puppetclasses'...)
@param payload: the dict of the payload
@param async: should this reque... |
self.url = self.base_url + obj
self.method = 'POST'
self.payload = json.dumps(payload)
if async:
self.method = 'POST(Async)'
session = FuturesSession()
self.resp = session.post(url=self.url, auth=self.auth,
headers... |
<SYSTEM_TASK:>
Function delete
<END_TASK>
<USER_TASK:>
Description:
def delete(self, obj, id):
""" Function delete
Delete an object by id
@param obj: object name ('hosts', 'puppetclasses'...)
@param id: the id of the object (name or id)
@return RETURN: the server response
... |
self.url = '{}{}/{}'.format(self.base_url, obj, id)
self.method = 'DELETE'
self.resp = requests.delete(url=self.url,
auth=self.auth,
headers=self.headers, cert=self.ca_cert)
return self.__process_resp__(obj) |
<SYSTEM_TASK:>
Modified ``run`` that captures return value and exceptions from ``target``
<END_TASK>
<USER_TASK:>
Description:
def run(self):
"""Modified ``run`` that captures return value and exceptions from ``target``""" |
try:
if self._target:
return_value = self._target(*self._args, **self._kwargs)
if return_value is not None:
self._exception = OrphanedReturn(self, return_value)
except BaseException as err:
self._exception = err
finally... |
<SYSTEM_TASK:>
Decorate functions that modify the internally stored usernotes JSON.
<END_TASK>
<USER_TASK:>
Description:
def update_cache(func):
"""Decorate functions that modify the internally stored usernotes JSON.
Ensures that updates are mirrored onto reddit.
Arguments:
func: the function bein... |
@wraps(func)
def wrapper(self, *args, **kwargs):
"""The wrapper function."""
lazy = kwargs.get('lazy', False)
kwargs.pop('lazy', None)
if not lazy:
self.get_json()
ret = func(self, *args, **kwargs)
# If returning a string assume it is an update mes... |
<SYSTEM_TASK:>
Return a tuple for authenticating a user
<END_TASK>
<USER_TASK:>
Description:
def get_auth():
"""Return a tuple for authenticating a user
If not successful raise ``AgileError``.
""" |
auth = get_auth_from_env()
if auth[0] and auth[1]:
return auth
home = os.path.expanduser("~")
config = os.path.join(home, '.gitconfig')
if not os.path.isfile(config):
raise GithubException('No .gitconfig available')
parser = configparser.ConfigParser()
parser.read(config)
... |
<SYSTEM_TASK:>
Function checkAndCreate
<END_TASK>
<USER_TASK:>
Description:
def checkAndCreate(self, key, payload, osIds):
""" Function checkAndCreate
Check if an architectures exists and create it if not
@param key: The targeted architectures
@param payload: The targeted architectures ... |
if key not in self:
self[key] = payload
oid = self[key]['id']
if not oid:
return False
#~ To be sure the OS list is good, we ensure our os are in the list
for os in self[key]['operatingsystems']:
osIds.add(os['id'])
self[key]["operatin... |
<SYSTEM_TASK:>
Find the common prefix of two or more paths.
<END_TASK>
<USER_TASK:>
Description:
def find_common_prefix(
paths: Sequence[Union[str, pathlib.Path]]
) -> Optional[pathlib.Path]:
"""
Find the common prefix of two or more paths.
::
>>> import pathlib
>>> one = pathlib.Path(... |
counter: collections.Counter = collections.Counter()
for path in paths:
path = pathlib.Path(path)
counter.update([path])
counter.update(path.parents)
valid_paths = sorted(
[path for path, count in counter.items() if count >= len(paths)],
key=lambda x: len(x.parts),
... |
<SYSTEM_TASK:>
r"""Finds executable `name`.
<END_TASK>
<USER_TASK:>
Description:
def find_executable(name: str, flags=os.X_OK) -> List[str]:
r"""Finds executable `name`.
Similar to Unix ``which`` command.
Returns list of zero or more full paths to `name`.
""" |
result = []
extensions = [x for x in os.environ.get("PATHEXT", "").split(os.pathsep) if x]
path = os.environ.get("PATH", None)
if path is None:
return []
for path in os.environ.get("PATH", "").split(os.pathsep):
path = os.path.join(path, name)
if os.access(path, flags):
... |
<SYSTEM_TASK:>
Walks a directory tree.
<END_TASK>
<USER_TASK:>
Description:
def walk(
root_path: Union[str, pathlib.Path], top_down: bool = True
) -> Generator[
Tuple[pathlib.Path, Sequence[pathlib.Path], Sequence[pathlib.Path]], None, None
]:
"""
Walks a directory tree.
Like :py:func:`os.walk` but... |
root_path = pathlib.Path(root_path)
directory_paths, file_paths = [], []
for path in sorted(root_path.iterdir()):
if path.is_dir():
directory_paths.append(path)
else:
file_paths.append(path)
if top_down:
yield root_path, directory_paths, file_paths
fo... |
<SYSTEM_TASK:>
Writes ``contents`` to ``path``.
<END_TASK>
<USER_TASK:>
Description:
def write(
contents: str,
path: Union[str, pathlib.Path],
verbose: bool = False,
logger_func=None,
) -> bool:
"""
Writes ``contents`` to ``path``.
Checks if ``path`` already exists and only write out new co... |
print_func = logger_func or print
path = pathlib.Path(path)
if path.exists():
with path.open("r") as file_pointer:
old_contents = file_pointer.read()
if old_contents == contents:
if verbose:
print_func("preserved {}".format(path))
return F... |
<SYSTEM_TASK:>
Send command without return value, wait for completion, verify success.
<END_TASK>
<USER_TASK:>
Description:
def sendQueryVerify(self, cmd):
""" Send command without return value, wait for completion, verify success.
:param cmd: command to send
""" |
cmd = cmd.strip()
self.logger.debug("sendQueryVerify(%s)", cmd)
if not self.is_connected():
raise socket.error("sendQueryVerify on a disconnected socket")
resp = self.__sendQueryReply(cmd)
if resp != self.reply_ok:
raise XenaCommandException('Command {} ... |
<SYSTEM_TASK:>
Modify a changes to add an automatically generated uidNumber.
<END_TASK>
<USER_TASK:>
Description:
def save_account(changes: Changeset, table: LdapObjectClass, database: Database) -> Changeset:
""" Modify a changes to add an automatically generated uidNumber. """ |
d = {}
settings = database.settings
uid_number = changes.get_value_as_single('uidNumber')
if uid_number is None:
scheme = settings['NUMBER_SCHEME']
first = settings.get('UID_FIRST', 10000)
d['uidNumber'] = Counters.get_and_increment(
scheme, "uidNumber", first,
... |
<SYSTEM_TASK:>
Search for entries in LDAP database.
<END_TASK>
<USER_TASK:>
Description:
def search(self, base, scope, filterstr='(objectClass=*)',
attrlist=None, limit=None) -> Generator[Tuple[str, dict], None, None]:
"""
Search for entries in LDAP database.
""" |
_debug("search", base, scope, filterstr, attrlist, limit)
# first results
if attrlist is None:
attrlist = ldap3.ALL_ATTRIBUTES
elif isinstance(attrlist, set):
attrlist = list(attrlist)
def first_results(obj):
_debug("---> searching ldap", l... |
<SYSTEM_TASK:>
Example shows how to configure environment from scratch
<END_TASK>
<USER_TASK:>
Description:
def prepare_env(org):
""" Example shows how to configure environment from scratch """ |
# Add services
key_service = org.service(type='builtin:cobalt_secure_store', name='Keystore')
wf_service = org.service(type='builtin:workflow_service', name='Workflow', parameters='{}')
# Add services to environment
env = org.environment(name='default')
env.clean()
env.add_service(key_ser... |
<SYSTEM_TASK:>
Commands for devops operations
<END_TASK>
<USER_TASK:>
Description:
def start(ctx, debug, version, config):
"""Commands for devops operations""" |
ctx.obj = {}
ctx.DEBUG = debug
if os.path.isfile(config):
with open(config) as fp:
agile = json.load(fp)
else:
agile = {}
ctx.obj['agile'] = agile
if version:
click.echo(__version__)
ctx.exit(0)
if not ctx.invoked_subcommand:
click.echo(ct... |
<SYSTEM_TASK:>
Duplicate all related objects of obj setting
<END_TASK>
<USER_TASK:>
Description:
def duplicate(obj, value=None, field=None, duplicate_order=None):
"""
Duplicate all related objects of obj setting
field to value. If one of the duplicate
objects has an FK to another duplicate object
u... |
using = router.db_for_write(obj._meta.model)
collector = CloneCollector(using=using)
collector.collect([obj])
collector.sort()
related_models = list(collector.data.keys())
data_snapshot = {}
for key in collector.data.keys():
data_snapshot.update({
key: dict(zip(
... |
<SYSTEM_TASK:>
Enters transaction management for a running thread. It must be balanced
<END_TASK>
<USER_TASK:>
Description:
def enter_transaction_management(using=None):
"""
Enters transaction management for a running thread. It must be balanced
with the appropriate leave_transaction_management call, since ... |
if using is None:
for using in tldap.backend.connections:
connection = tldap.backend.connections[using]
connection.enter_transaction_management()
return
connection = tldap.backend.connections[using]
connection.enter_transaction_management() |
<SYSTEM_TASK:>
Returns True if the current transaction requires a commit for changes to
<END_TASK>
<USER_TASK:>
Description:
def is_dirty(using=None):
"""
Returns True if the current transaction requires a commit for changes to
happen.
""" |
if using is None:
dirty = False
for using in tldap.backend.connections:
connection = tldap.backend.connections[using]
if connection.is_dirty():
dirty = True
return dirty
connection = tldap.backend.connections[using]
return connection.is_dirty(... |
<SYSTEM_TASK:>
Checks whether the transaction manager is in manual or in auto state.
<END_TASK>
<USER_TASK:>
Description:
def is_managed(using=None):
"""
Checks whether the transaction manager is in manual or in auto state.
""" |
if using is None:
managed = False
for using in tldap.backend.connections:
connection = tldap.backend.connections[using]
if connection.is_managed():
managed = True
return managed
connection = tldap.backend.connections[using]
return connection.i... |
<SYSTEM_TASK:>
Does the commit itself and resets the dirty flag.
<END_TASK>
<USER_TASK:>
Description:
def commit(using=None):
"""
Does the commit itself and resets the dirty flag.
""" |
if using is None:
for using in tldap.backend.connections:
connection = tldap.backend.connections[using]
connection.commit()
return
connection = tldap.backend.connections[using]
connection.commit() |
<SYSTEM_TASK:>
This function does the rollback itself and resets the dirty flag.
<END_TASK>
<USER_TASK:>
Description:
def rollback(using=None):
"""
This function does the rollback itself and resets the dirty flag.
""" |
if using is None:
for using in tldap.backend.connections:
connection = tldap.backend.connections[using]
connection.rollback()
return
connection = tldap.backend.connections[using]
connection.rollback() |
<SYSTEM_TASK:>
This decorator activates commit on response. This way, if the view function
<END_TASK>
<USER_TASK:>
Description:
def commit_on_success(using=None):
"""
This decorator activates commit on response. This way, if the view function
runs successfully, a commit is made; if the viewfunc produces an ... |
def entering(using):
enter_transaction_management(using=using)
def exiting(exc_value, using):
try:
if exc_value is not None:
if is_dirty(using=using):
rollback(using=using)
else:
commit(using=using)
finally:
... |
<SYSTEM_TASK:>
Reloads glitter URL patterns if page URLs change.
<END_TASK>
<USER_TASK:>
Description:
def process_request(self, request):
"""
Reloads glitter URL patterns if page URLs change.
Avoids having to restart the server to recreate the glitter URLs being used by Django.
""" |
global _urlconf_pages
page_list = list(
Page.objects.exclude(glitter_app_name='').values_list('id', 'url').order_by('id')
)
with _urlconf_lock:
if page_list != _urlconf_pages:
glitter_urls = 'glitter.urls'
if glitter_urls in sys.... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.