-
Notifications
You must be signed in to change notification settings - Fork 7
/
woexp.pyx
31 lines (24 loc) · 1.14 KB
/
woexp.pyx
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
cimport woexp
__doc__ = 'Primitive wordexp.h wrapper'
cpdef enum:
WRDE_DOOFFS = (1 << 0) # Insert PWORDEXP->we_offs NULLs.
WRDE_APPEND = (1 << 1) # Append to results of a previous call.
WRDE_NOCMD = (1 << 2) # Don't do command substitution.
WRDE_REUSE = (1 << 3) # Reuse storage in PWORDEXP.
WRDE_SHOWERR = (1 << 4) # Don't redirect stderr to /dev/null.
WRDE_UNDEF = (1 << 5) # Error for expanding undefined variables.
cdef class WordExp:
'wordexp.h wrapper class'
cdef woexp.wordexp_t data
def __init__(self, char *s, int flags=0):
'''__init__(s, flags)\n\nPerform wordexp(s, self.data, flags)'''
self.expand(s, flags&~WRDE_REUSE)
def __dealloc__(self):
woexp.wordfree(&self.data)
def expand(self, char *s, int flags=WRDE_REUSE):
'''expand(s, flags=WRDE_REUSE)\n\nPerform wordexp(s, self.data, flags)'''
if woexp.wordexp(s, &self.data, flags):
raise MemoryError("Cannot perform expansion")
def result(self):
'''result()\n\nReturn list of filenames.'''
return [self.data.we_wordv[i+self.data.we_offs] for i in xrange(self.data.we_wordc)]