Ejemplo n.º 1
0
 def tagre(self):
     return regex.symcomp(
         '%('                                     # beginning
         '\(<name>[a-zA-Z0-9_/.-]+\)'                       # tag name
         '\('
         '[\0- ]+'                                # space after tag name
         '\(<args>\([^)"]+\("[^"]*"\)?\)*\)'      # arguments
         '\)?'
         ')\(<fmt>[0-9]*[.]?[0-9]*[a-z]\|[]![]\)' # end
         , regex.casefold) 
Ejemplo n.º 2
0
 def compilepatterns(self):
     for name in dir(self):
         if name[-4:] == "_pat":
             pat = getattr(self, name)
             prog = regex.symcomp(pat)
             setattr(self, name[:-4], prog)
Ejemplo n.º 3
0
#
# Note that it will _always_ prompt you if the file in the editor has been modified.

import win32ui
import win32api
import win32con
import regex
import re
import string
import sys, os
import traceback
from pywin.mfc import docview, dialog, afxres

from pywin.framework.editor import GetEditorOption, SetEditorOption, GetEditorFontOption, SetEditorFontOption, defaultCharacterFormat

patImport = regex.symcomp('import \(<name>.*\)')
patIndent = regex.compile('^\\([ \t]*[~ \t]\\)')

ID_LOCATE_FILE = 0xe200
ID_GOTO_LINE = 0xe2001
MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER + 1999  ## WARNING: Duplicated in document.py and coloreditor.py

# Key Codes that modify the bufffer when Ctrl or Alt are NOT pressed.
MODIFYING_VK_KEYS = [
    win32con.VK_BACK, win32con.VK_TAB, win32con.VK_RETURN, win32con.VK_SPACE,
    win32con.VK_DELETE
]
for k in range(48, 91):
    MODIFYING_VK_KEYS.append(k)

# Key Codes that modify the bufffer when Ctrl is pressed.
Ejemplo n.º 4
0
are recognized and imported modules are scanned as well, this
shouldn't happen often.

