Merge pull request #5808 from ShaharNaveh/cln-general

This commit is contained in:
Jeong, YunWon authored and GitHub committed 2025-06-21 13:25:33 +09:00
commit f0e742714a
5 files changed
+38 -28

No files matched your search

+11 -7
View File
@@ -214,7 +214,7 @@ pub struct ByteInnerTranslateOptions {
impl ByteInnerTranslateOptions {
pub fn get_value(self, vm: &VirtualMachine) -> PyResult<(Vec<u8>, Vec<u8>)> {
let table = self.table.map_or_else(
|| Ok((0..=255).collect::<Vec<u8>>()),
|| Ok((0..=u8::MAX).collect::<Vec<u8>>()),
|v| {
let bytes = v
.try_into_value::<PyBytesInner>(vm)
@@ -424,8 +424,8 @@ impl PyBytesInner {
let mut new: Vec<u8> = Vec::with_capacity(self.elements.len());
for w in &self.elements {
match w {
65..=90 => new.push(w.to_ascii_lowercase()),
97..=122 => new.push(w.to_ascii_uppercase()),
b'A'..=b'Z' => new.push(w.to_ascii_lowercase()),
b'a'..=b'z' => new.push(w.to_ascii_uppercase()),
x => new.push(*x),
}
}
@@ -491,10 +491,11 @@ impl PyBytesInner {
vm: &VirtualMachine,
) -> PyResult<Vec<u8>> {
let (width, fillchar) = options.get_value("center", vm)?;
Ok(if self.len() as isize >= width {
let len = self.len();
Ok(if len as isize >= width {
Vec::from(&self.elements[..])
} else {
pad(&self.elements, width as usize, fillchar, self.len())
pad(&self.elements, width as usize, fillchar, len)
})
}
@@ -564,7 +565,7 @@ impl PyBytesInner {
}
let mut res = vec![];
for i in 0..=255 {
for i in 0..=u8::MAX {
res.push(if let Some(position) = from.elements.find_byte(i) {
to.elements[position]
} else {
@@ -929,7 +930,7 @@ impl PyBytesInner {
for i in &self.elements {
match i {
65..=90 | 97..=122 => {
b'A'..=b'Z' | b'a'..=b'z' => {
if spaced {
res.push(i.to_ascii_uppercase());
spaced = false
@@ -1011,6 +1012,7 @@ impl AnyStrWrapper<[u8]> for PyBytesInner {
fn as_ref(&self) -> Option<&[u8]> {
Some(&self.elements)
}
fn is_empty(&self) -> bool {
self.elements.is_empty()
}
@@ -1036,9 +1038,11 @@ impl anystr::AnyChar for u8 {
fn is_lowercase(self) -> bool {
self.is_ascii_lowercase()
}
fn is_uppercase(self) -> bool {
self.is_ascii_uppercase()
}
fn bytes_len(self) -> usize {
1
}
+1
View File
@@ -146,6 +146,7 @@ impl GenIndexes {
mask,
}
}
fn next(&mut self) -> usize {
let prev = self.idx;
self.idx = prev
+21 -21
View File
@@ -237,9 +237,10 @@ impl VirtualMachine {
let colno = offset - 1 - spaces;
let end_colno = end_offset - 1 - spaces;
if colno >= 0 {
let caret_space = l_text.chars().collect::<Vec<_>>()[..colno as usize]
.iter()
.map(|c| if c.is_whitespace() { *c } else { ' ' })
let caret_space = l_text
.chars()
.take(colno as usize)
.map(|c| if c.is_whitespace() { c } else { ' ' })
.collect::<String>();
let mut error_width = end_colno - colno;
@@ -1619,24 +1620,23 @@ pub(super) mod types {
.clone()
.downcast::<crate::builtins::PyTuple>()
{
#[allow(clippy::len_zero)]
if location_tuple.len() >= 1 {
zelf.set_attr("filename", location_tuple.fast_getitem(0).clone(), vm)?;
}
if location_tuple.len() >= 2 {
zelf.set_attr("lineno", location_tuple.fast_getitem(1).clone(), vm)?;
}
if location_tuple.len() >= 3 {
zelf.set_attr("offset", location_tuple.fast_getitem(2).clone(), vm)?;
}
if location_tuple.len() >= 4 {
zelf.set_attr("text", location_tuple.fast_getitem(3).clone(), vm)?;
}
if location_tuple.len() >= 5 {
zelf.set_attr("end_lineno", location_tuple.fast_getitem(4).clone(), vm)?;
}
if location_tuple.len() >= 6 {
zelf.set_attr("end_offset", location_tuple.fast_getitem(5).clone(), vm)?;
let location_tup_len = location_tuple.len();
for (i, &attr) in [
"filename",
"lineno",
"offset",
"text",
"end_lineno",
"end_offset",
]
.iter()
.enumerate()
{
if location_tup_len > i {
zelf.set_attr(attr, location_tuple.fast_getitem(i).clone(), vm)?;
} else {
break;
}
}
}
}
+4
View File
@@ -138,15 +138,19 @@ impl<H: Helper> Readline<H> {
pub fn new(helper: H) -> Self {
Readline(readline_inner::Readline::new(helper))
}
pub fn load_history(&mut self, path: &Path) -> OtherResult<()> {
self.0.load_history(path)
}
pub fn save_history(&mut self, path: &Path) -> OtherResult<()> {
self.0.save_history(path)
}
pub fn add_history_entry(&mut self, entry: &str) -> OtherResult<()> {
self.0.add_history_entry(entry)
}
pub fn readline(&mut self, prompt: &str) -> ReadlineResult {
self.0.readline(prompt)
}
+1
View File
@@ -331,6 +331,7 @@ impl SequenceIndexOp for BigInt {
self.try_into().unwrap_or(len)
}
}
fn wrapped_at(&self, _len: usize) -> Option<usize> {
unimplemented!("please add one once we need it")
}