text stringlengths 0 828 |
|---|
encoding = self.domain_encoding_table[domain] |
html = binary.decode(encoding, errors=errors) |
else: |
html, encoding, confidence = smart_decode( |
binary, errors=errors) |
# cache domain name and encoding |
self.domain_encoding_table[domain] = encoding |
else: |
html = binary.decode(encoding, errors=errors) |
return html" |
1893,"def modify_number_pattern(number_pattern, **kwargs): |
""""""Modifies a number pattern by specified keyword arguments."""""" |
params = ['pattern', 'prefix', 'suffix', 'grouping', |
'int_prec', 'frac_prec', 'exp_prec', 'exp_plus'] |
for param in params: |
if param in kwargs: |
continue |
kwargs[param] = getattr(number_pattern, param) |
return NumberPattern(**kwargs)" |
1894,"def format_currency_field(__, prec, number, locale): |
""""""Formats a currency field."""""" |
locale = Locale.parse(locale) |
currency = get_territory_currencies(locale.territory)[0] |
if prec is None: |
pattern, currency_digits = None, True |
else: |
prec = int(prec) |
pattern = locale.currency_formats['standard'] |
pattern = modify_number_pattern(pattern, frac_prec=(prec, prec)) |
currency_digits = False |
return format_currency(number, currency, pattern, locale=locale, |
currency_digits=currency_digits)" |
1895,"def format_decimal_field(__, prec, number, locale): |
""""""Formats a decimal field: |
.. sourcecode:: |
1234 ('D') -> 1234 |
-1234 ('D6') -> -001234 |
"""""" |
prec = 0 if prec is None else int(prec) |
if number < 0: |
prec += 1 |
return format(number, u'0%dd' % prec)" |
1896,"def format_float_field(__, prec, number, locale): |
""""""Formats a fixed-point field."""""" |
format_ = u'0.' |
if prec is None: |
format_ += u'#' * NUMBER_DECIMAL_DIGITS |
else: |
format_ += u'0' * int(prec) |
pattern = parse_pattern(format_) |
return pattern.apply(number, locale)" |
1897,"def format_number_field(__, prec, number, locale): |
""""""Formats a number field."""""" |
prec = NUMBER_DECIMAL_DIGITS if prec is None else int(prec) |
locale = Locale.parse(locale) |
pattern = locale.decimal_formats.get(None) |
return pattern.apply(number, locale, force_frac=(prec, prec))" |
1898,"def format_percent_field(__, prec, number, locale): |
""""""Formats a percent field."""""" |
prec = PERCENT_DECIMAL_DIGITS if prec is None else int(prec) |
locale = Locale.parse(locale) |
pattern = locale.percent_formats.get(None) |
return pattern.apply(number, locale, force_frac=(prec, prec))" |
1899,"def format_hexadecimal_field(spec, prec, number, locale): |
""""""Formats a hexadeciaml field."""""" |
if number < 0: |
# Take two's complement. |
number &= (1 << (8 * int(math.log(-number, 1 << 8) + 1))) - 1 |
format_ = u'0%d%s' % (int(prec or 0), spec) |
return format(number, format_)" |
1900,"def format_field(self, value, format_spec): |
""""""Format specifiers are described in :func:`format_field` which is a |
static function. |
"""""" |
if format_spec: |
spec, arg = format_spec[0], format_spec[1:] |
arg = arg or None |
else: |
spec = arg = None |
return self._format_field(spec, arg, value, self.numeric_locale)" |
1901,"def delegate(attribute_name, method_names): |
"""""" |
Decorator factory to delegate methods to an attribute. |
Decorate a class to map every method in `method_names` to the attribute `attribute_name`. |
"""""" |
call_attribute_method = partial(_call_delegated_method, attribute_name) |
def decorate(class_): |
for method in method_names: |
setattr(class_, method, partialmethod(call_attribute_method, method)) |
return class_ |
return decorate" |
1902,"def prepare_query(query): |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.