Skip to content

Commit

Permalink
Added sequence-query to *vastly* simplify browse by batch!
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fulton committed Sep 25, 1997
1 parent a8007ee commit cb55e83
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions DT_In.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
of the module 'Missing', if present.
'''

__rcs_id__='$Id: DT_In.py,v 1.4 1997/09/25 18:56:38 jim Exp $'
__rcs_id__='$Id: DT_In.py,v 1.5 1997/09/25 20:58:24 jim Exp $'

############################################################################
# Copyright
Expand Down Expand Up @@ -266,22 +266,36 @@
# (540) 371-6909
#
############################################################################
__version__='$Revision: 1.4 $'[11:-2]
__version__='$Revision: 1.5 $'[11:-2]

from DT_Util import *
from string import find, atoi, join
import regex
from regsub import gsub

class In:
blockContinuations=('else',)
name='in'
elses=None
expr=None
start_name_re=None

def __init__(self, blocks):
tname, args, section = blocks[0]
args=parse_params(args, name='', start='1',end='-1',size='10',
orphan='3',overlap='1',mapping=1,
previous=1, next=1, expr='')
self.args=args
if args.has_key('start'):
v=args['start']
if type(v)==type(''):
try: atoi(v)
except:
self.start_name_re=regex.compile(
'[?&]'+
join(map(lambda c: "[%s]" % c, v),'')+
'=[0-9]+\(&\|$\)')

name,expr=name_param(args,'in',1)
self.__name__, expr = name, expr
self.section=section
Expand Down Expand Up @@ -336,7 +350,11 @@ def render(self, md):

last=end-1
first=start-1
vars=sequence_variables(sequence)

try: query_string=md['QUERY_STRING']
except: query_string=''

vars=sequence_variables(sequence,'?'+query_string,self.start_name_re)
kw=vars.data
# kw['sequence-length']=l
kw['mapping']=mapping
Expand Down Expand Up @@ -411,7 +429,7 @@ def render(self, md):
if mapping:
client=mapping_wrapper(client)
result.append(section(client,md))
result=string.join(result, '')
result=join(result, '')
finally:
md.pop(1)

Expand Down Expand Up @@ -471,8 +489,12 @@ def __getattr__(self,name):

class sequence_variables:

def __init__(self,items=None):
def __init__(self,items=None,query_string='',start_name_re=None):

self.items=items
self.query_string=query_string
self.start_name_re=start_name_re

self.data={
'previous-sequence': 0,
'next-sequence': 0,
Expand Down Expand Up @@ -665,6 +687,18 @@ def __getitem__(self,key):
elif key=='sequence-length':
data[key]=l=len(self.items)
return l
elif key=='sequence-query' and self.start_name_re is not None:
query_string=self.query_string
re=self.start_name_re
l=re.search(query_string)
if l >= 0:
v=re.group(0)
if v[:1]=='?' or v[-1:]=='&': b=l+1
else: b=l
query_string=query_string[:b]+query_string[l+len(v):]
data[key]=query_string
return query_string

raise KeyError, key

def next_batches(self):
Expand All @@ -682,7 +716,8 @@ def next_batches(self):
r=[]
while end < l:
start,end,spam=opt(end+1-overlap,None,sz,orphan,sequence)
v=sequence_variables(self.items)
v=sequence_variables(self.items,
self.query_string,self.start_name_re)
d=v.data
d['batch-start-index']=start-1
d['batch-end-index']=end-1
Expand All @@ -707,7 +742,8 @@ def previous_batches(self):
r=[]
while start > 1:
start,end,spam=opt(None,start-1+overlap,sz,orphan,sequence)
v=sequence_variables(self.items)
v=sequence_variables(self.items,
self.query_string,self.start_name_re)
d=v.data
d['batch-start-index']=start-1
d['batch-end-index']=end-1
Expand All @@ -720,6 +756,9 @@ def previous_batches(self):

############################################################################
# $Log: DT_In.py,v $
# Revision 1.5 1997/09/25 20:58:24 jim
# Added sequence-query to *vastly* simplify browse by batch!
#
# Revision 1.4 1997/09/25 18:56:38 jim
# fixed problem in reporting errors
#
Expand Down

0 comments on commit cb55e83

Please sign in to comment.