_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q26600
DateTime._first_of_month
train
def _first_of_month(self, day_of_week): """ Modify to the first occurrence of a given day of the week in the current month. If no day_of_week is provided, modify to the first day of the month. Use the supplied consts to indicate the desired day_of_week, ex. DateTime.MONDAY. ...
python
{ "resource": "" }
q26601
DateTime._first_of_quarter
train
def _first_of_quarter(self, day_of_week=None): """ Modify to the first occurrence of a given day of the week in the current quarter. If no day_of_week is provided, modify to the first day of the quarter. Use the supplied consts to indicate the desired day_of_week, ex. DateTime.MO...
python
{ "resource": "" }
q26602
DateTime._last_of_quarter
train
def _last_of_quarter(self, day_of_week=None): """ Modify to the last occurrence of a given day of the week in the current quarter. If no day_of_week is provided, modify to the last day of the quarter. Use the supplied consts to indicate the desired day_of_week, ex. DateTime.MONDA...
python
{ "resource": "" }
q26603
DateTime._nth_of_year
train
def _nth_of_year(self, nth, day_of_week): """ Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside, the scope of the current year, then return False and no modifications are made. Use the supplied consts to...
python
{ "resource": "" }
q26604
Date.closest
train
def closest(self, dt1, dt2): """ Get the closest date from the instance. :type dt1: Date or date :type dt2: Date or date :rtype: Date
python
{ "resource": "" }
q26605
Date.is_birthday
train
def is_birthday(self, dt=None): """ Check if its the birthday. Compares the date/month values of the two dates. :rtype: bool """ if dt is None: dt
python
{ "resource": "" }
q26606
Date.diff
train
def diff(self, dt=None, abs=True): """ Returns the difference between two Date objects as a Period. :type dt: Date or None :param abs: Whether to return an absolute interval or not :type abs: bool :rtype: Period
python
{ "resource": "" }
q26607
Date.diff_for_humans
train
def diff_for_humans(self, other=None, absolute=False, locale=None): """ Get the difference in a human readable format in the current locale. When comparing a value in the past to default now: 1 day ago 5 months ago When comparing a value in the future to default now: ...
python
{ "resource": "" }
q26608
Date._start_of_decade
train
def _start_of_decade(self): """ Reset the date to the first day of the decade.
python
{ "resource": "" }
q26609
Date._end_of_decade
train
def _end_of_decade(self): """ Reset the date to the last day of the decade. :rtype: Date """
python
{ "resource": "" }
q26610
Date._start_of_century
train
def _start_of_century(self): """ Reset the date to the first day of the century.
python
{ "resource": "" }
q26611
Date.next
train
def next(self, day_of_week=None): """ Modify to the next occurrence of a given day of the week. If no day_of_week is provided, modify to the next occurrence of the current day of the week. Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MONDAY. ...
python
{ "resource": "" }
q26612
Date.previous
train
def previous(self, day_of_week=None): """ Modify to the previous occurrence of a given day of the week. If no day_of_week is provided, modify to the previous occurrence of the current day of the week. Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MOND...
python
{ "resource": "" }
q26613
Date._nth_of_month
train
def _nth_of_month(self, nth, day_of_week): """ Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside, the scope of the current month, then return False and no modifications are made. Use the supplied consts ...
python
{ "resource": "" }
q26614
Date._first_of_quarter
train
def _first_of_quarter(self, day_of_week=None): """ Modify to the first occurrence of a given day of the week in the current quarter. If no day_of_week is provided, modify to the first day of the quarter. Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MO...
python
{ "resource": "" }
q26615
Date._last_of_quarter
train
def _last_of_quarter(self, day_of_week=None): """ Modify to the last occurrence of a given day of the week in the current quarter. If no day_of_week is provided, modify to the last day of the quarter. Use the supplied consts to indicate the desired day_of_week, ex. pendulum.MONDA...
python
{ "resource": "" }
q26616
Date._nth_of_quarter
train
def _nth_of_quarter(self, nth, day_of_week): """ Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside, the scope of the current quarter, then return False and no modifications are made. Use the supplied consts ...
python
{ "resource": "" }
q26617
Formatter.format
train
def format(self, dt, fmt, locale=None): """ Formats a DateTime instance with a given format and locale. :param dt: The instance to format :type dt: pendulum.DateTime :param fmt: The format to use :type fmt: str :param locale: The locale to use :type loc...
python
{ "resource": "" }
q26618
Formatter._format_token
train
def _format_token(self, dt, token, locale): """ Formats a DateTime instance with a given token and locale. :param dt: The instance to format :type dt: pendulum.DateTime :param token: The token to use :type token: str :param locale: The locale to use :ty...
python
{ "resource": "" }
q26619
Formatter._format_localizable_token
train
def _format_localizable_token(self, dt, token, locale): """ Formats a DateTime instance with a given localizable token and locale. :param dt: The instance to format :type dt: pendulum.DateTime :param token: The token to use :type token: str :param local...
python
{ "resource": "" }
q26620
Formatter.parse
train
def parse( self, time, # type: str fmt, # type: str now, # type: pendulum.DateTime locale=None, # type: typing.Union[str, None] ): # type: (...) -> dict """ Parses a time string matching a given format as a tuple. :param time: The timestring ...
python
{ "resource": "" }
q26621
local_time
train
def local_time(unix_time, utc_offset, microseconds): """ Returns a UNIX time as a broken down time for a particular transition type. :type unix_time: int :type utc_offset: int :type microseconds: int :rtype: tuple """ year = EPOCH_YEAR seconds = int(math.floor(unix_time)) ...
python
{ "resource": "" }
q26622
_normalize
train
def _normalize(parsed, **options): """ Normalizes the parsed element. :param parsed: The parsed elements. :type parsed: Parsed :rtype: Parsed """ if options.get("exact"): return parsed if isinstance(parsed, time): now = options["now"] or datetime.now() return ...
python
{ "resource": "" }
q26623
_parse_common
train
def _parse_common(text, **options): """ Tries to parse the string as a common datetime format. :param text: The string to parse. :type text: str :rtype: dict or None """ m = COMMON.match(text) has_date = False year = 0 month = 1 day = 1 if not m: raise ParserEr...
python
{ "resource": "" }
q26624
FormattableMixing.format
train
def format(self, fmt, locale=None): """ Formats the instance using the given format. :param fmt: The format to use :type fmt: str :param locale: The locale to use
python
{ "resource": "" }
q26625
Spendable.as_bin
train
def as_bin(self, as_spendable=False): """Return the txo as binary.""" f = io.BytesIO()
python
{ "resource": "" }
q26626
Tx.from_bin
train
def from_bin(class_, blob): """Return the Tx for the given binary blob. :param blob: a binary blob containing a transaction streamed in standard form. The blob may also include the unspents (a nonstandard extension, optionally written by :func:`Tx.stream <stream>`), and they wil...
python
{ "resource": "" }
q26627
Tx.as_bin
train
def as_bin(self, *args, **kwargs): """Returns a binary blob containing the streamed transaction. For information about the parameters, see :func:`Tx.stream <stream>` :return: binary blob that would parse
python
{ "resource": "" }
q26628
Tx.set_unspents
train
def set_unspents(self, unspents): """ Set the unspent inputs for a transaction. :param unspents: a list of :class:`TxOut` (or the subclass :class:`Spendable`) objects corresponding to the :class:`TxIn` objects for this transaction (same number of items
python
{ "resource": "" }
q26629
Tx.sign
train
def sign(self, *args, **kwargs): """ Sign all transaction inputs. The parameters vary depending upon the way the coins being spent are encumbered.
python
{ "resource": "" }
q26630
_from_bytes
train
def _from_bytes(bytes, byteorder="big", signed=False): """This is the same functionality as ``int.from_bytes`` in python 3"""
python
{ "resource": "" }
q26631
MessageSigner.parse_signed_message
train
def parse_signed_message(class_, msg_in): """ Take an "armoured" message and split into the message body, signing address and the base64 signature. Should work on all altcoin networks, and should accept both Inputs.IO and Multibit formats but not Armory. Looks like RFC2550 <http...
python
{ "resource": "" }
q26632
MessageSigner.signature_for_message_hash
train
def signature_for_message_hash(self, secret_exponent, msg_hash, is_compressed): """ Return a signature, encoded in Base64, of msg_hash. """ r, s, recid = self._generator.sign_with_recid(secret_exponent, msg_hash) # See http://bitcoin.stackexchange.com/questions/14263 and key.cpp...
python
{ "resource": "" }
q26633
MessageSigner.sign_message
train
def sign_message(self, key, message, verbose=False): """ Return a signature, encoded in Base64, which can be verified by anyone using the public key. """ secret_exponent = key.secret_exponent() if not secret_exponent: raise ValueError("Private key is required ...
python
{ "resource": "" }
q26634
MessageSigner._decode_signature
train
def _decode_signature(self, signature): """ Decode the internal fields of the base64-encoded signature. """ sig = a2b_base64(signature) if len(sig) != 65: raise EncodingError("Wrong length, expected 65") # split into the parts. first = byte2int(s...
python
{ "resource": "" }
q26635
groestlHash
train
def groestlHash(data): """Groestl-512 compound hash.""" try: import groestlcoin_hash except ImportError: t = 'Groestlcoin
python
{ "resource": "" }
q26636
merkle
train
def merkle(hashes, hash_f=double_sha256): """Take a list of hashes, and return the root merkle hash.""" while len(hashes) > 1:
python
{ "resource": "" }
q26637
merkle_pair
train
def merkle_pair(hashes, hash_f): """Take a list of hashes, and return the parent row in the tree of merkle hashes.""" if len(hashes) % 2 == 1: hashes = list(hashes) hashes.append(hashes[-1]) items = [] for
python
{ "resource": "" }
q26638
BIP32Node.from_master_secret
train
def from_master_secret(class_, master_secret): """Generate a Wallet from a master password.""" I64 = hmac.HMAC(key=b"Bitcoin seed", msg=master_secret,
python
{ "resource": "" }
q26639
BIP32Node.serialize
train
def serialize(self, as_private=None): """ Yield a 74-byte binary blob corresponding to this node. You must add a 4-byte prefix before converting to base58. """ if as_private is None: as_private = self.secret_exponent() is not None if self.secret_exponent() is ...
python
{ "resource": "" }
q26640
BIP32Node.hwif
train
def hwif(self, as_private=False): """Yield a 111-byte string corresponding to this node."""
python
{ "resource": "" }
q26641
BIP32Node.public_copy
train
def public_copy(self): """Yield the corresponding public node for this node.""" d = dict(chain_code=self._chain_code, depth=self._depth,
python
{ "resource": "" }
q26642
BIP32Node.subkey
train
def subkey(self, i=0, is_hardened=False, as_private=None): """ Yield a child node for this node. i: the index for this node. is_hardened: use "hardened key derivation". That is, the public version of this node cannot calculate this child. as_p...
python
{ "resource": "" }
q26643
crack_secret_exponent_from_k
train
def crack_secret_exponent_from_k(generator, signed_value, sig, k): """ Given a signature of a signed_value and a known k, return the secret exponent. """ r,
python
{ "resource": "" }
q26644
crack_k_from_sigs
train
def crack_k_from_sigs(generator, sig1, val1, sig2, val2): """ Given two signatures with the same secret exponent and K value, return that K value. """ # s1 = v1 / k1 + (se * r1) / k1 # s2 = v2 / k2 + (se * r2) / k2 # and k = k1 = k2 # so # k * s1 = v1 + (se * r1) # k * s2 = v2 + (se...
python
{ "resource": "" }
q26645
subpaths_for_path_range
train
def subpaths_for_path_range(path_range, hardening_chars="'pH"): """ Return an iterator of paths # examples: # 0/1H/0-4 => ['0/1H/0', '0/1H/1', '0/1H/2', '0/1H/3', '0/1H/4'] # 0/2,5,9-11 => ['0/2', '0/5', '0/9', '0/10', '0/11'] # 3H/2/5/15-20p => ['3H/2/5/15p', '3H/2/5/16p'...
python
{ "resource": "" }
q26646
double_sha256
train
def double_sha256(data): """A standard compound hash."""
python
{ "resource": "" }
q26647
Optimizations.multiply
train
def multiply(self, p, e): """Multiply a point by an integer.""" e %= self.order() if p == self._infinity or e == 0: return self._infinity pubkey = create_string_buffer(64) public_pair_bytes = b'\4' + to_bytes_32(p[0]) + to_bytes_32(p[1]) r = libsecp256k1.secp2...
python
{ "resource": "" }
q26648
make_const_handler
train
def make_const_handler(data): """ Create a handler for a data opcode that returns a constant. """ data = bytes_as_hex(data) def
python
{ "resource": "" }
q26649
make_sized_handler
train
def make_sized_handler(size, const_values, non_minimal_data_handler): """ Create a handler for a data opcode that returns literal data of a fixed size. """ const_values = list(const_values) def constant_size_opcode_handler(script, pc, verify_minimal_data=False): pc += 1 data = bytes...
python
{ "resource": "" }
q26650
make_variable_handler
train
def make_variable_handler(dec_f, sized_values, min_size, non_minimal_data_handler): """ Create a handler for a data opcode that returns literal data of a variable size that's fetched and decoded by the function dec_f. """ sized_values = list(sized_values)
python
{ "resource": "" }
q26651
make_sized_encoder
train
def make_sized_encoder(opcode_value): """ Create an encoder that encodes the given opcode value as binary data and appends the given data. """
python
{ "resource": "" }
q26652
ascend_bip32
train
def ascend_bip32(bip32_pub_node, secret_exponent, child): """ Given a BIP32Node with public derivation child "child" with a known private key, return the secret exponent for the bip32_pub_node. """ i_as_bytes = struct.pack(">l", child) sec = public_pair_to_sec(bip32_pub_node.public_pair(), compr...
python
{ "resource": "" }
q26653
Key.wif
train
def wif(self, is_compressed=None): """ Return the WIF representation of this key, if available. """ secret_exponent = self.secret_exponent() if secret_exponent is None: return None if is_compressed is None:
python
{ "resource": "" }
q26654
Key.sec
train
def sec(self, is_compressed=None): """ Return the SEC representation of this key, if available. """ if is_compressed is None: is_compressed = self.is_compressed() public_pair = self.public_pair() if
python
{ "resource": "" }
q26655
Key.sec_as_hex
train
def sec_as_hex(self, is_compressed=None): """ Return the SEC representation of this key as hex text. """
python
{ "resource": "" }
q26656
Key.hash160
train
def hash160(self, is_compressed=None): """ Return the hash160 representation of this key, if available. """ if is_compressed is None: is_compressed = self.is_compressed() if is_compressed: if self._hash160_compressed is None: self._hash160_...
python
{ "resource": "" }
q26657
Key.address
train
def address(self, is_compressed=None): """ Return the public address representation of this key, if available. """
python
{ "resource": "" }
q26658
Key.as_text
train
def as_text(self): """ Return a textual representation of this key. """ if self.secret_exponent(): return self.wif()
python
{ "resource": "" }
q26659
Key.sign
train
def sign(self, h): """ Return a der-encoded signature for a hash h. Will throw a RuntimeError if this key is not a private key """ if not self.is_private(): raise RuntimeError("Key must be private to be able to sign")
python
{ "resource": "" }
q26660
Key.verify
train
def verify(self, h, sig): """ Return whether a signature is valid for hash h using this key.
python
{ "resource": "" }
q26661
create_tx
train
def create_tx(network, spendables, payables, fee="standard", lock_time=0, version=1): """ This function provides the easiest way to create an unsigned transaction. All coin values are in satoshis. :param spendables: a list of Spendable objects, which act as inputs. Each item in the list can be...
python
{ "resource": "" }
q26662
Curve.multiply
train
def multiply(self, p, e): """ multiply a point by an integer. :param p: a point :param e: an integer :returns: the result, equivalent to adding p to itself e times """ if self._order: e %= self._order if p == self._infinity or e == 0: ...
python
{ "resource": "" }
q26663
Block.parse
train
def parse(class_, f, include_transactions=True, include_offsets=None, check_merkle_hash=True): """ Parse the Block from the file-like object """ block = class_.parse_as_header(f) if include_transactions: count = parse_struct("I", f)[0]
python
{ "resource": "" }
q26664
Block.check_merkle_hash
train
def check_merkle_hash(self): """Raise a BadMerkleRootError if the Merkle hash of the transactions does not match the Merkle hash included in the block."""
python
{ "resource": "" }
q26665
TxIn.public_key_sec
train
def public_key_sec(self): """Return the public key as sec, or None in case of failure.""" if self.is_coinbase(): return None opcodes = ScriptTools.opcode_list(self.script) if len(opcodes) == 2 and opcodes[0].startswith("[30"):
python
{ "resource": "" }
q26666
Tx.coinbase_tx
train
def coinbase_tx(cls, public_key_sec, coin_value, coinbase_bytes=b'', version=1, lock_time=0): """Create the special "first in block" transaction that includes the mining fees.""" tx_in = cls.TxIn.coinbase_tx_in(script=coinbase_bytes)
python
{ "resource": "" }
q26667
Tx.parse
train
def parse(class_, f, allow_segwit=None): """Parse a Bitcoin transaction Tx. :param f: a file-like object that contains a binary streamed transaction :param allow_segwit: (optional) set to True to allow parsing of segwit transactions. The default value is defined by the class variabl...
python
{ "resource": "" }
q26668
Tx.stream
train
def stream(self, f, blank_solutions=False, include_unspents=False, include_witness_data=True): """Stream a Bitcoin transaction Tx to the file-like object f. :param f: writable file-like object to stream binary data of transaction :param blank_solutions: (optional) clear out the solutions script...
python
{ "resource": "" }
q26669
Tx.validate_unspents
train
def validate_unspents(self, tx_db): """ Spendable objects returned from blockchain.info or similar services contain coin_value information that must be trusted on faith. Mistaken coin_value data can result in coins being wasted to fees. This function solves this problem ...
python
{ "resource": "" }
q26670
locked_blocks_iterator
train
def locked_blocks_iterator(blockfile, start_info=(0, 0), cached_headers=50, batch_size=50): """ This method loads blocks from disk, skipping any orphan blocks. """ f = blockfile current_state = [] def change_state(bc, ops): for op, bh, work in ops: if op == 'add': ...
python
{ "resource": "" }
q26671
post_unpack_merkleblock
train
def post_unpack_merkleblock(d, f): """ A post-processing "post_unpack" to merkleblock messages. It validates the merkle proofs (throwing an exception if there's an error), and returns the list of transaction hashes in "tx_hashes". The transactions are supposed to be sent immediately after the merk...
python
{ "resource": "" }
q26672
_make_parser
train
def _make_parser(streamer, the_struct): "Return a function that parses the given structure into a dict" struct_items = [s.split(":") for s in the_struct.split()] names = [s[0] for s in struct_items] types
python
{ "resource": "" }
q26673
make_post_unpack_alert
train
def make_post_unpack_alert(streamer): """ Post-processor to "alert" message, to add an "alert_info" dictionary of parsed alert information. """ the_struct = ("version:L relayUntil:Q expiration:Q id:L cancel:L setCancel:[L] minVer:L "
python
{ "resource": "" }
q26674
standard_parsing_functions
train
def standard_parsing_functions(Block, Tx): """ Return the standard parsing functions for a given Block and Tx class. The return value is expected to be used with the standard_streamer function. """ def stream_block(f, block): assert isinstance(block, Block) block.stream(f) def s...
python
{ "resource": "" }
q26675
make_parser_and_packer
train
def make_parser_and_packer(streamer, message_dict, message_post_unpacks): """ Create a parser and a packer for a peer's network messages. streamer: used in conjunction with the message_dict. The message_dict turns a message into a string specifying the fields, and this dictionary specifies ...
python
{ "resource": "" }
q26676
ScriptTools.compile
train
def compile(self, s): """ Compile the given script. Returns a bytes object with the compiled script. """ f = io.BytesIO() for t in s.split(): t_up = t.upper() if t_up in self.opcode_to_int: f.write(int2byte(self.opcode_to_int[t])) ...
python
{ "resource": "" }
q26677
ScriptTools.get_opcodes
train
def get_opcodes(self, script, verify_minimal_data=False, pc=0): """ Iterator. Return opcode, data, pc, new_pc at each step """ while pc < len(script): opcode, data, new_pc, is_ok = self.scriptStreamer.get_opcode(
python
{ "resource": "" }
q26678
ScriptTools.opcode_list
train
def opcode_list(self, script): """Disassemble the given script. Returns a list of opcodes.""" opcodes = [] new_pc = 0 try: for opcode, data, pc, new_pc in self.get_opcodes(script):
python
{ "resource": "" }
q26679
Annotate.annotate_scripts
train
def annotate_scripts(self, tx, tx_in_idx): "return list of pre_annotations, pc, opcode, instruction, post_annotations" # input_annotations_f, output_annotations_f = annotation_f_for_scripts(tx, tx_in_idx) data_annotations = collections.defaultdict(list) def traceback_f(opcode, data, pc...
python
{ "resource": "" }
q26680
WhoSigned.solution_blobs
train
def solution_blobs(self, tx, tx_in_idx): """ This iterator yields data blobs that appear in the the last solution_script or the witness. """ sc = tx.SolutionChecker(tx) tx_context = sc.tx_context_for_idx(tx_in_idx) # set solution_stack in case there are no results from pu...
python
{ "resource": "" }
q26681
WhoSigned.extract_secs
train
def extract_secs(self, tx, tx_in_idx): """ For a given script solution, iterate yield its sec blobs """ sc = tx.SolutionChecker(tx) tx_context = sc.tx_context_for_idx(tx_in_idx) # set solution_stack in case there are no results from puzzle_and_solution_iterator so...
python
{ "resource": "" }
q26682
WhoSigned.public_pairs_for_script
train
def public_pairs_for_script(self, tx, tx_in_idx, generator): """ For a given script, iterate over and pull out public pairs encoded as sec values. """ public_pairs = [] for sec in self.extract_secs(tx, tx_in_idx):
python
{ "resource": "" }
q26683
iterate_symbols
train
def iterate_symbols(): """ Return an iterator yielding registered netcodes. """ for prefix in search_prefixes(): package = importlib.import_module(prefix)
python
{ "resource": "" }
q26684
BlockcypherProvider.tx_for_tx_hash
train
def tx_for_tx_hash(self, tx_hash): """ returns the pycoin.tx object for tx_hash """ try: url_append = "?token=%s&includeHex=true" % self.api_key
python
{ "resource": "" }
q26685
BlockcypherProvider.get_balance
train
def get_balance(self, address): """ returns the balance object from blockcypher for address """ url_append = "/balance?token=%s" % self.api_key url = self.base_url("addrs/%s" % (address +
python
{ "resource": "" }
q26686
BlockcypherProvider.broadcast_tx
train
def broadcast_tx(self, tx): """ broadcast a transaction to the network """ url = self.base_url("txs/push") data = {"tx": tx.as_hex()}
python
{ "resource": "" }
q26687
b2a_base58
train
def b2a_base58(s): """Convert binary to base58 using BASE58_ALPHABET. Like Bitcoin addresses."""
python
{ "resource": "" }
q26688
a2b_hashed_base58
train
def a2b_hashed_base58(s): """ If the passed string is hashed_base58, return the binary data. Otherwise raises an EncodingError. """ data = a2b_base58(s) data, the_hash
python
{ "resource": "" }
q26689
BloomFilter.copy
train
def copy(self): """Return a copy of this bloom filter. """ new_filter = BloomFilter(self.capacity, self.error_rate)
python
{ "resource": "" }
q26690
BloomFilter.intersection
train
def intersection(self, other): """ Calculates the intersection of the two underlying bitarrays and returns a new bloom filter object.""" if self.capacity != other.capacity or \ self.error_rate != other.error_rate: raise ValueError("Intersecting filters requires both filte...
python
{ "resource": "" }
q26691
BloomFilter.tofile
train
def tofile(self, f): """Write the bloom filter to file object `f'. Underlying bits are written as machine values. This is much more space efficient than pickling the
python
{ "resource": "" }
q26692
BloomFilter.fromfile
train
def fromfile(cls, f, n=-1): """Read a bloom filter from file-object `f' serialized with ``BloomFilter.tofile''. If `n' > 0 read only so many bytes.""" headerlen = calcsize(cls.FILE_FMT) if 0 < n < headerlen: raise ValueError('n too small!') filter = cls(1) # Bogus ...
python
{ "resource": "" }
q26693
ScalableBloomFilter.tofile
train
def tofile(self, f): """Serialize this ScalableBloomFilter into the file-object `f'.""" f.write(pack(self.FILE_FMT, self.scale, self.ratio, self.initial_capacity, self.error_rate)) # Write #-of-filters f.write(pack(b'<l', len(self.filters))) if len(...
python
{ "resource": "" }
q26694
ScalableBloomFilter.fromfile
train
def fromfile(cls, f): """Deserialize the ScalableBloomFilter in file object `f'.""" filter = cls() filter._setup(*unpack(cls.FILE_FMT, f.read(calcsize(cls.FILE_FMT)))) nfilters, = unpack(b'<l', f.read(calcsize(b'<l'))) if nfilters > 0: header_fmt = b'<' + b'Q'*nfilter...
python
{ "resource": "" }
q26695
safe_get_user_model
train
def safe_get_user_model(): """ Safe loading of the User model, customized or not. """
python
{ "resource": "" }
q26696
EntryAdmin.get_title
train
def get_title(self, entry): """ Return the title with word count and number of comments. """ title = _('%(title)s (%(word_count)i words)') % \ {'title': entry.title, 'word_count': entry.word_count} reaction_count = int(entry.comment_count + ...
python
{ "resource": "" }
q26697
EntryAdmin.get_authors
train
def get_authors(self, entry): """ Return the authors in HTML. """ try: return format_html_join( ', ', '<a href="{}" target="blank">{}</a>', [(author.get_absolute_url(), getattr(author, author.USERNAME_FIELD))
python
{ "resource": "" }
q26698
EntryAdmin.get_categories
train
def get_categories(self, entry): """ Return the categories linked in HTML. """ try: return format_html_join( ', ', '<a href="{}" target="blank">{}</a>', [(category.get_absolute_url(), category.title) for
python
{ "resource": "" }
q26699
EntryAdmin.get_tags
train
def get_tags(self, entry): """ Return the tags linked in HTML. """ try: return format_html_join( ', ',
python
{ "resource": "" }