Fix some miscellaneous stuff

Int division in _sre.py, float precision printf formatting
This commit is contained in:
Noah
2019-10-04 17:08:47 +00:00
committed by coolreader18
parent e89d00f167
commit e304504d22
2 changed files with 11 additions and 12 deletions

12
Lib/_sre.py vendored
View File

@@ -1155,17 +1155,17 @@ class _CharsetDispatcher(_Dispatcher):
block_index = char_code >> 8
# NB: there are CODESIZE block indices per bytecode
a = array.array("B")
a.fromstring(array.array(CODESIZE == 2 and "H" or "I",
[ctx.peek_code(block_index / CODESIZE)]).tostring())
a.frombytes(array.array(CODESIZE == 2 and "H" or "I",
[ctx.peek_code(block_index // CODESIZE)]).tobytes())
block = a[block_index % CODESIZE]
ctx.skip_code(256 / CODESIZE) # skip block indices
block_value = ctx.peek_code(block * (32 / CODESIZE)
ctx.skip_code(256 // CODESIZE) # skip block indices
block_value = ctx.peek_code(block * (32 // CODESIZE)
+ ((char_code & 255) >> (CODESIZE == 2 and 4 or 5)))
if block_value & (1 << (char_code & ((8 * CODESIZE) - 1))):
return self.ok
else:
ctx.skip_code(256 / CODESIZE) # skip block indices
ctx.skip_code(count * (32 / CODESIZE)) # skip blocks
ctx.skip_code(256 // CODESIZE) # skip block indices
ctx.skip_code(count * (32 // CODESIZE)) # skip blocks
def unknown(self, ctx):
return False

View File

@@ -225,14 +225,13 @@ impl CFormatSpec {
"-"
};
// TODO: Support precision
let magnitude_string = match self.format_type {
CFormatType::Float(CFloatType::PointDecimal) => {
if Some(CFormatQuantity::Amount(6)) != self.precision {
return Err("Not yet implemented for %#.#f types".to_string());
} else {
format!("{:.6}", magnitude)
}
let precision = match self.precision {
Some(CFormatQuantity::Amount(p)) => p,
_ => 6,
};
format!("{:.*}", precision, magnitude)
}
CFormatType::Float(CFloatType::Exponent(_)) => {
return Err("Not yet implemented for %e and %E".to_string())