-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy path_sre.java
More file actions
70 lines (62 loc) · 2.36 KB
/
Copy path_sre.java
File metadata and controls
70 lines (62 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright 2000 Finn Bock
*
* This program contains material copyrighted by:
* Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
*
* This version of the SRE library can be redistributed under CNRI's
* Python 1.6 license. For any other use, please contact Secret Labs
* AB (info@pythonware.com).
*
* Portions of this engine have been developed in cooperation with
* CNRI. Hewlett-Packard provided funding for 1.6 integration and
* other compatibility work.
*/
package org.python.modules;
import org.python.core.ArgParser;
import org.python.core.PyObject;
import org.python.core.PyUnicode;
import org.python.expose.ExposedConst;
import org.python.expose.ExposedFunction;
import org.python.expose.ExposedModule;
import org.python.modules.sre.PatternObject;
import org.python.modules.sre.SRE_STATE;
@ExposedModule
public class _sre {
@ExposedConst
public static final int MAGIC = SRE_STATE.SRE_MAGIC;
// probably the right number for Jython since we are UTF-16.
@ExposedConst
public static final int MAXREPEAT = Character.MAX_VALUE;
@ExposedConst
public static final int MAXGROUPS = Integer.MAX_VALUE;
// workaround the fact that H, I types are unsigned, but we are not really using them as such
// XXX: May not be the right size, but I suspect it is -- see sre_compile.py
@ExposedConst
public static final int CODESIZE = 4;
@ExposedFunction
public static PatternObject compile(PyObject[] args, String[] keywords) {
ArgParser ap = new ArgParser("compile", args, keywords,
"pattern", "flags", "code", "groups", "groupindex", "indexgroup");
PyObject pattern = ap.getPyObject(0);
int flags = ap.getInt(1);
PyObject code = ap.getPyObject(2);
int groups = ap.getInt(3);
PyObject groupindex = ap.getPyObject(4);
PyObject indexgroup = ap.getPyObject(5);
long[] ccode = new long[code.__len__()];
int i = 0;
for (PyObject item : code.asIterable()) {
ccode[i++] = item.asLong();
}
return new PatternObject(pattern, flags, ccode, groups, groupindex, indexgroup);
}
@ExposedFunction
public static int getcodesize() {
return CODESIZE;
}
@ExposedFunction
public static int getlower(PyObject ch, PyObject flags) {
return SRE_STATE.getlower(ch.asInt(), flags.asInt());
}
}