BUGS
Continuation lines are not dealt with at all and strings may confuse
the hell out of the parser, but it usually works.'''

import os
import sys
import imp
import regex
import string

id = '\\(<id>[A-Za-z_][A-Za-z0-9_]*\\)'	# match identifier
blank_line = regex.compile('^[ \t]*\\($\\|#\\)')
is_class = regex.symcomp('^class[ \t]+'+id+'[ \t]*\\(<sup>([^)]*)\\)?[ \t]*:')
is_method = regex.symcomp('^[ \t]+def[ \t]+'+id+'[ \t]*(')
is_import = regex.symcomp('^import[ \t]*\\(<imp>[^#]+\\)')
is_from = regex.symcomp('^from[ \t]+'+id+'[ \t]+import[ \t]+\\(<imp>[^#]+\\)')
dedent = regex.compile('^[^ \t]')
indent = regex.compile('^[^ \t]*')

_modules = {}				# cache of modules we've seen

# each Python class is represented by an instance of this class
class Class:
	'''Class to represent a Python class.'''
	def __init__(self, module, name, super, file, lineno):
		self.module = module
		self.name = name
		if super is None:
Ejemplo n.º 5
0
regex.set_syntax(prev)
print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')

re = '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
print 'matching with group names and compile()'
cre = regex.compile(re)
print cre.match('801 999')
try:
    print cre.group('one')
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'

print 'matching with group names and symcomp()'
cre = regex.symcomp(re)
print cre.match('801 999')
print cre.group(0)
print cre.group('one')
print cre.group(1, 2)
print cre.group('one', 'two')
print 'realpat:', cre.realpat
print 'groupindex:', sortdict(cre.groupindex)

re = 'world'
cre = regex.compile(re)
print 'not case folded search:', cre.search('HELLO WORLD')
cre = regex.compile(re, regex.casefold)
print 'case folded search:', cre.search('HELLO WORLD')

print '__members__:', cre.__members__
Ejemplo n.º 6
0
import regex
import re
import string
import sys, os
import traceback
from pywin.mfc import docview, dialog, afxres

from pywin.framework.editor import (
    GetEditorOption,
    SetEditorOption,
    GetEditorFontOption,
    SetEditorFontOption,
    defaultCharacterFormat,
)

patImport = regex.symcomp("import \(<name>.*\)")
patIndent = regex.compile("^\\([ \t]*[~ \t]\\)")

ID_LOCATE_FILE = 0xE200
ID_GOTO_LINE = 0xE2001
MSG_CHECK_EXTERNAL_FILE = (
    win32con.WM_USER + 1999
)  ## WARNING: Duplicated in document.py and coloreditor.py

# Key Codes that modify the bufffer when Ctrl or Alt are NOT pressed.
MODIFYING_VK_KEYS = [
    win32con.VK_BACK,
    win32con.VK_TAB,
    win32con.VK_RETURN,
    win32con.VK_SPACE,
    win32con.VK_DELETE,
Ejemplo n.º 7
0
def main():
    form = cgi.FormContentDict()

    archive = os.environ['PATH_TRANSLATED']
    try:
	path = form['file'][0]
    except KeyError:
	path = ''

    tmpdir = '/tmp/%s' % os.getpid()

    try:
	os.mkdir(tmpdir, 0755)
    except os.error:
	pass

    f = os.popen('/usr/contrib/bin/gzcat %s | tar tvf - %s' % (archive, path), 'r')


    listing = f.readlines()
    if listing:

	if listing[0][0] == 'd':
	    _write(sys.stdout,'Content-type: %s\r\n\r\n' % 'text/html')
	    _write(sys.stdout,'<html><head><title>%s</title></head><body><pre>\n' %
		   path)
	    # user asked for a directory - send back a listing
	    listing = listing[1:-1]
	    splpat = regex.symcomp('\(<f>.* \)\(<r>.*\)')
	    deeppat = regex.compile('%s/[^/]*/' % path)
	    pathinfo = os.environ['PATH_INFO']
	    super = string.join(string.split(path, '/')[:-1], '/')
	    if super:
		_write(sys.stdout,' '*32)
		_write(sys.stdout,'<a href="/cgi-bin/tgzextr%s?file=%s">&lt;Up One Level&gt;</a>\n' %
		      (pathinfo, super))
	    for line in map(string.strip, listing):
		if splpat.match(line) != -1:
		    first = splpat.group('f')
		    rest = splpat.group('r')
		    if deeppat.match(rest) != -1: continue
		    _write(sys.stdout,first[:11]+first[32:])
		    _write(sys.stdout,'<a href="/cgi-bin/tgzextr%s?file=%s">%s</a>\n' %
			  (pathinfo, rest, rest))
	else:
	    fmimetype = mimetypes.get_type(path)

	    _write(sys.stdout,'Content-type: %s\r\n\r\n' % fmimetype)
	    os.chdir(tmpdir)
	    os.system("/usr/contrib/bin/gzcat %s | tar xf - %s" % (archive, path))

	    _writelines(sys.stdout,open('%s/%s' % (tmpdir, path)).readlines())

	    os.unlink('%s/%s' % (tmpdir, path))
	    path = string.split(path)[:-1]
	    try:
		while path:
		    dirs = string.join(path)
		    os.rmdir('%s/%s', (tmpdir, dirs))
		    path = path[:-1]
		os.rmdir(tmpdir)
	    except os.error:
		pass
Ejemplo n.º 8
0
def main():
    form = cgi.FormContentDict()

    archive = os.environ['PATH_TRANSLATED']
    try:
        path = form['file'][0]
    except KeyError:
        path = ''

    tmpdir = '/tmp/%s' % os.getpid()

    try:
        os.mkdir(tmpdir, 0755)
    except os.error:
        pass

    f = os.popen('/usr/contrib/bin/gzcat %s | tar tvf - %s' % (archive, path),
                 'r')

    listing = f.readlines()
    if listing:

        if listing[0][0] == 'd':
            _write(sys.stdout, 'Content-type: %s\r\n\r\n' % 'text/html')
            _write(sys.stdout,
                   '<html><head><title>%s</title></head><body><pre>\n' % path)
            # user asked for a directory - send back a listing
            listing = listing[1:-1]
            splpat = regex.symcomp('\(<f>.* \)\(<r>.*\)')
            deeppat = regex.compile('%s/[^/]*/' % path)
            pathinfo = os.environ['PATH_INFO']
            super = string.join(string.split(path, '/')[:-1], '/')
            if super:
                _write(sys.stdout, ' ' * 32)
                _write(
                    sys.stdout,
                    '<a href="/cgi-bin/tgzextr%s?file=%s">&lt;Up One Level&gt;</a>\n'
                    % (pathinfo, super))
            for line in map(string.strip, listing):
                if splpat.match(line) != -1:
                    first = splpat.group('f')
                    rest = splpat.group('r')
                    if deeppat.match(rest) != -1: continue
                    _write(sys.stdout, first[:11] + first[32:])
                    _write(
                        sys.stdout,
                        '<a href="/cgi-bin/tgzextr%s?file=%s">%s</a>\n' %
                        (pathinfo, rest, rest))
        else:
            fmimetype = mimetypes.get_type(path)

            _write(sys.stdout, 'Content-type: %s\r\n\r\n' % fmimetype)
            os.chdir(tmpdir)
            os.system("/usr/contrib/bin/gzcat %s | tar xf - %s" %
                      (archive, path))

            _writelines(sys.stdout, open('%s/%s' % (tmpdir, path)).readlines())

            os.unlink('%s/%s' % (tmpdir, path))
            path = string.split(path)[:-1]
            try:
                while path:
                    dirs = string.join(path)
                    os.rmdir('%s/%s', (tmpdir, dirs))
                    path = path[:-1]
                os.rmdir(tmpdir)
            except os.error:
                pass
Ejemplo n.º 9
0
	def compilepatterns(self):
		for name in dir(self):
			if name[-4:] == "_pat":
				pat = getattr(self, name)
				prog = regex.symcomp(pat)
				setattr(self, name[:-4], prog)
Ejemplo n.º 10
0
 def __init__(self, *args):
     self._r=r=regex.symcomp(*args)
     self._init(r)
     self.groupindex=r.groupindex
Ejemplo n.º 11
0
"""\
Ejemplo n.º 12
0
from test_support import verbose, sortdict
import warnings
warnings.filterwarnings("ignore", "the regex module is deprecated",
                        DeprecationWarning, __name__)
import regex
from regex_syntax import *
re = 'a+b+c+'
print 'no match:', regex.match(re, 'hello aaaabcccc world')
print 'successful search:', regex.search(re, 'hello aaaabcccc world')
try:
    cre = regex.compile('\(' + re)
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'
print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
prev = regex.set_syntax(RE_SYNTAX_AWK)
print 'successful awk syntax:', regex.search('(a+)|(b+)', 'cdb')
regex.set_syntax(prev)
print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
re = '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
print 'matching with group names and compile()'
cre = regex.compile(re)
print cre.match('801 999')
try:
    print cre.group('one')
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'
Ejemplo n.º 13
0
"""\
Ejemplo n.º 14
0
# Note that it will _always_ prompt you if the file in the editor has been modified.


import win32ui
import win32api
import win32con
import regex
import re
import string
import sys, os
import traceback
from pywin.mfc import docview, dialog, afxres

from pywin.framework.editor import GetEditorOption, SetEditorOption, GetEditorFontOption, SetEditorFontOption, defaultCharacterFormat

patImport=regex.symcomp('import \(<name>.*\)')
patIndent=regex.compile('^\\([ \t]*[~ \t]\\)')

ID_LOCATE_FILE = 0xe200
ID_GOTO_LINE = 0xe2001
MSG_CHECK_EXTERNAL_FILE = win32con.WM_USER+1999 ## WARNING: Duplicated in document.py and coloreditor.py

# Key Codes that modify the bufffer when Ctrl or Alt are NOT pressed.
MODIFYING_VK_KEYS = [win32con.VK_BACK, win32con.VK_TAB, win32con.VK_RETURN, win32con.VK_SPACE, win32con.VK_DELETE]
for k in range(48, 91):
	MODIFYING_VK_KEYS.append(k)

# Key Codes that modify the bufffer when Ctrl is pressed.
MODIFYING_VK_KEYS_CTRL = [win32con.VK_BACK, win32con.VK_RETURN, win32con.VK_SPACE, win32con.VK_DELETE]

# Key Codes that modify the bufffer when Alt is pressed.
Ejemplo n.º 15
0
are recognized and imported modules are scanned as well, this
shouldn't happen often.

BUGS
Continuation lines are not dealt with at all and strings may confuse
the hell out of the parser, but it usually works.'''

