|
| 1 | +/* String builtin module |
| 2 | + * |
| 3 | + * |
| 4 | + */ |
| 5 | + |
| 6 | +use super::super::pyobject::{PyContext, PyObjectRef}; |
| 7 | + |
| 8 | +pub fn mk_module(ctx: &PyContext) -> PyObjectRef { |
| 9 | + let py_mod = ctx.new_module(&"string".to_string(), ctx.new_scope(None)); |
| 10 | + |
| 11 | + let ascii_lowercase = "abcdefghijklmnopqrstuvwxyz".to_string(); |
| 12 | + let ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".to_string(); |
| 13 | + let ascii_letters = format!("{}{}", ascii_lowercase, ascii_uppercase); |
| 14 | + let digits = "0123456789".to_string(); |
| 15 | + let hexdigits = "0123456789abcdefABCDEF".to_string(); |
| 16 | + let octdigits = "01234567".to_string(); |
| 17 | + let punctuation = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~".to_string(); |
| 18 | + /* FIXME |
| 19 | + let whitespace = " \t\n\r\x0b\x0c".to_string(); |
| 20 | + let printable = format!("{}{}{}{}", digits, ascii_letters, punctuation, whitespace); |
| 21 | + */ |
| 22 | + |
| 23 | + // Constants: |
| 24 | + ctx.set_attr(&py_mod, "ascii_letters", ctx.new_str(ascii_letters.clone())); |
| 25 | + ctx.set_attr( |
| 26 | + &py_mod, |
| 27 | + "ascii_lowercase", |
| 28 | + ctx.new_str(ascii_lowercase.clone()), |
| 29 | + ); |
| 30 | + ctx.set_attr( |
| 31 | + &py_mod, |
| 32 | + "ascii_uppercase", |
| 33 | + ctx.new_str(ascii_uppercase.clone()), |
| 34 | + ); |
| 35 | + ctx.set_attr(&py_mod, "digits", ctx.new_str(digits.clone())); |
| 36 | + ctx.set_attr(&py_mod, "hexdigits", ctx.new_str(hexdigits.clone())); |
| 37 | + ctx.set_attr(&py_mod, "octdigits", ctx.new_str(octdigits.clone())); |
| 38 | + // ctx.set_attr(&py_mod, "printable", ctx.new_str(printable.clone())); |
| 39 | + ctx.set_attr(&py_mod, "punctuation", ctx.new_str(punctuation.clone())); |
| 40 | + // ctx.set_attr(&py_mod, "whitespace", ctx.new_str(whitespace.clone())); |
| 41 | + |
| 42 | + py_mod |
| 43 | +} |
0 commit comments