| 1 |
from Form import * |
|---|
| 2 |
from Table import * |
|---|
| 3 |
from Module import * |
|---|
| 4 |
import validations |
|---|
| 5 |
|
|---|
| 6 |
NOTE_HEADER = "Header against which the regular expression will be evaluated." |
|---|
| 7 |
NOTE_MATCH = "Regular expression." |
|---|
| 8 |
|
|---|
| 9 |
LENGHT_LIMIT = 10 |
|---|
| 10 |
|
|---|
| 11 |
HEADERS = [ |
|---|
| 12 |
('Accept-Encoding', 'Accept-Encoding'), |
|---|
| 13 |
('Accept-Charset', 'Accept-Charset'), |
|---|
| 14 |
('Accept-Language', 'Accept-Language'), |
|---|
| 15 |
('Referer', 'Referer'), |
|---|
| 16 |
('User-Agent', 'User-Agent') |
|---|
| 17 |
] |
|---|
| 18 |
|
|---|
| 19 |
class ModuleHeader (Module, FormHelper): |
|---|
| 20 |
validation = [('tmp!new_rule!match', validations.is_regex)] |
|---|
| 21 |
|
|---|
| 22 |
def __init__ (self, cfg, prefix, submit_url): |
|---|
| 23 |
FormHelper.__init__ (self, 'header', cfg) |
|---|
| 24 |
Module.__init__ (self, 'header', cfg, prefix, submit_url) |
|---|
| 25 |
|
|---|
| 26 |
def _op_render (self): |
|---|
| 27 |
table = TableProps() |
|---|
| 28 |
if self._prefix.startswith('tmp!'): |
|---|
| 29 |
self.AddPropOptions_Reload (table, 'Header', '%s!value'%(self._prefix), HEADERS, NOTE_HEADER) |
|---|
| 30 |
else: |
|---|
| 31 |
self.AddPropOptions_Reload (table, 'Header', '%s!header'%(self._prefix), HEADERS, NOTE_HEADER) |
|---|
| 32 |
self.AddPropEntry (table, 'Regular Expression', '%s!match'%(self._prefix), NOTE_MATCH) |
|---|
| 33 |
return str(table) |
|---|
| 34 |
|
|---|
| 35 |
def apply_cfg (self, values): |
|---|
| 36 |
if values.has_key('value'): |
|---|
| 37 |
header = values['value'] |
|---|
| 38 |
self._cfg['%s!match!header'%(self._prefix)] = header |
|---|
| 39 |
|
|---|
| 40 |
if values.has_key('match'): |
|---|
| 41 |
match = values['match'] |
|---|
| 42 |
self._cfg['%s!match!match'%(self._prefix)] = match |
|---|
| 43 |
|
|---|
| 44 |
def get_name (self): |
|---|
| 45 |
header = self._cfg.get_val ('%s!match!header'%(self._prefix)) |
|---|
| 46 |
if not header: |
|---|
| 47 |
return '' |
|---|
| 48 |
|
|---|
| 49 |
tmp = self._cfg.get_val ('%s!match!match'%(self._prefix), '') |
|---|
| 50 |
if len(tmp) > LENGHT_LIMIT: |
|---|
| 51 |
return "%s (%s..)" % (header, tmp[:5]) |
|---|
| 52 |
|
|---|
| 53 |
return "%s (%s)" % (header, tmp) |
|---|
| 54 |
|
|---|
| 55 |
def get_type_name (self): |
|---|
| 56 |
return self._id.capitalize() |
|---|