66use crate :: pyobject:: { PyContext , PyObjectRef } ;
77
88pub fn mk_module ( ctx : & PyContext ) -> PyObjectRef {
9- let py_mod = ctx. new_module ( & "string" . to_string ( ) , ctx. new_scope ( None ) ) ;
10-
119 let ascii_lowercase = "abcdefghijklmnopqrstuvwxyz" . to_string ( ) ;
1210 let ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" . to_string ( ) ;
1311 let ascii_letters = format ! ( "{}{}" , ascii_lowercase, ascii_uppercase) ;
@@ -21,15 +19,15 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
2119 */
2220
2321 // Constants:
24- ctx . set_attr ( & py_mod , "ascii_letters " , ctx . new_str ( ascii_letters ) ) ;
25- ctx . set_attr ( & py_mod , "ascii_lowercase" , ctx. new_str ( ascii_lowercase ) ) ;
26- ctx . set_attr ( & py_mod , "ascii_uppercase" , ctx. new_str ( ascii_uppercase ) ) ;
27- ctx . set_attr ( & py_mod , "digits" , ctx. new_str ( digits ) ) ;
28- ctx . set_attr ( & py_mod , "hexdigits" , ctx. new_str ( hexdigits ) ) ;
29- ctx . set_attr ( & py_mod , "octdigits" , ctx. new_str ( octdigits ) ) ;
30- // ctx.set_attr(&py_mod, "printable", ctx.new_str(printable));
31- ctx . set_attr ( & py_mod , "punctuation ", ctx. new_str ( punctuation ) ) ;
32- // ctx.set_attr(&py_mod, "whitespace", ctx.new_str(whitespace));
33-
34- py_mod
22+ py_module ! ( ctx , "string " , {
23+ "ascii_letters" => ctx. new_str( ascii_letters ) ,
24+ "ascii_lowercase" => ctx. new_str( ascii_lowercase ) ,
25+ "ascii_uppercase" => ctx. new_str( ascii_uppercase ) ,
26+ "digits" => ctx. new_str( digits ) ,
27+ "hexdigits" => ctx. new_str( hexdigits ) ,
28+ "octdigits" => ctx. new_str( octdigits ) ,
29+ // "printable ", ctx.new_str(printable)
30+ "punctuation" => ctx. new_str( punctuation )
31+ // "whitespace", ctx.new_str(whitespace)
32+ } )
3533}
0 commit comments