_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q45300
Socket._fair_send
train
async def _fair_send(self, frames): """ Send from the first available, non-blocking peer or wait until one meets the condition. :params frames: The frames to write. :returns: The peer that was used. """ peer = await self._fair_get_out_peer() peer.outbox.w...
python
{ "resource": "" }
q45301
Socket.subscribe
train
async def subscribe(self, topic): """ Subscribe the socket to the specified topic. :param topic: The topic to subscribe to. """ if self.socket_type not in {SUB, XSUB}: raise AssertionError( "A %s socket cannot subscribe." % self.socket_type.decode(), ...
python
{ "resource": "" }
q45302
Socket.unsubscribe
train
async def unsubscribe(self, topic): """ Unsubscribe the socket from the specified topic. :param topic: The topic to unsubscribe from. """ if self.socket_type not in {SUB, XSUB}: raise AssertionError( "A %s socket cannot unsubscribe." % self.socket_typ...
python
{ "resource": "" }
q45303
playerSurrendered
train
def playerSurrendered(cfg): """the player has forceibly left the game""" if cfg.numAgents + cfg.numBots == 2: otherResult = c.RESULT_VICTORY else: otherResult = c.RESULT_UNDECIDED # if multiple players remain, they need to finish the match return assignValue(cfg, c.RESULT_DEFEAT, otherResult)
python
{ "resource": "" }
q45304
idPlayerResults
train
def idPlayerResults(cfg, rawResult): """interpret standard rawResult for all players with known IDs""" result = {} knownPlayers = [] dictResult = {plyrRes.player_id : plyrRes.result for plyrRes in rawResult} for p in cfg.players: if p.playerID and p.playerID in dictResult: # identified playe...
python
{ "resource": "" }
q45305
GenericPositionsAdmin.save_model
train
def save_model(self, request, obj, form, change): """Add an ObjectPosition to the object.""" super(GenericPositionsAdmin, self).save_model(request, obj, form, change) c_type = ContentType.objects.get_for_model(obj) try: Ob...
python
{ "resource": "" }
q45306
managed
train
def managed(name, packages=None, requirements=None, saltenv='base', user=None): """ Create and install python requirements in a conda enviroment pip is installed by default in the new enviroment name : path to the enviroment to be created packages : None single package or list of packages t...
python
{ "resource": "" }
q45307
GridEngineProvider.get_configs
train
def get_configs(self, command): """Compose a dictionary with information for writing the submit script.""" logger.debug("Requesting one block with {} nodes per block and {} tasks per node".format( self.nodes_per_block, self.tasks_per_node)) job_config = {} job_config["submi...
python
{ "resource": "" }
q45308
qr2scad
train
def qr2scad(stream): """Convert black pixels to OpenSCAD cubes.""" img = Image.open(stream) # Convert to black and white 8-bit if img.mode != 'L': img = img.convert('L') # Invert color to get the right bounding box img = ImageOps.invert(img) bbox = img.getbbox() # Crop to on...
python
{ "resource": "" }
q45309
run
train
def run(*args): """Load given `envfile` and run `command` with `params`""" if not args: args = sys.argv[1:] if len(args) < 2: print('Usage: runenv <envfile> <command> <params>') sys.exit(0) os.environ.update(create_env(args[0])) os.environ['_RUNENV_WRAPPED'] = '1' runna...
python
{ "resource": "" }
q45310
create_env
train
def create_env(env_file): """Create environ dictionary from current os.environ and variables got from given `env_file`""" environ = {} with open(env_file, 'r') as f: for line in f.readlines(): line = line.rstrip(os.linesep) if '=' not in line: continue ...
python
{ "resource": "" }
q45311
info
train
def info(args): " Show information about site. " site = find_site(args.PATH) print_header("%s -- install information" % site.get_name()) LOGGER.debug(site.get_info(full=True)) return True
python
{ "resource": "" }
q45312
module
train
def module(args): " Copy module source to current directory. " mod = op.join(settings.MOD_DIR, args.MODULE) assert op.exists(mod), "Not found module: %s" % args.MODULE if not args.DEST.startswith(op.sep): args.DEST = op.join(getcwd(), args.DEST) print_header("Copy module source") copytr...
python
{ "resource": "" }
q45313
uninstall
train
def uninstall(args): " Uninstall site. " site = find_site(args.PATH) site.run_remove() site.clean() if not listdir(op.dirname(site.deploy_dir)): call('sudo rm -rf %s' % op.dirname(site.deploy_dir))
python
{ "resource": "" }
q45314
template
train
def template(args): " Add or remove templates from site. " site = Site(args.PATH) if args.ACTION == "add": return site.add_template(args.TEMPLATE) return site.remove_template(args.TEMPLATE)
python
{ "resource": "" }
q45315
shell
train
def shell(args): " A helper command to be used for shell integration " print print "# Makesite integration " print "# ==================== " print "export MAKESITE_HOME=%s" % args.path print "source %s" % op.join(settings.BASEDIR, 'shell.sh') print
python
{ "resource": "" }
q45316
install
train
def install(args): " Install site from sources or module " # Deactivate virtualenv if 'VIRTUAL_ENV' in environ: LOGGER.warning('Virtualenv enabled: %s' % environ['VIRTUAL_ENV']) # Install from base modules if args.module: args.src = op.join(settings.MOD_DIR, args.module) as...
python
{ "resource": "" }
q45317
autocomplete
train
def autocomplete(force=False): " Shell autocompletion support. " if 'MAKESITE_AUTO_COMPLETE' not in environ and not force: return commands = filter(lambda cmd: cmd != 'main', ACTIONS.keys()) cwords = environ['COMP_WORDS'].split()[1:] cword = int(environ['COMP_CWORD']) try: cu...
python
{ "resource": "" }
q45318
DistanceMatrix._error_and_gradient
train
def _error_and_gradient(self, x): """Compute the error and the gradient. This is the function optimized by :obj:`scipy.optimize.minimize`. Args: x (`array-like`): [`m` * `n`, ] matrix. Returns: `tuple`: containing: - Error (`float`) ...
python
{ "resource": "" }
q45319
DistanceMatrix.optimize
train
def optimize(self, start=None, n=2): """Run multidimensional scaling on this distance matrix. Args: start (`None` or `array-like`): Starting coordinates. If `start=None`, random starting coordinates are used. If `array-like` must have shape [`m` * `n`, ]. ...
python
{ "resource": "" }
q45320
DistanceMatrix.optimize_batch
train
def optimize_batch(self, batchsize=10, returns='best', paralell=True): """ Run multiple optimizations using different starting coordinates. Args: batchsize (`int`): Number of optimizations to run. returns (`str`): If ``'all'``, return results of all optimizations, ...
python
{ "resource": "" }
q45321
Projection.from_optimize_result
train
def from_optimize_result(cls, result, n, m, index=None): """Construct a Projection from the output of an optimization. Args: result (:py:class:`scipy.optimize.OptimizeResult`): Object returned by :py:func:`scipy.optimize.minimize`. n (`int`): Number of dimension...
python
{ "resource": "" }
q45322
Projection._get_samples_shared_with
train
def _get_samples_shared_with(self, other, index=None): """Find samples shared with another dataset. Args: other (:py:class:`pymds.Projection` or :py:class:`pandas.DataFrame` or `array-like`): The other dataset. If `other` is an instance of...
python
{ "resource": "" }
q45323
Projection.plot
train
def plot(self, **kwds): """Plot the coordinates in the first two dimensions of the projection. Removes axis and tick labels, and sets the grid spacing to 1 unit. One way to display the grid is to use `Seaborn`_: Args: **kwds: Passed to :py:meth:`pandas.DataFrame.plot.scatte...
python
{ "resource": "" }
q45324
Projection.plot_lines_to
train
def plot_lines_to(self, other, index=None, **kwds): """Plot lines from samples shared between this projection and another dataset. Args: other (:py:class:`pymds.Projection` or :py:class:`pandas.DataFrame` or `array-like`): The other da...
python
{ "resource": "" }
q45325
Projection.orient_to
train
def orient_to(self, other, index=None, inplace=False, scaling=False): """Orient this Projection to another dataset. Orient this projection using reflection, rotation and translation to match another projection using procrustes superimposition. Scaling is optional. Args: ...
python
{ "resource": "" }
q45326
create
train
def create(name, packages=None, user=None): """ Create a conda env """ packages = packages or '' packages = packages.split(',') packages.append('pip') args = packages + ['--yes', '-q'] cmd = _create_conda_cmd('create', args=args, env=name, user=user) ret = _execcmd(cmd, user=user, re...
python
{ "resource": "" }
q45327
list_
train
def list_(env=None, user=None): """ List the installed packages on an environment Returns ------- Dictionary: {package: {version: 1.0.0, build: 1 } ... } """ cmd = _create_conda_cmd('list', args=['--json'], env=env, user=user) ret = _execcmd(cmd, user=user) if ret['retcode'] == ...
python
{ "resource": "" }
q45328
update
train
def update(packages, env=None, user=None): """ Update conda packages in a conda env Attributes ---------- packages: list of packages comma delimited """ packages = ' '.join(packages.split(',')) cmd = _create_conda_cmd('update', args=[packages, '--yes', '-q'], env=env, user=user) ...
python
{ "resource": "" }
q45329
remove
train
def remove(packages, env=None, user=None): """ Remove conda packages in a conda env Attributes ---------- packages: list of packages comma delimited """ packages = ' '.join(packages.split(',')) cmd = _create_conda_cmd('remove', args=[packages, '--yes', '-q'], env=env, user=user) ...
python
{ "resource": "" }
q45330
_create_conda_cmd
train
def _create_conda_cmd(conda_cmd, args=None, env=None, user=None): """ Utility to create a valid conda command """ cmd = [_get_conda_path(user=user), conda_cmd] if env: cmd.extend(['-n', env]) if args is not None and isinstance(args, list) and args != []: cmd.extend(args) retu...
python
{ "resource": "" }
q45331
UAgentInfo.initDeviceScan
train
def initDeviceScan(self): """Initialize Key Stored Values.""" self.__isIphone = self.detectIphoneOrIpod() self.__isAndroidPhone = self.detectAndroidPhone() self.__isTierTablet = self.detectTierTablet() self.__isTierIphone = self.detectTierIphone() self.__isTierRichCss = s...
python
{ "resource": "" }
q45332
UAgentInfo.detectIphone
train
def detectIphone(self): """Return detection of an iPhone Detects if the current device is an iPhone. """ # The iPad and iPod touch say they're an iPhone! So let's disambiguate. return UAgentInfo.deviceIphone in self.__userAgent \ and not self.detectIpad() \ ...
python
{ "resource": "" }
q45333
UAgentInfo.detectIphoneOrIpod
train
def detectIphoneOrIpod(self): """Return detection of an iPhone or iPod Touch Detects if the current device is an iPhone or iPod Touch. """ #We repeat the searches here because some iPods may report themselves as an iPhone, which would be okay. return UAgentInfo.deviceIphone in s...
python
{ "resource": "" }
q45334
UAgentInfo.detectAndroid
train
def detectAndroid(self): """Return detection of an Android device Detects *any* Android OS-based device: phone, tablet, and multi-media player. Also detects Google TV. """ if UAgentInfo.deviceAndroid in self.__userAgent \ or self.detectGoogleTV(): return T...
python
{ "resource": "" }
q45335
UAgentInfo.detectAndroidPhone
train
def detectAndroidPhone(self): """Return detection of an Android phone Detects if the current device is a (small-ish) Android OS-based device used for calling and/or multi-media (like a Samsung Galaxy Player). Google says these devices will have 'Android' AND 'mobile' in user agent. ...
python
{ "resource": "" }
q45336
UAgentInfo.detectAndroidTablet
train
def detectAndroidTablet(self): """Return detection of an Android tablet Detects if the current device is a (self-reported) Android tablet. Google says these devices will have 'Android' and NOT 'mobile' in their user agent. """ #First, let's make sure we're on an Android device. ...
python
{ "resource": "" }
q45337
UAgentInfo.detectS60OssBrowser
train
def detectS60OssBrowser(self): """Return detection of Symbian S60 Browser Detects if the current browser is the Symbian S60 Open Source Browser. """ #First, test for WebKit, then make sure it's either Symbian or S60. return self.detectWebkit() \ and (UAgentInfo.devic...
python
{ "resource": "" }
q45338
UAgentInfo.detectSymbianOS
train
def detectSymbianOS(self): """Return detection of SymbianOS Detects if the current device is any Symbian OS-based device, including older S60, Series 70, Series 80, Series 90, and UIQ, or other browsers running on these devices. """ return UAgentInfo.deviceSymbian in sel...
python
{ "resource": "" }
q45339
UAgentInfo.detectWindowsMobile
train
def detectWindowsMobile(self): """Return detection of Windows Mobile Detects if the current browser is a Windows Mobile device. Excludes Windows Phone 7 devices. Focuses on Windows Mobile 6.xx and earlier. """ #Exclude new Windows Phone. if self.detectWindowsPhon...
python
{ "resource": "" }
q45340
UAgentInfo.detectBlackBerry
train
def detectBlackBerry(self): """Return detection of Blackberry Detects if the current browser is any BlackBerry. Includes the PlayBook. """ return UAgentInfo.deviceBB in self.__userAgent \ or UAgentInfo.vndRIM in self.__httpAccept
python
{ "resource": "" }
q45341
UAgentInfo.detectBlackBerry10Phone
train
def detectBlackBerry10Phone(self): """Return detection of a Blackberry 10 OS phone Detects if the current browser is a BlackBerry 10 OS phone. Excludes the PlayBook. """ return UAgentInfo.deviceBB10 in self.__userAgent \ and UAgentInfo.mobile in self.__userAgent
python
{ "resource": "" }
q45342
UAgentInfo.detectBlackBerryTouch
train
def detectBlackBerryTouch(self): """Return detection of a Blackberry touchscreen device Detects if the current browser is a BlackBerry Touch device, such as the Storm, Torch, and Bold Touch. Excludes the Playbook. """ return UAgentInfo.deviceBBStorm in self.__userAgent \ ...
python
{ "resource": "" }
q45343
UAgentInfo.detectBlackBerryHigh
train
def detectBlackBerryHigh(self): """Return detection of a Blackberry device with a better browser Detects if the current browser is a BlackBerry device AND has a more capable recent browser. Excludes the Playbook. Examples, Storm, Bold, Tour, Curve2 Excludes the new BlackBerry OS...
python
{ "resource": "" }
q45344
UAgentInfo.detectPalmOS
train
def detectPalmOS(self): """Return detection of a PalmOS device Detects if the current browser is on a PalmOS device. """ #Most devices nowadays report as 'Palm', but some older ones reported as Blazer or Xiino. if UAgentInfo.devicePalm in self.__userAgent \ or UAgentI...
python
{ "resource": "" }
q45345
UAgentInfo.detectWebOSTablet
train
def detectWebOSTablet(self): """Return detection of an HP WebOS tablet Detects if the current browser is on an HP tablet running WebOS. """ return UAgentInfo.deviceWebOShp in self.__userAgent \ and UAgentInfo.deviceTablet in self.__userAgent
python
{ "resource": "" }
q45346
UAgentInfo.detectWebOSTV
train
def detectWebOSTV(self): """Return detection of a WebOS smart TV Detects if the current browser is on a WebOS smart TV. """ return UAgentInfo.deviceWebOStv in self.__userAgent \ and UAgentInfo.smartTV2 in self.__userAgent
python
{ "resource": "" }
q45347
UAgentInfo.detectTizen
train
def detectTizen(self): """Return detection of a Tizen device Detects a device running the Tizen smartphone OS. """ return UAgentInfo.deviceTizen in self.__userAgent \ and UAgentInfo.mobile in self.__userAgent
python
{ "resource": "" }
q45348
UAgentInfo.detectTizenTV
train
def detectTizenTV(self): """Return detection of a Tizen smart TV Detects if the current browser is on a Tizen smart TV. """ return UAgentInfo.deviceTizen in self.__userAgent \ and UAgentInfo.smartTV1 in self.__userAgent
python
{ "resource": "" }
q45349
UAgentInfo.detectMeegoPhone
train
def detectMeegoPhone(self): """Return detection of a Meego phone Detects a phone running the Meego OS. """ return UAgentInfo.deviceMeego in self.__userAgent \ and UAgentInfo.mobi in self.__userAgent
python
{ "resource": "" }
q45350
UAgentInfo.detectFirefoxOSPhone
train
def detectFirefoxOSPhone(self): """Return detection of a Firefox OS phone Detects a phone (probably) running the Firefox OS. """ if self.detectIos() \ or self.detectAndroid() \ or self.detectSailfish(): return False if UAgentInfo.engineFirefo...
python
{ "resource": "" }
q45351
UAgentInfo.detectFirefoxOSTablet
train
def detectFirefoxOSTablet(self): """Return detection of a Firefox OS tablet Detects a tablet (probably) running the Firefox OS. """ if self.detectIos() \ or self.detectAndroid() \ or self.detectSailfish(): return False if UAgentInfo.engineFir...
python
{ "resource": "" }
q45352
UAgentInfo.detectSailfishPhone
train
def detectSailfishPhone(self): """Return detection of a Sailfish phone Detects a phone running the Sailfish OS. """ if self.detectSailfish() \ and UAgentInfo.mobile in self.__userAgent: return True return False
python
{ "resource": "" }
q45353
UAgentInfo.detectUbuntuPhone
train
def detectUbuntuPhone(self): """Return detection of an Ubuntu Mobile OS phone Detects a phone running the Ubuntu Mobile OS. """ if UAgentInfo.deviceUbuntu in self.__userAgent \ and UAgentInfo.mobile in self.__userAgent: return True return False
python
{ "resource": "" }
q45354
UAgentInfo.detectUbuntuTablet
train
def detectUbuntuTablet(self): """Return detection of an Ubuntu Mobile OS tablet Detects a tablet running the Ubuntu Mobile OS. """ if UAgentInfo.deviceUbuntu in self.__userAgent \ and UAgentInfo.deviceTablet in self.__userAgent: return True return False
python
{ "resource": "" }
q45355
UAgentInfo.detectDangerHiptop
train
def detectDangerHiptop(self): """Return detection of a Danger Hiptop Detects the Danger Hiptop device. """ return UAgentInfo.deviceDanger in self.__userAgent \ or UAgentInfo.deviceHiptop in self.__userAgent
python
{ "resource": "" }
q45356
UAgentInfo.detectOperaMobile
train
def detectOperaMobile(self): """Return detection of an Opera browser for a mobile device Detects Opera Mobile or Opera Mini. """ return UAgentInfo.engineOpera in self.__userAgent \ and (UAgentInfo.mini in self.__userAgent or UAgentInfo.mobi in self.__userAgen...
python
{ "resource": "" }
q45357
UAgentInfo.detectWapWml
train
def detectWapWml(self): """Return detection of a WAP- or WML-capable device Detects whether the device supports WAP or WML. """ return UAgentInfo.vndwap in self.__httpAccept \ or UAgentInfo.wml in self.__httpAccept
python
{ "resource": "" }
q45358
UAgentInfo.detectGamingHandheld
train
def detectGamingHandheld(self): """Return detection of a gaming handheld with a modern iPhone-class browser Detects if the current device is a handheld gaming device with a touchscreen and modern iPhone-class browser. Includes the Playstation Vita. """ return UAgentInfo.devicePl...
python
{ "resource": "" }
q45359
UAgentInfo.detectNintendo
train
def detectNintendo(self): """Return detection of Nintendo Detects if the current device is a Nintendo game device. """ return UAgentInfo.deviceNintendo in self.__userAgent \ or UAgentInfo.deviceNintendo in self.__userAgent \ or UAgentInfo.deviceNintendo in self._...
python
{ "resource": "" }
q45360
UAgentInfo.detectMidpCapable
train
def detectMidpCapable(self): """Return detection of a MIDP mobile Java-capable device Detects if the current device supports MIDP, a mobile Java technology. """ return UAgentInfo.deviceMidp in self.__userAgent \ or UAgentInfo.deviceMidp in self.__httpAccept
python
{ "resource": "" }
q45361
UAgentInfo.detectMaemoTablet
train
def detectMaemoTablet(self): """Return detection of a Maemo OS tablet Detects if the current device is on one of the Maemo-based Nokia Internet Tablets. """ if UAgentInfo.maemo in self.__userAgent: return True return UAgentInfo.linux in self.__userAgent \ ...
python
{ "resource": "" }
q45362
UAgentInfo.detectSonyMylo
train
def detectSonyMylo(self): """Return detection of a Sony Mylo device Detects if the current browser is a Sony Mylo device. """ return UAgentInfo.manuSony in self.__userAgent \ and (UAgentInfo.qtembedded in self.__userAgent or UAgentInfo.mylocom2 in self.__user...
python
{ "resource": "" }
q45363
UAgentInfo.detectSmartphone
train
def detectSmartphone(self): """Return detection of a general smartphone device Checks to see whether the device is *any* 'smartphone'. Note: It's better to use DetectTierIphone() for modern touchscreen devices. """ return self.detectTierIphone() \ or self.detectS60Os...
python
{ "resource": "" }
q45364
UAgentInfo.detectMobileQuick
train
def detectMobileQuick(self): """Return detection of any mobile device using the quicker method Detects if the current device is a mobile device. This method catches most of the popular modern devices. Excludes Apple iPads and other modern tablets. """ #Let's exclude tabl...
python
{ "resource": "" }
q45365
UAgentInfo.detectMobileLong
train
def detectMobileLong(self): """Return detection of any mobile device using the more thorough method The longer and more thorough way to detect for a mobile device. Will probably detect most feature phones, smartphone-class devices, Internet Tablets, Internet-enabled game console...
python
{ "resource": "" }
q45366
UAgentInfo.detectTierTablet
train
def detectTierTablet(self): """Return detection of any device in the Tablet Tier The quick way to detect for a tier of devices. This method detects for the new generation of HTML 5 capable, larger screen tablets. Includes iPad, Android (e.g., Xoom), BB Playbook, WebOS, etc. ...
python
{ "resource": "" }
q45367
UAgentInfo.detectTierRichCss
train
def detectTierRichCss(self): """Return detection of any device in the 'Rich CSS' Tier The quick way to detect for a tier of devices. This method detects for devices which are likely to be capable of viewing CSS content optimized for the iPhone, but may not necessarily support Ja...
python
{ "resource": "" }
q45368
Status.str_to_date
train
def str_to_date(self): """ Returns the date attribute as a date object. :returns: Date of the status if it exists. :rtype: date or NoneType """ if hasattr(self, 'date'): return date(*list(map(int, self.date.split('-')))) else: return None
python
{ "resource": "" }
q45369
cancel_on_closing
train
def cancel_on_closing(func): """ Automatically cancels a function or coroutine when the defining instance gets closed. :param func: The function to cancel on closing. :returns: A decorated function or coroutine. """ @wraps(func) async def wrapper(self, *args, **kwargs): return a...
python
{ "resource": "" }
q45370
ClosableAsyncObject.await_until_closing
train
async def await_until_closing(self, coro): """ Wait for some task to complete but aborts as soon asthe instance is being closed. :param coro: The coroutine or future-like object to wait for. """ wait_task = asyncio.ensure_future(self.wait_closing(), loop=self.loop) ...
python
{ "resource": "" }
q45371
ClosableAsyncObject._set_closed
train
def _set_closed(self, future): """ Indicate that the instance is effectively closed. :param future: The close future. """ logger.debug("%s[%s] closed.", self.__class__.__name__, id(self)) self.on_closed.emit(self) self._closed_future.set_result(future.result())
python
{ "resource": "" }
q45372
ClosableAsyncObject.close
train
def close(self): """ Close the instance. """ if not self.closed and not self.closing: logger.debug( "%s[%s] closing...", self.__class__.__name__, id(self), ) self._closing.set() future = async...
python
{ "resource": "" }
q45373
CompositeClosableAsyncObject.register_child
train
def register_child(self, child): """ Register a new child that will be closed whenever the current instance closes. :param child: The child instance. """ if self.closing: child.close() else: self._children.add(child) child.on_c...
python
{ "resource": "" }
q45374
CompositeClosableAsyncObject.unregister_child
train
def unregister_child(self, child): """ Unregister an existing child that is no longer to be owned by the current instance. :param child: The child instance. """ self._children.remove(child) child.on_closed.disconnect(self.unregister_child)
python
{ "resource": "" }
q45375
AsyncTimeout.on_open
train
def on_open(self, callback, timeout): """ Initialize a new timeout. :param callback: The callback to execute when the timeout reaches the end of its life. May be a coroutine function. :param timeout: The maximum time to wait for, in seconds. """ super().on_o...
python
{ "resource": "" }
q45376
AsyncTimeout.revive
train
def revive(self, timeout=None): """ Revive the timeout. :param timeout: If not `None`, specifies a new timeout value to use. """ if timeout is not None: self.timeout = timeout self.revive_event.set()
python
{ "resource": "" }
q45377
AsyncPeriodicTimer.on_open
train
def on_open(self, callback, period): """ Initialize a new timer. :param callback: The function or coroutine function to call on each tick. :param period: The interval of time between two ticks. """ super().on_open() self.callback = callback se...
python
{ "resource": "" }
q45378
AsyncPeriodicTimer.reset
train
def reset(self, period=None): """ Reset the internal timer, effectively causing the next tick to happen in `self.period` seconds. :param period: If not `None`, specifies a new period to use. """ if period is not None: self.period = period self.reset_...
python
{ "resource": "" }
q45379
AsyncBox.read
train
async def read(self): """ Read from the box in a blocking manner. :returns: An item from the box. """ result = await self._queue.get() self._can_write.set() if self._queue.empty(): self._can_read.clear() return result
python
{ "resource": "" }
q45380
AsyncBox.read_nowait
train
def read_nowait(self): """ Read from the box in a non-blocking manner. If the box is empty, an exception is thrown. You should always check for emptiness with `empty` or `wait_not_empty` before calling this method. :returns: An item from the box. """ res...
python
{ "resource": "" }
q45381
AsyncBox.write
train
async def write(self, item): """ Write an item in the queue. :param item: The item. """ await self._queue.put(item) self._can_read.set() if self._queue.full(): self._can_write.clear()
python
{ "resource": "" }
q45382
AsyncBox.write_nowait
train
def write_nowait(self, item): """ Write in the box in a non-blocking manner. If the box is full, an exception is thrown. You should always check for fullness with `full` or `wait_not_full` before calling this method. :param item: An item. """ self._queue.put_now...
python
{ "resource": "" }
q45383
AsyncBox.clone
train
def clone(self): """ Clone the box. :returns: A new box with the same item queue. The cloned box is not closed, no matter the initial state of the original instance. """ result = AsyncBox(maxsize=self._maxsize, loop=self.loop) result._queue = self._queue...
python
{ "resource": "" }
q45384
LValue.get_expr
train
def get_expr(self, ctx): """ Returns the MUF needed to get the contents of the lvalue. Returned MUF will push the contained value onto the stack. """ varname = ctx.lookup_variable(self.varname) if varname is None: val = ctx.lookup_constant(self.varname) ...
python
{ "resource": "" }
q45385
Cluster.create_bare
train
def create_bare(self): """ Create instances for the Bare provider """ self.instances = [] for ip in self.settings['NODES']: new_instance = Instance.new(settings=self.settings, cluster=self) new_instance.ip = ip self.instances.append(new_instanc...
python
{ "resource": "" }
q45386
Cluster.create_cloud
train
def create_cloud(self): """ Create instances for the cloud providers """ instances = [] for i in range(self.settings['NUMBER_NODES']): new_instance = Instance.new(settings=self.settings, cluster=self) instances.append(new_instance) create_nodes = ...
python
{ "resource": "" }
q45387
deserialize_uri
train
def deserialize_uri(value): """ Deserialize a representation of a BNode or URIRef. """ if isinstance(value, BNode): return value if isinstance(value, URIRef): return value if not value: return None if not isinstance(value, basestring): raise ValueError("Cannot...
python
{ "resource": "" }
q45388
serialize_uri
train
def serialize_uri(value): """ Serialize a BNode or URIRef. """ if isinstance(value, BNode): return value.n3() if isinstance(value, URIRef): return unicode(value) raise ValueError("Cannot get prepvalue for {0} of type {1}".format(value, value.__class__))
python
{ "resource": "" }
q45389
CrabGateway.list_gewesten
train
def list_gewesten(self, sort=1): ''' List all `gewesten` in Belgium. :param integer sort: What field to sort on. :rtype: A :class`list` of class: `Gewest`. ''' def creator(): res = crab_gateway_request(self.client, 'ListGewesten', sort) tmp = {} ...
python
{ "resource": "" }
q45390
CrabGateway.get_gewest_by_id
train
def get_gewest_by_id(self, id): ''' Get a `gewest` by id. :param integer id: The id of a `gewest`. :rtype: A :class:`Gewest`. ''' def creator(): nl = crab_gateway_request( self.client, 'GetGewestByGewestIdAndTaalCode', id, 'nl' ) ...
python
{ "resource": "" }
q45391
CrabGateway.list_provincies
train
def list_provincies(self, gewest=2): ''' List all `provincies` in a `gewest`. :param gewest: The :class:`Gewest` for which the \ `provincies` are wanted. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Provincie`. ''' tr...
python
{ "resource": "" }
q45392
CrabGateway.get_provincie_by_id
train
def get_provincie_by_id(self, niscode): ''' Retrieve a `provincie` by the niscode. :param integer niscode: The niscode of the provincie. :rtype: :class:`Provincie` ''' def creator(): for p in self.provincies: if p[0] == niscode: ...
python
{ "resource": "" }
q45393
CrabGateway.list_gemeenten_by_provincie
train
def list_gemeenten_by_provincie(self, provincie): ''' List all `gemeenten` in a `provincie`. :param provincie: The :class:`Provincie` for which the \ `gemeenten` are wanted. :rtype: A :class:`list` of :class:`Gemeente`. ''' try: gewest = provincie...
python
{ "resource": "" }
q45394
CrabGateway.list_gemeenten
train
def list_gemeenten(self, gewest=2, sort=1): ''' List all `gemeenten` in a `gewest`. :param gewest: The :class:`Gewest` for which the \ `gemeenten` are wanted. :param integer sort: What field to sort on. :rtype: A :class:`list` of :class:`Gemeente`. ''' ...
python
{ "resource": "" }
q45395
CrabGateway.get_gemeente_by_id
train
def get_gemeente_by_id(self, id): ''' Retrieve a `gemeente` by the crab id. :param integer id: The CRAB id of the gemeente. :rtype: :class:`Gemeente` ''' def creator(): res = crab_gateway_request( self.client, 'GetGemeenteByGemeenteId', id ...
python
{ "resource": "" }
q45396
CrabGateway.list_deelgemeenten
train
def list_deelgemeenten(self, gewest=2): ''' List all `deelgemeenten` in a `gewest`. :param gewest: The :class:`Gewest` for which the \ `deelgemeenten` are wanted. Currently only Flanders is supported. :rtype: A :class:`list` of :class:`Deelgemeente`. ''' try:...
python
{ "resource": "" }
q45397
CrabGateway.list_deelgemeenten_by_gemeente
train
def list_deelgemeenten_by_gemeente(self, gemeente): ''' List all `deelgemeenten` in a `gemeente`. :param gemeente: The :class:`Gemeente` for which the \ `deelgemeenten` are wanted. Currently only Flanders is supported. :rtype: A :class:`list` of :class:`Deelgemeente`. ...
python
{ "resource": "" }
q45398
CrabGateway.get_deelgemeente_by_id
train
def get_deelgemeente_by_id(self, id): ''' Retrieve a `deelgemeente` by the id. :param string id: The id of the deelgemeente. :rtype: :class:`Deelgemeente` ''' def creator(): if id in self.deelgemeenten: dg = self.deelgemeenten[id] ...
python
{ "resource": "" }
q45399
CrabGateway.list_straten
train
def list_straten(self, gemeente, sort=1): ''' List all `straten` in a `Gemeente`. :param gemeente: The :class:`Gemeente` for which the \ `straten` are wanted. :rtype: A :class:`list` of :class:`Straat` ''' try: id = gemeente.id except Attr...
python
{ "resource": "" }