_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q8800 | not_next | train | def not_next(e):
"""
Create a PEG function for negative lookahead.
"""
def match_not_next(s, grm=None, pos=0):
try:
e(s, grm, pos)
except PegreError as ex:
return PegreResult(s, Ignore, (pos, pos))
else:
raise PegreError('Negative lookahead fai... | python | {
"resource": ""
} |
q8801 | sequence | train | def sequence(*es):
"""
Create a PEG function to match a sequence.
"""
def match_sequence(s, grm=None, pos=0):
data = []
start = pos
for e in es:
s, obj, span = e(s, grm, pos)
pos = span[1]
if obj is not Ignore:
data.append(obj)
... | python | {
"resource": ""
} |
q8802 | choice | train | def choice(*es):
"""
Create a PEG function to match an ordered choice.
"""
msg = 'Expected one of: {}'.format(', '.join(map(repr, es)))
def match_choice(s, grm=None, pos=0):
errs = []
for e in es:
try:
return e(s, grm, pos)
except PegreError as... | python | {
"resource": ""
} |
q8803 | optional | train | def optional(e, default=Ignore):
"""
Create a PEG function to optionally match an expression.
"""
def match_optional(s, grm=None, pos=0):
try:
return e(s, grm, pos)
except PegreError:
return PegreResult(s, default, (pos, pos))
return match_optional | python | {
"resource": ""
} |
q8804 | zero_or_more | train | def zero_or_more(e, delimiter=None):
"""
Create a PEG function to match zero or more expressions.
Args:
e: the expression to match
delimiter: an optional expression to match between the
primary *e* matches.
"""
if delimiter is None:
delimiter = lambda s, grm, pos... | python | {
"resource": ""
} |
q8805 | one_or_more | train | def one_or_more(e, delimiter=None):
"""
Create a PEG function to match one or more expressions.
Args:
e: the expression to match
delimiter: an optional expression to match between the
primary *e* matches.
"""
if delimiter is None:
delimiter = lambda s, grm, pos: ... | python | {
"resource": ""
} |
q8806 | _prepare_axes | train | def _prepare_axes(node, sort_key):
"""
Sort axes and combine those that point to the same target and go
in the same direction.
"""
links = node.links
o_links = node._overlapping_links
overlap = {ax2 for ax in links for ax2 in o_links.get(ax, [])}
axes = []
for axis in sorted(links.ke... | python | {
"resource": ""
} |
q8807 | _lex | train | def _lex(s):
"""
Lex the input string according to _tsql_lex_re.
Yields
(gid, token, line_number)
"""
s += '.' # make sure there's a terminator to know when to stop parsing
lines = enumerate(s.splitlines(), 1)
lineno = pos = 0
try:
for lineno, line in lines:
... | python | {
"resource": ""
} |
q8808 | Bot.get_webhook_info | train | def get_webhook_info(self, ):
"""
Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
https://core.telegram.org/bots/api#getwebhookinfo
... | python | {
"resource": ""
} |
q8809 | Bot.send_contact | train | def send_contact(self, chat_id, phone_number, first_name, last_name=None, vcard=None, disable_notification=None, reply_to_message_id=None, reply_markup=None):
"""
Use this method to send phone contacts. On success, the sent Message is returned.
https://core.telegram.org/bots/api#sendcontact
... | python | {
"resource": ""
} |
q8810 | Bot.restrict_chat_member | train | def restrict_chat_member(self, chat_id, user_id, until_date=None, can_send_messages=None, can_send_media_messages=None, can_send_other_messages=None, can_add_web_page_previews=None):
"""
Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to wo... | python | {
"resource": ""
} |
q8811 | Bot.promote_chat_member | train | def promote_chat_member(self, chat_id, user_id, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None):
"""
Use this method to promote or demote a user in a supergr... | python | {
"resource": ""
} |
q8812 | Bot.set_chat_photo | train | def set_chat_photo(self, chat_id, photo):
"""
Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
Note: In regular ... | python | {
"resource": ""
} |
q8813 | Bot.answer_callback_query | train | def answer_callback_query(self, callback_query_id, text=None, show_alert=None, url=None, cache_time=None):
"""
Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On succe... | python | {
"resource": ""
} |
q8814 | Bot.get_sticker_set | train | def get_sticker_set(self, name):
"""
Use this method to get a sticker set. On success, a StickerSet object is returned.
https://core.telegram.org/bots/api#getstickerset
Parameters:
:param name: Name of the sticker set
:type name: str|unicode
... | python | {
"resource": ""
} |
q8815 | Bot.create_new_sticker_set | train | def create_new_sticker_set(self, user_id, name, title, png_sticker, emojis, contains_masks=None, mask_position=None):
"""
Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success.
https://core.telegram.org/bots/api#... | python | {
"resource": ""
} |
q8816 | Bot.set_sticker_position_in_set | train | def set_sticker_position_in_set(self, sticker, position):
"""
Use this method to move a sticker in a set created by the bot to a specific position . Returns True on success.
https://core.telegram.org/bots/api#setstickerpositioninset
Parameters:
:param sticker:... | python | {
"resource": ""
} |
q8817 | Bot.answer_shipping_query | train | def answer_shipping_query(self, shipping_query_id, ok, shipping_options=None, error_message=None):
"""
If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot. Use this method to reply to shi... | python | {
"resource": ""
} |
q8818 | Bot.send_game | train | def send_game(self, chat_id, game_short_name, disable_notification=None, reply_to_message_id=None, reply_markup=None):
"""
Use this method to send a game. On success, the sent Message is returned.
https://core.telegram.org/bots/api#sendgame
Parameters:
:param ... | python | {
"resource": ""
} |
q8819 | Bot.get_download_url | train | def get_download_url(self, file):
"""
Creates a url to download the file.
Note: Contains the secret API key, so you should not share this url!
:param file: The File you want to get the url to download.
:type file: pytgbot.api_types.receivable.media.File
:return: url
... | python | {
"resource": ""
} |
q8820 | InputMediaVideo.to_array | train | def to_array(self):
"""
Serializes this InputMediaVideo to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
from .files import InputFile
array = super(InputMediaVideo, self).to_array()
# 'type' given by superclass
... | python | {
"resource": ""
} |
q8821 | InputMediaDocument.from_array | train | def from_array(array):
"""
Deserialize a new InputMediaDocument from a given dictionary.
:return: new InputMediaDocument instance.
:rtype: InputMediaDocument
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(array, d... | python | {
"resource": ""
} |
q8822 | REPP.from_config | train | def from_config(cls, path, directory=None):
"""
Instantiate a REPP from a PET-style `.set` configuration file.
The *path* parameter points to the configuration file.
Submodules are loaded from *directory*. If *directory* is not
given, it is the directory part of *path*.
... | python | {
"resource": ""
} |
q8823 | REPP.from_file | train | def from_file(cls, path, directory=None, modules=None, active=None):
"""
Instantiate a REPP from a `.rpp` file.
The *path* parameter points to the top-level module. Submodules
are loaded from *directory*. If *directory* is not given, it is
the directory part of *path*.
... | python | {
"resource": ""
} |
q8824 | REPP.from_string | train | def from_string(cls, s, name=None, modules=None, active=None):
"""
Instantiate a REPP from a string.
Args:
name (str, optional): the name of the REPP module
modules (dict, optional): a mapping from identifiers to
REPP modules
active (iterable,... | python | {
"resource": ""
} |
q8825 | TextMessage.to_array | train | def to_array(self):
"""
Serializes this TextMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(TextMessage, self).to_array()
array['text'] = u(self.text) # py2: type unicode, py3: type str
if self.... | python | {
"resource": ""
} |
q8826 | AudioMessage.to_array | train | def to_array(self):
"""
Serializes this AudioMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(AudioMessage, self).to_array()
if isinstance(self.audio, InputFile):
array['audio'] = self.audio.to... | python | {
"resource": ""
} |
q8827 | AnimationMessage.to_array | train | def to_array(self):
"""
Serializes this AnimationMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(AnimationMessage, self).to_array()
if isinstance(self.animation, InputFile):
array['animation']... | python | {
"resource": ""
} |
q8828 | VoiceMessage.to_array | train | def to_array(self):
"""
Serializes this VoiceMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(VoiceMessage, self).to_array()
if isinstance(self.voice, InputFile):
array['voice'] = self.voice.to... | python | {
"resource": ""
} |
q8829 | VideoNoteMessage.to_array | train | def to_array(self):
"""
Serializes this VideoNoteMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(VideoNoteMessage, self).to_array()
if isinstance(self.video_note, InputFile):
array['video_note... | python | {
"resource": ""
} |
q8830 | MediaGroupMessage.to_array | train | def to_array(self):
"""
Serializes this MediaGroupMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(MediaGroupMessage, self).to_array()
if isinstance(self.media, InputMediaPhoto):
array['media']... | python | {
"resource": ""
} |
q8831 | MediaGroupMessage.from_array | train | def from_array(array):
"""
Deserialize a new MediaGroupMessage from a given dictionary.
:return: new MediaGroupMessage instance.
:rtype: MediaGroupMessage
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(array, dict... | python | {
"resource": ""
} |
q8832 | LocationMessage.to_array | train | def to_array(self):
"""
Serializes this LocationMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(LocationMessage, self).to_array()
array['latitude'] = float(self.latitude) # type float
array['long... | python | {
"resource": ""
} |
q8833 | VenueMessage.to_array | train | def to_array(self):
"""
Serializes this VenueMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(VenueMessage, self).to_array()
array['latitude'] = float(self.latitude) # type float
array['longitude'... | python | {
"resource": ""
} |
q8834 | ContactMessage.to_array | train | def to_array(self):
"""
Serializes this ContactMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(ContactMessage, self).to_array()
array['phone_number'] = u(self.phone_number) # py2: type unicode, py3: type... | python | {
"resource": ""
} |
q8835 | ChatActionMessage.to_array | train | def to_array(self):
"""
Serializes this ChatActionMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(ChatActionMessage, self).to_array()
array['action'] = u(self.action) # py2: type unicode, py3: type str
... | python | {
"resource": ""
} |
q8836 | ChatActionMessage.from_array | train | def from_array(array):
"""
Deserialize a new ChatActionMessage from a given dictionary.
:return: new ChatActionMessage instance.
:rtype: ChatActionMessage
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(array, dict... | python | {
"resource": ""
} |
q8837 | StickerMessage.to_array | train | def to_array(self):
"""
Serializes this StickerMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(StickerMessage, self).to_array()
if isinstance(self.sticker, InputFile):
array['sticker'] = self.... | python | {
"resource": ""
} |
q8838 | InvoiceMessage.to_array | train | def to_array(self):
"""
Serializes this InvoiceMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InvoiceMessage, self).to_array()
array['title'] = u(self.title) # py2: type unicode, py3: type str
... | python | {
"resource": ""
} |
q8839 | GameMessage.to_array | train | def to_array(self):
"""
Serializes this GameMessage to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(GameMessage, self).to_array()
array['game_short_name'] = u(self.game_short_name) # py2: type unicode, py3: type... | python | {
"resource": ""
} |
q8840 | GameMessage.from_array | train | def from_array(array):
"""
Deserialize a new GameMessage from a given dictionary.
:return: new GameMessage instance.
:rtype: GameMessage
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(array, dict, parameter_name="... | python | {
"resource": ""
} |
q8841 | find_subgraphs_by_preds | train | def find_subgraphs_by_preds(xmrs, preds, connected=None):
"""
Yield subgraphs matching a list of predicates.
Predicates may match multiple EPs/nodes in the *xmrs*, meaning that
more than one subgraph is possible. Also, predicates in *preds*
match in number, so if a predicate appears twice in *preds... | python | {
"resource": ""
} |
q8842 | in_labelset | train | def in_labelset(xmrs, nodeids, label=None):
"""
Test if all nodeids share a label.
Args:
nodeids: iterable of nodeids
label (str, optional): the label that all nodeids must share
Returns:
bool: `True` if all nodeids share a label, otherwise `False`
"""
nodeids = set(node... | python | {
"resource": ""
} |
q8843 | InputFile.factory | train | def factory(
cls, file_id=None, path=None, url=None, blob=None, mime=None,
prefer_local_download=True, prefer_str=False, create_instance=True
):
"""
Creates a new InputFile subclass instance fitting the given parameters.
:param prefer_local_download: If `True`, we do... | python | {
"resource": ""
} |
q8844 | PassportData.to_array | train | def to_array(self):
"""
Serializes this PassportData to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(PassportData, self).to_array()
array['data'] = self._as_array(self.data) # type list of EncryptedPassportEleme... | python | {
"resource": ""
} |
q8845 | PassportFile.to_array | train | def to_array(self):
"""
Serializes this PassportFile to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(PassportFile, self).to_array()
array['file_id'] = u(self.file_id) # py2: type unicode, py3: type str
a... | python | {
"resource": ""
} |
q8846 | EncryptedPassportElement.to_array | train | def to_array(self):
"""
Serializes this EncryptedPassportElement to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(EncryptedPassportElement, self).to_array()
array['type'] = u(self.type) # py2: type unicode, py3: ... | python | {
"resource": ""
} |
q8847 | EncryptedCredentials.to_array | train | def to_array(self):
"""
Serializes this EncryptedCredentials to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(EncryptedCredentials, self).to_array()
array['data'] = u(self.data) # py2: type unicode, py3: type str... | python | {
"resource": ""
} |
q8848 | EncryptedCredentials.from_array | train | def from_array(array):
"""
Deserialize a new EncryptedCredentials from a given dictionary.
:return: new EncryptedCredentials instance.
:rtype: EncryptedCredentials
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(ar... | python | {
"resource": ""
} |
q8849 | Bot.get_updates | train | def get_updates(self, offset=None, limit=100, poll_timeout=0, allowed_updates=None, request_timeout=None, delta=timedelta(milliseconds=100), error_as_empty=False):
"""
Use this method to receive incoming updates using long polling. An Array of Update objects is returned.
You can choose to set `... | python | {
"resource": ""
} |
q8850 | Bot.set_game_score | train | def set_game_score(self, user_id, score, force=False, disable_edit_message=False, chat_id=None, message_id=None, inline_message_id=None):
"""
Use this method to set the score of the specified user in a game.
On success, if the message was sent by the bot, returns the edited Message, otherwise re... | python | {
"resource": ""
} |
q8851 | LabeledPrice.to_array | train | def to_array(self):
"""
Serializes this LabeledPrice to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(LabeledPrice, self).to_array()
array['label'] = u(self.label) # py2: type unicode, py3: type str
arra... | python | {
"resource": ""
} |
q8852 | LabeledPrice.from_array | train | def from_array(array):
"""
Deserialize a new LabeledPrice from a given dictionary.
:return: new LabeledPrice instance.
:rtype: LabeledPrice
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(array, dict, parameter_nam... | python | {
"resource": ""
} |
q8853 | ShippingOption.to_array | train | def to_array(self):
"""
Serializes this ShippingOption to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(ShippingOption, self).to_array()
array['id'] = u(self.id) # py2: type unicode, py3: type str
array[... | python | {
"resource": ""
} |
q8854 | _prepare_target | train | def _prepare_target(ts, tables, buffer_size):
"""Clear tables affected by the processing."""
for tablename in tables:
table = ts[tablename]
table[:] = []
if buffer_size is not None and table.is_attached():
table.write(append=False) | python | {
"resource": ""
} |
q8855 | _prepare_source | train | def _prepare_source(selector, source):
"""Normalize source rows and selectors."""
tablename, fields = get_data_specifier(selector)
if len(fields) != 1:
raise ItsdbError(
'Selector must specify exactly one data column: {}'
.format(selector)
)
if isinstance(source, ... | python | {
"resource": ""
} |
q8856 | _add_record | train | def _add_record(table, data, buffer_size):
"""
Prepare and append a Record into its Table; flush to disk if necessary.
"""
fields = table.fields
# remove any keys that aren't relation fields
for invalid_key in set(data).difference([f.name for f in fields]):
del data[invalid_key]
tabl... | python | {
"resource": ""
} |
q8857 | decode_row | train | def decode_row(line, fields=None):
"""
Decode a raw line from a profile into a list of column values.
Decoding involves splitting the line by the field delimiter
(`"@"` by default) and unescaping special characters. If *fields*
is given, cast the values into the datatype given by their
respecti... | python | {
"resource": ""
} |
q8858 | _table_filename | train | def _table_filename(tbl_filename):
"""
Determine if the table path should end in .gz or not and return it.
A .gz path is preferred only if it exists and is newer than any
regular text file path.
Raises:
:class:`delphin.exceptions.ItsdbError`: when neither the .gz
nor text file ... | python | {
"resource": ""
} |
q8859 | _open_table | train | def _open_table(tbl_filename, encoding):
"""
Transparently open the compressed or text table file.
Can be used as a context manager in a 'with' statement.
"""
path = _table_filename(tbl_filename)
if path.endswith('.gz'):
# gzip.open() cannot use mode='rt' until Python2.7 support
... | python | {
"resource": ""
} |
q8860 | select_rows | train | def select_rows(cols, rows, mode='list', cast=True):
"""
Yield data selected from rows.
It is sometimes useful to select a subset of data from a profile.
This function selects the data in *cols* from *rows* and yields it
in a form specified by *mode*. Possible values of *mode* are:
===========... | python | {
"resource": ""
} |
q8861 | join | train | def join(table1, table2, on=None, how='inner', name=None):
"""
Join two tables and return the resulting Table object.
Fields in the resulting table have their names prefixed with their
corresponding table name. For example, when joining `item` and
`parse` tables, the `i-input` field of the `item` t... | python | {
"resource": ""
} |
q8862 | default_value | train | def default_value(fieldname, datatype):
"""
Return the default value for a column.
If the column name (e.g. *i-wf*) is defined to have an idiosyncratic
value, that value is returned. Otherwise the default value for the
column's datatype is returned.
Args:
fieldname: the column name (e.... | python | {
"resource": ""
} |
q8863 | filter_rows | train | def filter_rows(filters, rows):
"""
Yield rows matching all applicable filters.
Filter functions have binary arity (e.g. `filter(row, col)`) where
the first parameter is the dictionary of row data, and the second
parameter is the data at one particular column.
Args:
filters: a tuple of... | python | {
"resource": ""
} |
q8864 | apply_rows | train | def apply_rows(applicators, rows):
"""
Yield rows after applying the applicator functions to them.
Applicators are simple unary functions that return a value, and that
value is stored in the yielded row. E.g.
`row[col] = applicator(row[col])`. These are useful to, e.g., cast
strings to numeric ... | python | {
"resource": ""
} |
q8865 | Field.default_value | train | def default_value(self):
"""Get the default value of the field."""
if self.name in tsdb_coded_attributes:
return tsdb_coded_attributes[self.name]
elif self.datatype == ':integer':
return -1
else:
return '' | python | {
"resource": ""
} |
q8866 | Relation.keys | train | def keys(self):
"""Return the tuple of field names of key fields."""
keys = self._keys
if keys is None:
keys = tuple(self[i].name for i in self.key_indices)
return keys | python | {
"resource": ""
} |
q8867 | Relations.from_file | train | def from_file(cls, source):
"""Instantiate Relations from a relations file."""
if hasattr(source, 'read'):
relations = cls.from_string(source.read())
else:
with open(source) as f:
relations = cls.from_string(f.read())
return relations | python | {
"resource": ""
} |
q8868 | Relations.from_string | train | def from_string(cls, s):
"""Instantiate Relations from a relations string."""
tables = []
seen = set()
current_table = None
lines = list(reversed(s.splitlines())) # to pop() in right order
while lines:
line = lines.pop().strip()
table_m = re.match... | python | {
"resource": ""
} |
q8869 | Relations.path | train | def path(self, source, target):
"""
Find the path of id fields connecting two tables.
This is just a basic breadth-first-search. The relations file
should be small enough to not be a problem.
Returns:
list: (table, fieldname) pairs describing the path from
... | python | {
"resource": ""
} |
q8870 | Record.from_dict | train | def from_dict(cls, fields, mapping):
"""
Create a Record from a dictionary of field mappings.
The *fields* object is used to determine the column indices
of fields in the mapping.
Args:
fields: the Relation schema for the table of this record
mapping: a ... | python | {
"resource": ""
} |
q8871 | Table.from_file | train | def from_file(cls, path, fields=None, encoding='utf-8'):
"""
Instantiate a Table from a database file.
This method instantiates a table attached to the file at *path*.
The file will be opened and traversed to determine the number of
records, but the contents will not be stored i... | python | {
"resource": ""
} |
q8872 | Table.write | train | def write(self, records=None, path=None, fields=None, append=False,
gzip=None):
"""
Write the table to disk.
The basic usage has no arguments and writes the table's data
to the attached file. The parameters accommodate a variety of
use cases, such as using *fields*... | python | {
"resource": ""
} |
q8873 | Table.commit | train | def commit(self):
"""
Commit changes to disk if attached.
This method helps normalize the interface for detached and
attached tables and makes writing attached tables a bit more
efficient. For detached tables nothing is done, as there is no
notion of changes, but neither... | python | {
"resource": ""
} |
q8874 | Table.detach | train | def detach(self):
"""
Detach the table from a file.
Detaching a table reads all data from the file and places it
in memory. This is useful when constructing or significantly
manipulating table data, or when more speed is needed. Tables
created by the default constructor ... | python | {
"resource": ""
} |
q8875 | Table.list_changes | train | def list_changes(self):
"""
Return a list of modified records.
This is only applicable for attached tables.
Returns:
A list of `(row_index, record)` tuples of modified records
Raises:
:class:`delphin.exceptions.ItsdbError`: when called on a
... | python | {
"resource": ""
} |
q8876 | Table._sync_with_file | train | def _sync_with_file(self):
"""Clear in-memory structures so table is synced with the file."""
self._records = []
i = -1
for i, line in self._enum_lines():
self._records.append(None)
self._last_synced_index = i | python | {
"resource": ""
} |
q8877 | Table._enum_lines | train | def _enum_lines(self):
"""Enumerate lines from the attached file."""
with _open_table(self.path, self.encoding) as lines:
for i, line in enumerate(lines):
yield i, line | python | {
"resource": ""
} |
q8878 | Table._enum_attached_rows | train | def _enum_attached_rows(self, indices):
"""Enumerate on-disk and in-memory records."""
records = self._records
i = 0
# first rows covered by the file
for i, line in self._enum_lines():
if i in indices:
row = records[i]
if row is None:
... | python | {
"resource": ""
} |
q8879 | Table._iterslice | train | def _iterslice(self, slice):
"""Yield records from a slice index."""
indices = range(*slice.indices(len(self._records)))
if self.is_attached():
rows = self._enum_attached_rows(indices)
if slice.step is not None and slice.step < 0:
rows = reversed(list(rows... | python | {
"resource": ""
} |
q8880 | Table._getitem | train | def _getitem(self, index):
"""Get a single non-slice index."""
row = self._records[index]
if row is not None:
pass
elif self.is_attached():
# need to handle negative indices manually
if index < 0:
index = len(self._records) + index
... | python | {
"resource": ""
} |
q8881 | Table.select | train | def select(self, cols, mode='list'):
"""
Select columns from each row in the table.
See :func:`select_rows` for a description of how to use the
*mode* parameter.
Args:
cols: an iterable of Field (column) names
mode: how to return the data
"""
... | python | {
"resource": ""
} |
q8882 | ItsdbProfile.exists | train | def exists(self, table=None):
"""
Return True if the profile or a table exist.
If *table* is `None`, this function returns True if the root
directory exists and contains a valid relations file. If *table*
is given, the function returns True if the table exists as a
file ... | python | {
"resource": ""
} |
q8883 | _calculate_crc_ccitt | train | def _calculate_crc_ccitt(data):
"""
All CRC stuff ripped from PyCRC, GPLv3 licensed
"""
global CRC_CCITT_TABLE
if not CRC_CCITT_TABLE:
crc_ccitt_table = []
for i in range(0, 256):
crc = 0
c = i << 8
for j in range(0, 8):
if (crc ^ ... | python | {
"resource": ""
} |
q8884 | GRF.to_zpl | train | def to_zpl(
self, quantity=1, pause_and_cut=0, override_pause=False,
print_mode='C', print_orientation='N', media_tracking='Y', **kwargs
):
"""
The most basic ZPL to print the GRF. Since ZPL printers are stateful
this may not work and you may need to build your own.
"... | python | {
"resource": ""
} |
q8885 | GRF._optimise_barcodes | train | def _optimise_barcodes(
self, data, min_bar_height=20, min_bar_count=100, max_gap_size=30,
min_percent_white=0.2, max_percent_white=0.8, **kwargs
):
"""
min_bar_height = Minimum height of black bars in px. Set this too
low and it might pick up text and ... | python | {
"resource": ""
} |
q8886 | convert_to_underscore | train | def convert_to_underscore(name):
""" "someFunctionWhatever" -> "some_function_whatever" """
s1 = _first_cap_re.sub(r'\1_\2', name)
return _all_cap_re.sub(r'\1_\2', s1).lower() | python | {
"resource": ""
} |
q8887 | User.to_array | train | def to_array(self):
"""
Serializes this User to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(User, self).to_array()
array['id'] = int(self.id) # type int
array['is_bot'] = bool(self.is_bot) # type bool
... | python | {
"resource": ""
} |
q8888 | User.from_array | train | def from_array(array):
"""
Deserialize a new User from a given dictionary.
:return: new User instance.
:rtype: User
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(array, dict, parameter_name="array")
data... | python | {
"resource": ""
} |
q8889 | Chat.to_array | train | def to_array(self):
"""
Serializes this Chat to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(Chat, self).to_array()
array['id'] = int(self.id) # type int
array['type'] = u(self.type) # py2: type unicode... | python | {
"resource": ""
} |
q8890 | Chat.from_array | train | def from_array(array):
"""
Deserialize a new Chat from a given dictionary.
:return: new Chat instance.
:rtype: Chat
"""
if array is None or not array:
return None
# end if
assert_type_or_raise(array, dict, parameter_name="array")
from ... | python | {
"resource": ""
} |
q8891 | ChatMember.to_array | train | def to_array(self):
"""
Serializes this ChatMember to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(ChatMember, self).to_array()
array['user'] = self.user.to_array() # type User
array['status'] = u(self.... | python | {
"resource": ""
} |
q8892 | loads | train | def loads(s, single=False):
"""
Deserialize MRX string representations
Args:
s (str): a MRX string
single (bool): if `True`, only return the first Xmrs object
Returns:
a generator of Xmrs objects (unless *single* is `True`)
"""
corpus = etree.fromstring(s)
if single:... | python | {
"resource": ""
} |
q8893 | InlineQueryResultArticle.to_array | train | def to_array(self):
"""
Serializes this InlineQueryResultArticle to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InlineQueryResultArticle, self).to_array()
# 'type' and 'id' given by superclass
array['tit... | python | {
"resource": ""
} |
q8894 | InlineQueryResultGif.to_array | train | def to_array(self):
"""
Serializes this InlineQueryResultGif to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InlineQueryResultGif, self).to_array()
# 'type' and 'id' given by superclass
array['gif_url'] =... | python | {
"resource": ""
} |
q8895 | InlineQueryResultAudio.to_array | train | def to_array(self):
"""
Serializes this InlineQueryResultAudio to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InlineQueryResultAudio, self).to_array()
# 'type' and 'id' given by superclass
array['audio_u... | python | {
"resource": ""
} |
q8896 | InlineQueryResultLocation.to_array | train | def to_array(self):
"""
Serializes this InlineQueryResultLocation to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InlineQueryResultLocation, self).to_array()
# 'type' and 'id' given by superclass
array['l... | python | {
"resource": ""
} |
q8897 | InlineQueryResultContact.to_array | train | def to_array(self):
"""
Serializes this InlineQueryResultContact to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InlineQueryResultContact, self).to_array()
# 'type' and 'id' given by superclass
array['pho... | python | {
"resource": ""
} |
q8898 | InlineQueryResultCachedGif.to_array | train | def to_array(self):
"""
Serializes this InlineQueryResultCachedGif to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InlineQueryResultCachedGif, self).to_array()
# 'type' and 'id' given by superclass
array[... | python | {
"resource": ""
} |
q8899 | InlineQueryResultCachedDocument.to_array | train | def to_array(self):
"""
Serializes this InlineQueryResultCachedDocument to a dictionary.
:return: dictionary representation of this object.
:rtype: dict
"""
array = super(InlineQueryResultCachedDocument, self).to_array()
# 'type' and 'id' given by superclass
... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.