desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Look up a phone number.
:param str number: The phone number to query.
:param bool include_carrier_info: Whether to do a carrier lookup on
the phone number. See twilio.com for the latest pricing.
:param str country_code: If the number is provided in a local format
rather than E.164, specify the two-letter code of the c... | def get(self, number, include_carrier_info=False, country_code=None):
| params = {}
if (country_code is not None):
params['country_code'] = country_code
if include_carrier_info:
params['type'] = 'carrier'
params = transform_params(params)
uri = ('%s/%s' % (self.uri, number))
(_, item) = self.request('GET', uri, params=params)
return self.load_ins... |
'Update your Twilio Sandbox'
| def update(self, **kwargs):
| a = self.parent.update(**kwargs)
self.load(a.__dict__)
|
'Request the specified instance resource'
| def get(self):
| return self.get_instance(self.uri)
|
'Update your Twilio Sandbox'
| def update(self, **kwargs):
| (resp, entry) = self.request('POST', self.uri, body=transform_params(kwargs))
return self.create_instance(entry)
|
'Create a Twilio REST API client.'
| def __init__(self, account=None, token=None, base='https://taskrouter.twilio.com', version='v1', timeout=UNSET_TIMEOUT, request_account=None):
| super(TwilioTaskRouterClient, self).__init__(account, token, base, version, timeout, request_account)
self.base_uri = '{0}/{1}'.format(base, version)
self.workspace_uri = '{0}/Workspaces'.format(self.base_uri)
self.workspaces = Workspaces(self.base_uri, self.auth, timeout)
|
'Return a :class:`Activities` instance for the :class:`Activity`
with the given workspace_sid'
| def activities(self, workspace_sid):
| base_uri = '{0}/{1}'.format(self.workspace_uri, workspace_sid)
return Activities(base_uri, self.auth, self.timeout)
|
'Return a :class:`Events` instance for the :class:`Event` with the given
workspace_sid'
| def events(self, workspace_sid):
| base_uri = '{0}/{1}'.format(self.workspace_uri, workspace_sid)
return Events(base_uri, self.auth, self.timeout)
|
'Return a :class:`Reservations` instance for the :class:`Reservation`
with the given workspace_sid ans task_sid'
| def reservations(self, workspace_sid, task_sid):
| base_uri = '{0}/{1}/Tasks/{2}'.format(self.workspace_uri, workspace_sid, task_sid)
return Reservations(base_uri, self.auth, self.timeout)
|
'Return a :class:`Reservations` instance for the :class:`Reservation`
with the given workspace_sid ans worker_sid'
| def worker_reservations(self, workspace_sid, worker_sid):
| base_uri = '{0}/{1}/Workers/{2}'.format(self.workspace_uri, workspace_sid, worker_sid)
return Reservations(base_uri, self.auth, self.timeout)
|
'Return a :class:`TaskQueues` instance for the :class:`TaskQueue` with
the given workspace_sid'
| def task_queues(self, workspace_sid):
| base_uri = '{0}/{1}'.format(self.workspace_uri, workspace_sid)
return TaskQueues(base_uri, self.auth, self.timeout)
|
'Return a :class:`Tasks` instance for the :class:`Task` with the given
workspace_sid'
| def tasks(self, workspace_sid):
| base_uri = '{0}/{1}'.format(self.workspace_uri, workspace_sid)
return Tasks(base_uri, self.auth, self.timeout)
|
'Return a :class:`Workers` instance for the :class:`Worker` with the
given workspace_sid'
| def workers(self, workspace_sid):
| base_uri = '{0}/{1}'.format(self.workspace_uri, workspace_sid)
return Workers(base_uri, self.auth, self.timeout)
|
'Return a :class:`Workflows` instance for the :class:`Workflow` with the
given workspace_sid'
| def workflows(self, workspace_sid):
| base_uri = '{0}/{1}'.format(self.workspace_uri, workspace_sid)
return Workflows(base_uri, self.auth, self.timeout)
|
'Return the contents of this verb as an XML string
:param bool xml_declaration: Include the XML declaration. Defaults to
True'
| def toxml(self, xml_declaration=True):
| xml = ET.tostring(self.xml()).decode('utf-8')
if xml_declaration:
return ('<?xml version="1.0" encoding="UTF-8"?>' + xml)
else:
return xml
|
'Version: Twilio API version e.g. 2008-08-01'
| def __init__(self, **kwargs):
| super(Response, self).__init__(**kwargs)
|
'Return a newly created :class:`Say` verb, nested inside this
:class:`Response`'
| def say(self, text, **kwargs):
| return self.append(Say(text, **kwargs))
|
'Return a newly created :class:`Play` verb, nested inside this
:class:`Response`'
| def play(self, url=None, digits=None, **kwargs):
| return self.append(Play(url=url, digits=digits, **kwargs))
|
'Return a newly created :class:`Pause` verb, nested inside this
:class:`Response`'
| def pause(self, **kwargs):
| return self.append(Pause(**kwargs))
|
'Return a newly created :class:`Redirect` verb, nested inside this
:class:`Response`'
| def redirect(self, url=None, **kwargs):
| return self.append(Redirect(url, **kwargs))
|
'Return a newly created :class:`Hangup` verb, nested inside this
:class:`Response`'
| def hangup(self, **kwargs):
| return self.append(Hangup(**kwargs))
|
'Return a newly created :class:`Hangup` verb, nested inside this
:class:`Response`'
| def reject(self, reason=None, **kwargs):
| return self.append(Reject(reason=reason, **kwargs))
|
'Return a newly created :class:`Gather` verb, nested inside this
:class:`Response`'
| def gather(self, **kwargs):
| return self.append(Gather(**kwargs))
|
'Return a newly created :class:`Dial` verb, nested inside this
:class:`Response`'
| def dial(self, number=None, **kwargs):
| return self.append(Dial(number, **kwargs))
|
'Return a newly created :class:`Enqueue` verb, nested inside this
:class:`Response`'
| def enqueue(self, name, **kwargs):
| return self.append(Enqueue(name, **kwargs))
|
'Return a newly created :class:`Leave` verb, nested inside this
:class:`Response`'
| def leave(self, **kwargs):
| return self.append(Leave(**kwargs))
|
'Return a newly created :class:`Record` verb, nested inside this
:class:`Response`'
| def record(self, **kwargs):
| return self.append(Record(**kwargs))
|
'Return a newly created :class:`Sms` verb, nested inside this
:class:`Response`'
| def sms(self, msg, **kwargs):
| return self.append(Sms(msg, **kwargs))
|
'Return a newly created :class:`Message` verb, nested inside this
:class:`Response`'
| def message(self, msg=None, **kwargs):
| return self.append(Message(msg, **kwargs))
|
'A deluge client session.'
| def __init__(self):
| self.transfer = DelugeTransfer()
self.modules = []
self._request_counter = 0
|
'Connects to a daemon process.
:param host: str, the hostname of the daemon
:param port: int, the port of the daemon
:param username: str, the username to login with
:param password: str, the password to login with'
| def connect(self, host='127.0.0.1', port=58846, username='', password=''):
| self.transfer.connect((host, port))
if ((not username) and (host in ('127.0.0.1', 'localhost'))):
(username, password) = self._get_local_auth()
self.remote_call('daemon.login', username, password).get()
self._introspect()
|
'Disconnects from the daemon.'
| def disconnect(self):
| self.transfer.disconnect()
|
'Returns True if entry is a directory.'
| def isdir(self):
| if (self.type == RAR_BLOCK_FILE):
return ((self.flags & RAR_FILE_DIRECTORY) == RAR_FILE_DIRECTORY)
return False
|
'Returns True if data is stored password-protected.'
| def needs_password(self):
| if (self.type == RAR_BLOCK_FILE):
return ((self.flags & RAR_FILE_PASSWORD) > 0)
return False
|
'Open and parse a RAR archive.
Parameters:
rarfile
archive file name
mode
only \'r\' is supported.
charset
fallback charset to use, if filenames are not already Unicode-enabled.
info_callback
debug callback, gets to see all archive entries.
crc_check
set to False to disable CRC checks
errors
Either "stop" to quietly st... | def __init__(self, rarfile, mode='r', charset=None, info_callback=None, crc_check=True, errors='stop'):
| self._rarfile = rarfile
self._charset = (charset or DEFAULT_CHARSET)
self._info_callback = info_callback
self._crc_check = crc_check
self._password = None
self._file_parser = None
if (errors == 'stop'):
self._strict = False
elif (errors == 'strict'):
self._strict = True
... |
'Open context.'
| def __enter__(self):
| return self
|
'Exit context'
| def __exit__(self, typ, value, traceback):
| self.close()
|
'Sets the password to use when extracting.'
| def setpassword(self, password):
| self._password = password
if self._file_parser:
if self._file_parser.has_header_encryption():
self._file_parser = None
if (not self._file_parser):
self._parse()
else:
self._file_parser.setpassword(self._password)
|
'Returns True if any archive entries require password for extraction.'
| def needs_password(self):
| return self._file_parser.needs_password()
|
'Return list of filenames in archive.'
| def namelist(self):
| return [f.filename for f in self.infolist()]
|
'Return RarInfo objects for all files/directories in archive.'
| def infolist(self):
| return self._file_parser.infolist()
|
'Returns filenames of archive volumes.
In case of single-volume archive, the list contains
just the name of main archive file.'
| def volumelist(self):
| return self._file_parser.volumelist()
|
'Return RarInfo for file.'
| def getinfo(self, fname):
| return self._file_parser.getinfo(fname)
|
'Returns file-like object (:class:`RarExtFile`) from where the data can be read.
The object implements :class:`io.RawIOBase` interface, so it can
be further wrapped with :class:`io.BufferedReader`
and :class:`io.TextIOWrapper`.
On older Python where io module is not available, it implements
only .read(), .seek(), .tell... | def open(self, fname, mode='r', psw=None):
| if (mode != 'r'):
raise NotImplementedError('RarFile.open() supports only mode=r')
inf = self.getinfo(fname)
if inf.isdir():
raise TypeError(('Directory does not have any data: ' + inf.filename))
if inf.needs_password():
psw = (psw or self._password)
... |
'Return uncompressed data for archive entry.
For longer files using :meth:`RarFile.open` may be better idea.
Parameters:
fname
filename or RarInfo instance
psw
password to use for extracting.'
| def read(self, fname, psw=None):
| with self.open(fname, 'r', psw) as f:
return f.read()
|
'Release open resources.'
| def close(self):
| pass
|
'Print archive file list to stdout.'
| def printdir(self):
| for f in self.infolist():
print(f.filename)
|
'Extract single file into current directory.
Parameters:
member
filename or :class:`RarInfo` instance
path
optional destination path
pwd
optional password to use'
| def extract(self, member, path=None, pwd=None):
| if isinstance(member, RarInfo):
fname = member.filename
else:
fname = member
self._extract([fname], path, pwd)
|
'Extract all files into current directory.
Parameters:
path
optional destination path
members
optional filename or :class:`RarInfo` instance list to extract
pwd
optional password to use'
| def extractall(self, path=None, members=None, pwd=None):
| fnlist = []
if (members is not None):
for m in members:
if isinstance(m, RarInfo):
fnlist.append(m.filename)
else:
fnlist.append(m)
self._extract(fnlist, path, pwd)
|
'Let \'unrar\' test the archive.'
| def testrar(self):
| cmd = ([UNRAR_TOOL] + list(TEST_ARGS))
add_password_arg(cmd, self._password)
cmd.append('--')
with XTempFile(self._rarfile) as rarfile:
cmd.append(rarfile)
p = custom_popen(cmd)
output = p.communicate()[0]
check_returncode(p, output)
|
'Return error string if parsing failed or None if no problems.'
| def strerror(self):
| if (not self._file_parser):
return 'Not a RAR file'
return self._file_parser.strerror()
|
'Returns True if headers are encrypted'
| def has_header_encryption(self):
| if self._hdrenc_main:
return True
if self._main:
if (self._main.flags & RAR_MAIN_PASSWORD):
return True
return False
|
'Set cached password.'
| def setpassword(self, psw):
| self._password = psw
|
'Volume files'
| def volumelist(self):
| return self._vol_list
|
'Is password required'
| def needs_password(self):
| return self._needs_password
|
'Last error'
| def strerror(self):
| return self._parse_error
|
'List of RarInfo records.'
| def infolist(self):
| return self._info_list
|
'Return RarInfo for filename'
| def getinfo(self, member):
| if isinstance(member, RarInfo):
fname = member.filename
else:
fname = member
if (PATH_SEP == '/'):
fname2 = fname.replace('\\', '/')
else:
fname2 = fname.replace('/', '\\')
try:
return self._info_map[fname]
except KeyError:
try:
return ... |
'Process file.'
| def parse(self):
| self._fd = None
try:
self._parse_real()
finally:
if self._fd:
self._fd.close()
self._fd = None
|
'Examine item, add into lookup cache.'
| def process_entry(self, fd, item):
| raise NotImplementedError()
|
'Return stream object for file data.'
| def open(self, inf, psw):
| if inf.file_redir:
if (inf.file_redir[0] in (RAR5_XREDIR_FILE_COPY, RAR5_XREDIR_HARD_LINK)):
inf = self.getinfo(inf.file_redir[2])
if (not inf):
raise BadRarFile('cannot find copied file')
if (inf.flags & RAR_FILE_SPLIT_BEFORE):
raise NeedFirstVol... |
'Copy encoded byte.'
| def enc_byte(self):
| try:
c = self.encdata[self.encpos]
self.encpos += 1
return c
except IndexError:
self.failed = 1
return 0
|
'Copy byte from 8-bit representation.'
| def std_byte(self):
| try:
return self.std_name[self.pos]
except IndexError:
self.failed = 1
return ord('?')
|
'Copy 16-bit value to result.'
| def put(self, lo, hi):
| self.buf.append(lo)
self.buf.append(hi)
self.pos += 1
|
'Decompress compressed UTF16 value.'
| def decode(self):
| hi = self.enc_byte()
flagbits = 0
while (self.encpos < len(self.encdata)):
if (flagbits == 0):
flags = self.enc_byte()
flagbits = 8
flagbits -= 2
t = ((flags >> flagbits) & 3)
if (t == 0):
self.put(self.enc_byte(), 0)
elif (t == 1):... |
'Open archive entry.'
| def __init__(self, parser, inf):
| super(RarExtFile, self).__init__()
self.name = inf.filename
self.mode = 'rb'
self._parser = parser
self._inf = inf
self._fd = None
self._remain = 0
self._returncode = 0
self._md_context = None
self._open()
|
'Read all or specified amount of data from archive entry.'
| def read(self, cnt=None):
| if ((cnt is None) or (cnt < 0)):
cnt = self._remain
elif (cnt > self._remain):
cnt = self._remain
if (cnt == 0):
return EMPTY
data = self._read(cnt)
if data:
self._md_context.update(data)
self._remain -= len(data)
if (len(data) != cnt):
raise BadRa... |
'Check final CRC.'
| def _check(self):
| final = self._md_context.digest()
exp = self._inf._md_expect
if (exp is None):
return
if (final is None):
return
if self._returncode:
check_returncode(self, '')
if (self._remain != 0):
raise BadRarFile('Failed the read enough data')
if (final != ex... |
'Close open resources.'
| def close(self):
| super(RarExtFile, self).close()
if self._fd:
self._fd.close()
self._fd = None
|
'Hook delete to make sure tempfile is removed.'
| def __del__(self):
| self.close()
|
'Zero-copy read directly into buffer.
Returns bytes read.'
| def readinto(self, buf):
| raise NotImplementedError('readinto')
|
'Return current reading position in uncompressed data.'
| def tell(self):
| return (self._inf.file_size - self._remain)
|
'Seek in data.
On uncompressed files, the seeking works by actual
seeks so it\'s fast. On compresses files its slow
- forward seeking happends by reading ahead,
backwards by re-opening and decompressing from the start.'
| def seek(self, ofs, whence=0):
| self._md_context = NoHashContext()
fsize = self._inf.file_size
cur_ofs = self.tell()
if (whence == 0):
new_ofs = ofs
elif (whence == 1):
new_ofs = (cur_ofs + ofs)
elif (whence == 2):
new_ofs = (fsize + ofs)
else:
raise ValueError('Invalid value for wh... |
'Read and discard data'
| def _skip(self, cnt):
| while (cnt > 0):
if (cnt > 8192):
buf = self.read(8192)
else:
buf = self.read(cnt)
if (not buf):
break
cnt -= len(buf)
|
'Returns True'
| def readable(self):
| return True
|
'Returns False.
Writing is not supported.'
| def writable(self):
| return False
|
'Returns True.
Seeking is supported, although it\'s slow on compressed files.'
| def seekable(self):
| return True
|
'Read all remaining data'
| def readall(self):
| return self.read()
|
'Read from pipe.'
| def _read(self, cnt):
| data = self._fd.read(cnt)
if ((len(data) == cnt) or (not data)):
return data
buf = [data]
cnt -= len(data)
while (cnt > 0):
data = self._fd.read(cnt)
if (not data):
break
cnt -= len(data)
buf.append(data)
return EMPTY.join(buf)
|
'Close open resources.'
| def close(self):
| self._close_proc()
super(PipeReader, self).close()
if self._tempfile:
try:
os.unlink(self._tempfile)
except OSError:
pass
self._tempfile = None
|
'Zero-copy read directly into buffer.'
| def readinto(self, buf):
| cnt = len(buf)
if (cnt > self._remain):
cnt = self._remain
vbuf = memoryview(buf)
res = got = 0
while (got < cnt):
res = self._fd.readinto(vbuf[got:cnt])
if (not res):
break
self._md_context.update(vbuf[got:(got + res)])
self._remain -= res
... |
'RAR Seek, skipping through rar files to get to correct position'
| def _skip(self, cnt):
| while (cnt > 0):
if (self._cur_avail == 0):
if (not self._open_next()):
break
if (cnt > self._cur_avail):
cnt -= self._cur_avail
self._remain -= self._cur_avail
self._cur_avail = 0
else:
self._fd.seek(cnt, 1)
... |
'Read from potentially multi-volume archive.'
| def _read(self, cnt):
| buf = []
while (cnt > 0):
if (self._cur_avail == 0):
if (not self._open_next()):
break
if (cnt > self._cur_avail):
data = self._fd.read(self._cur_avail)
else:
data = self._fd.read(cnt)
if (not data):
break
cn... |
'Proceed to next volume.'
| def _open_next(self):
| if ((self._cur.flags & RAR_FILE_SPLIT_AFTER) == 0):
return False
if self._fd:
self._fd.close()
self._fd = None
self._volfile = self._parser._next_volname(self._volfile)
fd = open(self._volfile, 'rb', 0)
self._fd = fd
sig = fd.read(len(self._parser._expect_sig))
if (si... |
'Zero-copy read directly into buffer.'
| def readinto(self, buf):
| got = 0
vbuf = memoryview(buf)
while (got < len(buf)):
if (self._cur_avail == 0):
if (not self._open_next()):
break
cnt = (len(buf) - got)
if (cnt > self._cur_avail):
cnt = self._cur_avail
res = self._fd.readinto(vbuf[got:(got + cnt)])
... |
'Current file pos - works only on block boundaries.'
| def tell(self):
| return self.f.tell()
|
'Read and decrypt.'
| def read(self, cnt=None):
| if (cnt > (8 * 1024)):
raise BadRarFile('Bad count to header decrypt - wrong password?')
if (cnt <= len(self.buf)):
res = self.buf[:cnt]
self.buf = self.buf[cnt:]
return res
res = self.buf
self.buf = EMPTY
cnt -= len(res)
blklen = 16
while... |
'Read from file.'
| def read(self, n=None):
| return self._fd.read(n)
|
'Return file pos.'
| def tell(self):
| return self._fd.tell()
|
'Move file pos.'
| def seek(self, ofs, whence=0):
| return self._fd.seek(ofs, whence)
|
'Read into buffer.'
| def readinto(self, dst):
| return self._fd.readinto(dst)
|
'Close file object.'
| def close(self):
| if self._need_close:
self._fd.close()
|
'Process data.'
| def update(self, data):
| self._crc = rar_crc32(data, self._crc)
|
'Final hash.'
| def digest(self):
| return self._crc
|
'Hexadecimal digest.'
| def hexdigest(self):
| return ('%08x' % self.digest())
|
'Hash data.'
| def update(self, data):
| view = memoryview(data)
bs = self.block_size
if self._buf:
need = (bs - len(self._buf))
if (len(view) < need):
self._buf += view.tobytes()
return
self._add_block((self._buf + view[:need].tobytes()))
view = view[need:]
while (len(view) >= bs):
... |
'Return final digest value.'
| def digest(self):
| if (self._digest is None):
if self._buf:
self._add_block(self._buf)
self._buf = EMPTY
ctx = self._blake2s(0, 1, True)
for t in self._thread:
ctx.update(t.digest())
self._digest = ctx.digest()
return self._digest
|
'Hexadecimal digest.'
| def hexdigest(self):
| return tohex(self.digest())
|
'Returns true if argument is a ASN1 subtype of ourselves'
| def isSuperTypeOf(self, other):
| return (self._tagSet.isSuperTagSetOf(other.getTagSet()) and self._subtypeSpec.isSuperTypeOf(other.getSubtypeSpec()))
|
'Returns true if argument OID resides deeper in the OID tree'
| def isPrefixOf(self, value):
| l = len(self)
if (l <= len(value)):
if (self._value[:l] == value[:l]):
return 1
return 0
|
'Dotted -> tuple of numerics OID converter'
| def prettyIn(self, value):
| if isinstance(value, tuple):
pass
elif isinstance(value, ObjectIdentifier):
return tuple(value)
elif isinstance(value, str):
r = []
for element in [x for x in value.split('.') if (x != '')]:
try:
r.append(int(element, 0))
except ValueEr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.