import os
import sys
import imp
import regex
import string

id = '\\(<id>[A-Za-z_][A-Za-z0-9_]*\\)'  # match identifier
blank_line = regex.compile('^[ \t]*\\($\\|#\\)')
is_class = regex.symcomp('^class[ \t]+' + id +
                         '[ \t]*\\(<sup>([^)]*)\\)?[ \t]*:')
is_method = regex.symcomp('^[ \t]+def[ \t]+' + id + '[ \t]*(')
is_import = regex.symcomp('^import[ \t]*\\(<imp>[^#]+\\)')
is_from = regex.symcomp('^from[ \t]+' + id +
                        '[ \t]+import[ \t]+\\(<imp>[^#]+\\)')
dedent = regex.compile('^[^ \t]')
indent = regex.compile('^[^ \t]*')

_modules = {}  # cache of modules we've seen


# each Python class is represented by an instance of this class
class Class:
    '''Class to represent a Python class.'''
    def __init__(self, name, super, file, lineno):
        self.name = name
Ejemplo n.º 16
0
regex.set_syntax(prev)
print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')

re = '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
print 'matching with group names and compile()'
cre = regex.compile(re)
print cre.match('801 999')
try:
    print cre.group('one')
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'

print 'matching with group names and symcomp()'
cre = regex.symcomp(re)
print cre.match('801 999')
print cre.group(0)
print cre.group('one')
print cre.group(1, 2)
print cre.group('one', 'two')
print 'realpat:', cre.realpat
print 'groupindex:', sortdict(cre.groupindex)

re = 'world'
cre = regex.compile(re)
print 'not case folded search:', cre.search('HELLO WORLD')
cre = regex.compile(re, regex.casefold)
print 'case folded search:', cre.search('HELLO WORLD')

print '__members__:', cre.__members__
Ejemplo n.º 17
0
from test_support import verbose, sortdict
import warnings
warnings.filterwarnings("ignore", "the regex module is deprecated",
                        DeprecationWarning, __name__)
import regex
from regex_syntax import *
re = 'a+b+c+'
print 'no match:', regex.match(re, 'hello aaaabcccc world')
print 'successful search:', regex.search(re, 'hello aaaabcccc world')
try:
    cre = regex.compile('\(' + re)
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'
print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
prev = regex.set_syntax(RE_SYNTAX_AWK)
print 'successful awk syntax:', regex.search('(a+)|(b+)', 'cdb')
regex.set_syntax(prev)
print 'failed awk syntax:', regex.search('(a+)|(b+)', 'cdb')
re = '\(<one>[0-9]+\) *\(<two>[0-9]+\)'
print 'matching with group names and compile()'
cre = regex.compile(re)
print cre.match('801 999')
try:
    print cre.group('one')
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'