rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
Globals.Bobobase['roles']=tuple(role_names)
role_names=tuple(role_names) if Globals.Bobobase['roles'] != role_names: Globals.Bobobase['roles'] = role_names
def productItems(self, name=name): t=[] for i in self.objectMap(): if i['meta_type']=='Image': n=i['name'] t.append((n,getattr(self,n))) return t
import sys, os, string, types, cgi, regex, regsub, base64
import sys, os, string, cgi, regex, regsub
def main(): # The "main" program for this module pass
try:
if environ.has_key('HTTP_AUTHORIZATION'):
def __init__(self,
del environ['HTTP_AUTHORIZATION'] except: try: self.HTTP_AUTHORIZATION=environ['HTTP_CGI_AUTHORIZATION'] del environ['HTTP_CGI_AUTHORIZATION']
try: del environ['HTTP_AUTHORIZATION'] except: pass elif environ.has_key('HTTP_CGI_AUTHORIZATION'): self.HTTP_AUTHORIZATION=environ['HTTP_CGI_AUTHORIZATION'] try: del environ['HTTP_CGI_AUTHORIZATION']
def __init__(self,
try: fslist=fs.list except: fslist=None if fslist is None: form['BODY']=fs.value other['BODY']=fs.value
if not hasattr(fs,'list'): form['BODY']=other['BODY']=fs.value
def __init__(self,
try:
if (hasattr(item,'file') and hasattr(item,'filename') and hasattr(item,'headers')):
def __init__(self,
except: pass
def __init__(self,
try: bobo_before=module.__bobo_before__ except: bobo_before=None try: bobo_after=module.__bobo_after__ except: bobo_after=None
if hasattr(module,'__bobo_before__'): bobo_before=module.__bobo_before__ else: bobo_before=None if hasattr(module,'__bobo_after__'): bobo_after=module.__bobo_after__ else: bobo_after=None
def get_module_info(self, server_name, module_name, module):
try: request_params=module.__request_data__ except: request_params=None
if hasattr(module,'__request_data__'): request_params=module.__request_data__ else: request_params=None
def get_module_info(self, server_name, module_name, module):
try:
if hasattr(module,'__allow_groups__'):
def get_module_info(self, server_name, module_name, module):
except: groups=None
else: groups=None
def get_module_info(self, server_name, module_name, module):
try:
if hasattr(module,'bobo_application'):
def get_module_info(self, server_name, module_name, module):
try:
if hasattr(object,'__allow_groups__'):
def get_module_info(self, server_name, module_name, module):
except: groups=None try: roles=object.__roles__ except: pass except: try:
else: groups=None if hasattr(object,'__roles__'): roles=object.__roles__ else: if hasattr(module,'web_objects'):
def get_module_info(self, server_name, module_name, module):
except: object=module
else: object=module
def get_module_info(self, server_name, module_name, module):
try: if lower(self.request['SUBMIT'])=='cancel': cancel=self.request['CANCEL_ACTION'] except: pass if cancel: raise 'Redirect', cancel
if request_get('SUBMIT','')=='cancel': cancel=request_get('CANCEL_ACTION','') if cancel: raise 'Redirect', cancel
def publish(self, module_name, after_list, published='web_objects',
request=self.request response=self.response
def publish(self, module_name, after_list, published='web_objects',
try:
info_key=server_name, module_name if module_dicts.has_key(info_key):
def publish(self, module_name, after_list, published='web_objects',
) = info = module_dicts[server_name, module_name] except:
) = info = module_dicts[info_key] else:
def publish(self, module_name, after_list, published='web_objects',
module_dicts[server_name, module_name]=info
module_dicts[info_key]=info
def publish(self, module_name, after_list, published='web_objects',
path=strip(request['PATH_INFO'])
path=strip(request_get('PATH_INFO'))
def publish(self, module_name, after_list, published='web_objects',
method=upper(request['REQUEST_METHOD'])
method=upper(request_get('REQUEST_METHOD'))
def publish(self, module_name, after_list, published='web_objects',
try: object=object.__of__(RequestContainer(REQUEST=self.request)) except: pass
if hasattr(object, '__of__'): object=object.__of__(RequestContainer(REQUEST=request))
def publish(self, module_name, after_list, published='web_objects',
try: roles=subobject.__roles__ except:
if hasattr(subobject,'__roles__'): roles=subobject.__roles__ else:
def publish(self, module_name, after_list, published='web_objects',
try: roles=getattr(object, entry_name+'__roles__') except:
roleshack=entry_name+'__roles__' if hasattr(object, roleshack): roles=getattr(object, roleshack) else:
def publish(self, module_name, after_list, published='web_objects',
try: groups=parents[i].__allow_groups__ except: groups=-1 if groups == -1: continue try: v=groups.validate except: v=old_validation
if hasattr(parents[i],'__allow_groups__'): groups=parents[i].__allow_groups__ else: continue if hasattr(groups, 'validate'): v=groups.validate else: v=old_validation
def publish(self, module_name, after_list, published='web_objects',
try: roles=groups.keys() except AttributeError:
if hasattr(groups,'keys'): roles=groups.keys() else:
def publish(self, module_name, after_list, published='web_objects',
try: auth=self.HTTP_AUTHORIZATION except: self.unauthorized(realm)
auth=self.HTTP_AUTHORIZATION
def publish(self, module_name, after_list, published='web_objects',
try: groups=parents[i].__allow_groups__ except: groups=-1
parent=parents[i]
def publish(self, module_name, after_list, published='web_objects',
if groups == -1: continue try: v=groups.validate except: v=old_validation
if hasattr(parent, '__allow_groups__'): groups=parent.__allow_groups__ else: continue if hasattr(groups,'validate'): v=groups.validate else: v=old_validation
def publish(self, module_name, after_list, published='web_objects',
if user is None: self.unauthorized(realm)
if user is None and roles != UNSPECIFIED_ROLES: self.unauthorized(realm)
def publish(self, module_name, after_list, published='web_objects',
info="\t" + request['PATH_INFO'] try: info=("%s %s" % (steps,request['AUTHENTICATED_USER']))+info except: pass
info="\t" + request_get('PATH_INFO') auth_user=request_get('AUTHENTICATED_USER',None) if auth_user is not None: info=("%s %s" % (steps,auth_user))+info
def publish(self, module_name, after_list, published='web_objects',
object_as_function=object if type(object_as_function) is types.ClassType: if hasattr(object_as_function,'__init__'): object_as_function=object_as_function.__init__ else: def function_with_empty_signature(): pass object_as_function=function_with_empty_signature
object_as_function=object
def publish(self, module_name, after_list, published='web_objects',
try: defaults=object_as_function.im_func.func_defaults argument_names=( object_as_function.im_func. func_code.co_varnames[ 1:object_as_function.im_func.func_code.co_argcount]) except:
if hasattr(object_as_function,'im_func'): f=object_as_function.im_func c=f.func_code defaults=f.func_defaults argument_names=c.co_varnames[1:c.co_argcount] else:
def function_with_empty_signature(): pass
try:
if hasattr(object_as_function,'func_defaults'):
def function_with_empty_signature(): pass
argument_names=object_as_function.func_code.co_varnames[ :object_as_function.func_code.co_argcount] except: return response.setBody(object)
c=object_as_function.func_code argument_names=c.co_varnames[:c.co_argcount] if hasattr(object_as_function, '__bases__'): self.forbiddenError(entry_name) else: return response.setBody(object)
def function_with_empty_signature(): pass
try: p=parents[i].aq_self
parent=parents[i] if hasattr(parent,'aq_self'): p=parent.aq_self
def function_with_empty_signature(): pass
except: pass
def function_with_empty_signature(): pass
try: v=request[argument_name] args.append(v) except (KeyError,AttributeError,IndexError):
v=request_get(argument_name, args) if v is args:
def function_with_empty_signature(): pass
except: raise 'BadRequest', ( '<strong>Invalid entry for <em>%s</em> </strong>' % argument_name)
else: args.append(v)
def function_with_empty_signature(): pass
if type(v) is types.ListType:
if type(v) is ListType:
def str_field(v): if type(v) is types.ListType: return map(str_field,v) if type(v) is types.InstanceType and v.__class__ is FieldStorage: v=v.value elif type(v) is not types.StringType: try: if v.file: v=v.file else: v=v.value except: pass return v
if type(v) is types.InstanceType and v.__class__ is FieldStorage:
if hasattr(v,'__class__') and v.__class__ is FieldStorage:
def str_field(v): if type(v) is types.ListType: return map(str_field,v) if type(v) is types.InstanceType and v.__class__ is FieldStorage: v=v.value elif type(v) is not types.StringType: try: if v.file: v=v.file else: v=v.value except: pass return v
elif type(v) is not types.StringType: try: if v.file: v=v.file else: v=v.value except: pass
elif type(v) is not StringType: if hasattr(v,'file') and v.file: v=v.file elif hasattr(v,'value'): v=v.value
def str_field(v): if type(v) is types.ListType: return map(str_field,v) if type(v) is types.InstanceType and v.__class__ is FieldStorage: v=v.value elif type(v) is not types.StringType: try: if v.file: v=v.file else: v=v.value except: pass return v
try: methods=file.__methods__ except: methods= ['close', 'fileno', 'flush', 'isatty', 'read', 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write', 'writelines']
if hasattr(file, '__methods__'): methods=file.__methods__ else: methods= ['close', 'fileno', 'flush', 'isatty', 'read', 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write', 'writelines'] d=self.__dict__
def __init__(self, aFieldStorage):
try: self.__dict__[m]=getattr(file,m) except: pass
if hasattr(file,m): d[m]=getattr(file,m)
def __init__(self, aFieldStorage):
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2string(v): try: v=v.read() except: v=str(v) return v
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2text(v, nl=regex.compile('\r\n\|\n\r'), sub=regsub.gsub): try: v=v.read() except: v=str(v) v=sub(nl,'\n',v) return v
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2required(v): try: v=v.read() except: v=str(v) if strip(v): return v raise ValueError, 'No input for required field<p>'
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2int(v): try: v=v.read() except: v=str(v) # we can remove the check for an empty string when we go to python 1.4 if v: return atoi(v) raise ValueError, 'Empty entry when <strong>integer</strong> expected'
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2float(v): try: v=v.read() except: v=str(v) # we can remove the check for an empty string when we go to python 1.4 if v: return atof(v) raise ValueError, ( 'Empty entry when <strong>floating-point number</strong> expected')
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2long(v): try: v=v.read() except: v=str(v) # we can remove the check for an empty string when we go to python 1.4 if v: return atol(v) raise ValueError, 'Empty entry when <strong>integer</strong> expected'
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2Regex(v): try: v=v.read() except: v=str(v) if v: return regex.compile(v)
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2regex(v): try: v=v.read() except: v=str(v) if v: return regex.compile(v,regex.casefold)
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2Regexs(v): try: v=v.read() except: v=str(v) v= map(lambda v: regex.compile(v), split(v)) if v: return v
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2regexs(v): try: v=v.read() except: v=str(v) v= map(lambda v: regex.compile(v, regex.casefold), split(v)) if v: return v
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2tokens(v): try: v=v.read() except: v=str(v) return split(v)
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2lines(v, crlf=regex.compile('\r\n\|\n\r')): try: v=v.read() except: v=str(v) v=regsub.gsub(crlf,'\n',v) return split(v,'\n')
try: v=v.read() except: v=str(v)
if hasattr(v,'read'): v=v.read() else: v=str(v)
def field2date(v): from DateTime import DateTime try: v=v.read() except: v=str(v) return DateTime(v)
if type(v) is not types.ListType: v=[v]
if type(v) is not ListType: v=[v]
def field2list(v): if type(v) is not types.ListType: v=[v] return v
if type(v) is not types.ListType: v=(v,)
if type(v) is not ListType: v=(v,)
def field2tuple(v): if type(v) is not types.ListType: v=(v,) return tuple(v)
try: try: server_url="http://%s" % strip(environ['HTTP_HOST']) except: server_url=strip(environ['SERVER_URL'])
if have_env('HTTP_HOST'): server_url="http://%s" % strip(environ['HTTP_HOST'])
def __init__(self,environ,form,stdin):
except:
elif have_env('SERVER_URL'): server_url=strip(environ['SERVER_URL']) if server_url[-1:]=='/': server_url=server_url[:-1] else:
def __init__(self,environ,form,stdin):
def has_key(self,key): try: self[key] return 1 except: return 0
def has_key(self,key):
try: return other[key] except: pass if URLmatch(key) >= 0 and other.has_key('URL'):
if other.has_key(key): return other[key] if key[:1]=='U' and URLmatch(key) >= 0 and other.has_key('URL'):
def __getitem__(self,key, URLmatch=regex.compile('URL[0-9]$').match, BASEmatch=regex.compile('BASE[0-9]$').match, ):
try: return self.environ[key] except: return ''
environ=self.environ if environ.has_key(key): return environ[key] return ''
def __getitem__(self,key, URLmatch=regex.compile('URL[0-9]$').match, BASEmatch=regex.compile('BASE[0-9]$').match, ):
if BASEmatch(key) >= 0 and other.has_key('URL'):
if key[:1]=='B' and BASEmatch(key) >= 0 and other.has_key('URL'):
def __getitem__(self,key, URLmatch=regex.compile('URL[0-9]$').match, BASEmatch=regex.compile('BASE[0-9]$').match, ):
__getattr__=__getitem__
__getattr__=get=__getitem__ def has_key(self,key): return self.get(key, field2tuple) is not field2tuple
def __getitem__(self,key, URLmatch=regex.compile('URL[0-9]$').match, BASEmatch=regex.compile('BASE[0-9]$').match, ):
if type(v)==types.TupleType and len(v)==3:
if type(v)==TupleType and len(v)==3:
def publish_module(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0): must_die=0 status=200 after_list=[None] try: response=Response(stdout=stdout, stderr=stderr) publisher = ModulePublisher(stdin=stdin, stdout=stdout, stderr=stderr, environ=environ) response = publisher.response response = publisher.publish(module_name,after_list,debug=debug) except SystemExit: must_die=1 response.exception(must_die) except ImportError, v: if type(v)==types.TupleType and len(v)==3: sys.exc_type, sys.exc_value, sys.exc_traceback = v must_die=1 response.exception(must_die) except: response.exception() status=response.getStatus() if response: response=str(response) if response: stdout.write(response) # The module defined a post-access function, call it if after_list[0] is not None: after_list[0]() if must_die: raise sys.exc_type, sys.exc_value, sys.exc_traceback sys.exc_type, sys.exc_value, sys.exc_traceback = None, None, None return status
self.sockname = os.path.join(config.clienthome, "zopectlsock")
self.sockname = os.path.join(self.clienthome, "zopectlsock")
def realize(self, *args, **kw): ZDOptions.realize(self, *args, **kw) config = self.configroot self.directory = config.instancehome self.program = [os.path.join(self.directory, "bin", "runzope")] self.sockname = os.path.join(config.clienthome, "zopectlsock") self.user = None self.python = sys.executable self.zdrun = os.path.join(os.path.dirname(zdaemon.__file__), "zdrun.py") self.exitcodes = [0, 2] if self.logfile is None and config.eventlog is not None: for handler in config.eventlog.handler_factories: if isinstance(handler, FileHandlerFactory): self.logfile = handler.section.path if self.logfile not in ("STDERR", "STDOUT"): break
flt_pattern =regex.compile('\([0-9]+\.[0-9]+\)')
flt_pattern =regex.compile(':\([0-9]+\.[0-9]+\)')
def __init__(self,*args): """Return a new date-time object
if fltpat.match(string,i) >= 0:
if i > 0: b=i-1 else: b=i if fltpat.match(string, b) >= 0:
def _parse(self,string): # Parse date-time components from a string month=year=tz=tm=None spaces =self.space_chars intpat =self.int_pattern fltpat =self.flt_pattern wordpat =self.name_pattern delimiters =self.delimiters MonthNumbers =self._monthmap DayOfWeekNames=self._daymap ValidZones =self._tzinfo._zidx TimeModifiers =['am','pm']
'operation' % absattr(object.id),
'operation.' % absattr(object.id),
def _verifyObjectPaste(self, object, validate_src=1): # Verify whether the current user is allowed to paste the # passed object into self. This is determined by checking # to see if the user could create a new object of the same # meta_type of the object passed in and checking that the # user actually is allowed to access the passed in object # in its existing context. # # Passing a false value for the validate_src argument will skip # checking the passed in object in its existing context. This is # mainly useful for situations where the passed in object has no # existing context, such as checking an object during an import # (the object will not yet have been connected to the acquisition # heirarchy). if not hasattr(object, 'meta_type'): raise CopyError, MessageDialog( title='Not Supported', message='The object <EM>%s</EM> does not support this ' \ 'operation' % absattr(object.id), action='manage_main') mt=object.meta_type if not hasattr(self, 'all_meta_types'): raise CopyError, MessageDialog( title='Not Supported', message='Cannot paste into this object.', action='manage_main')
class CopySource:
class CopySource(ExtensionClass.Base):
def _verifyObjectPaste(self, object, validate_src=1): # Verify whether the current user is allowed to paste the # passed object into self. This is determined by checking # to see if the user could create a new object of the same # meta_type of the object passed in and checking that the # user actually is allowed to access the passed in object # in its existing context. # # Passing a false value for the validate_src argument will skip # checking the passed in object in its existing context. This is # mainly useful for situations where the passed in object has no # existing context, such as checking an object during an import # (the object will not yet have been connected to the acquisition # heirarchy). if not hasattr(object, 'meta_type'): raise CopyError, MessageDialog( title='Not Supported', message='The object <EM>%s</EM> does not support this ' \ 'operation' % absattr(object.id), action='manage_main') mt=object.meta_type if not hasattr(self, 'all_meta_types'): raise CopyError, MessageDialog( title='Not Supported', message='Cannot paste into this object.', action='manage_main')
message='The item <EM>%s</EM> does not support this operation.',
message=( 'The action against the <em>%s</em> object could not be carried ' 'out. ' 'One of the following constraints caused the problem: <br><br>' 'The object does not support this operation.' '<br><br>-- OR --<br><br>' 'The currently logged-in user does not have the <b>Copy or ' 'Move</b> permission respective to the object.' ),
def cookie_path(request): # Return a "path" value for use in a cookie that refers # to the root of the Zope object space. return request['BASEPATH1'] or "/"
def field2date(v): from DateTime import DateTime if hasattr(v,'read'): v=v.read() else: v=str(v) return DateTime(v)
def field2date(v): from DateTime import DateTime if hasattr(v,'read'): v=v.read() else: v=str(v) return DateTime(v)
ListType=type([])
def field2boolean(v): return v
if type(v) is not ListType: v=(v,)
if type(v) is not TupleType: v=(v,)
def field2tuple(v): if type(v) is not ListType: v=(v,) return tuple(v)
content_type='application/octet-stream'
type='application/octet-stream'
def PUT(self, REQUEST, RESPONSE): """Create a new non-collection resource.""" self.dav__init(REQUEST, RESPONSE) type=REQUEST.get_header('content-type', None) body=REQUEST.get('BODY', '') name=self.__name__ if type is None: type, enc=mimetypes.guess_type(name) if type is None: if OFS.content_types.find_binary(body) >= 0: content_type='application/octet-stream' else: type=OFS.content_types.text_type(body) type=string.lower(type) from OFS.Image import Image, File if type in ('text/html', 'text/xml', 'text/plain'): self.__parent__.manage_addDTMLDocument(name, '', body) elif type[:6]=='image/': ob=Image(name, '', body, content_type=type) self.__parent__._setObject(name, ob) else: ob=File(name, '', body, content_type=type) self.__parent__._setObject(name, ob) RESPONSE.setStatus(201) RESPONSE.setBody('') return RESPONSE
self.namespaceDict = {}
self.namespaceDict = {"xml": XML_NS}
def __call__(self): self.namespaceDict = {} self.namespaceStack = [self.namespaceDict] DOMVisitor.__call__(self) assert not self.stack return self.program, self.macros
if item[0] == "rawtext":
opcode = item[0] if opcode == "rawtext":
def optimize(self, program): output = [] collect = [] rawseen = cursor = 0 if self.xml: endsep = "/>" else: endsep = " />" for cursor in xrange(len(program)+1): try: item = program[cursor] except IndexError: item = (None, None) if item[0] == "rawtext": collect.append(item[1]) continue if item[0] == "endTag": collect.append("</%s>" % item[1]) continue if item[0] == "startTag": if self.optimizeStartTag(collect, item[1], item[2], ">"): continue if item[0] == "startEndTag": if self.optimizeStartTag(collect, item[1], item[2], endsep): continue text = string.join(collect, "") if text: output.append(("rawtext", text)) if item[0] != None: output.append(item) rawseen = cursor+1 collect = [] return output
if item[0] == "endTag":
if opcode == "endTag":
def optimize(self, program): output = [] collect = [] rawseen = cursor = 0 if self.xml: endsep = "/>" else: endsep = " />" for cursor in xrange(len(program)+1): try: item = program[cursor] except IndexError: item = (None, None) if item[0] == "rawtext": collect.append(item[1]) continue if item[0] == "endTag": collect.append("</%s>" % item[1]) continue if item[0] == "startTag": if self.optimizeStartTag(collect, item[1], item[2], ">"): continue if item[0] == "startEndTag": if self.optimizeStartTag(collect, item[1], item[2], endsep): continue text = string.join(collect, "") if text: output.append(("rawtext", text)) if item[0] != None: output.append(item) rawseen = cursor+1 collect = [] return output
if item[0] == "startTag":
if opcode == "startTag":
def optimize(self, program): output = [] collect = [] rawseen = cursor = 0 if self.xml: endsep = "/>" else: endsep = " />" for cursor in xrange(len(program)+1): try: item = program[cursor] except IndexError: item = (None, None) if item[0] == "rawtext": collect.append(item[1]) continue if item[0] == "endTag": collect.append("</%s>" % item[1]) continue if item[0] == "startTag": if self.optimizeStartTag(collect, item[1], item[2], ">"): continue if item[0] == "startEndTag": if self.optimizeStartTag(collect, item[1], item[2], endsep): continue text = string.join(collect, "") if text: output.append(("rawtext", text)) if item[0] != None: output.append(item) rawseen = cursor+1 collect = [] return output
if item[0] == "startEndTag":
if opcode == "startEndTag":
def optimize(self, program): output = [] collect = [] rawseen = cursor = 0 if self.xml: endsep = "/>" else: endsep = " />" for cursor in xrange(len(program)+1): try: item = program[cursor] except IndexError: item = (None, None) if item[0] == "rawtext": collect.append(item[1]) continue if item[0] == "endTag": collect.append("</%s>" % item[1]) continue if item[0] == "startTag": if self.optimizeStartTag(collect, item[1], item[2], ">"): continue if item[0] == "startEndTag": if self.optimizeStartTag(collect, item[1], item[2], endsep): continue text = string.join(collect, "") if text: output.append(("rawtext", text)) if item[0] != None: output.append(item) rawseen = cursor+1 collect = [] return output
output.append(("rawtext", text)) if item[0] != None: output.append(item)
i = string.rfind(text, "\n") if i >= 0: i = len(text) - (i + 1) output.append(("rawtextColumn", (text, i))) else: output.append(("rawtextOffset", (text, len(text)))) if opcode != None: output.append((opcode, tuple(item[1:])))
def optimize(self, program): output = [] collect = [] rawseen = cursor = 0 if self.xml: endsep = "/>" else: endsep = " />" for cursor in xrange(len(program)+1): try: item = program[cursor] except IndexError: item = (None, None) if item[0] == "rawtext": collect.append(item[1]) continue if item[0] == "endTag": collect.append("</%s>" % item[1]) continue if item[0] == "startTag": if self.optimizeStartTag(collect, item[1], item[2], ">"): continue if item[0] == "startEndTag": if self.optimizeStartTag(collect, item[1], item[2], endsep): continue text = string.join(collect, "") if text: output.append(("rawtext", text)) if item[0] != None: output.append(item) rawseen = cursor+1 collect = [] return output
if container is None: container=accessed containerbase=accessedbase=accessed else: containerbase=getattr(container, 'aq_base', container) accessedbase=getattr(accessed, 'aq_base', container)
containerbase=getattr(container, 'aq_base', container) accessedbase=getattr(accessed, 'aq_base', container)
def validate(self, accessed, container, name, value, context, None=None, type=type, IntType=type(0), DictType=type({}), getattr=getattr, _noroles=_noroles, StringType=type(''), Containers=SimpleObjectPolicies.Containers, valid_aq_=('aq_parent','aq_explicit')):
if accessed is container:
if accessedbase is containerbase:
def validate(self, accessed, container, name, value, context, None=None, type=type, IntType=type(0), DictType=type({}), getattr=getattr, _noroles=_noroles, StringType=type(''), Containers=SimpleObjectPolicies.Containers, valid_aq_=('aq_parent','aq_explicit')):
ol=regex.compile('[ \t]*\(\([0-9]+\|[a-zA-Z]+\)\.\)+[ \t\n]+\([^\0]*\|$\)')
ol=regex.compile('[ \t]*\(\([0-9]+\|[a-zA-Z]+\)[.)]\)+[ \t\n]+\([^\0]*\|$\)')
def structure(list): if not list: return [] i=0 l=len(list) r=[] while i < l: sublen=paragraphs(list,i) i=i+1 r.append((list[i-1][1],structure(list[i:i+sublen]))) i=i+sublen return r
def __init__(self,aStructuredString, level=1):
def __init__(self,aStructuredString, level=0):
def __init__(self,aStructuredString, level=1):
s=regsub.gsub(extra_dl,'\n',s) s=regsub.gsub(extra_ul,'\n',s) s=regsub.gsub(extra_ol,'\n',s)
def ctag(s): if s is None: s='' s=regsub.gsub(extra_dl,'\n',s) s=regsub.gsub(extra_ul,'\n',s) s=regsub.gsub(extra_ol,'\n',s) s=regsub.gsub(strong,' <strong>\\1</strong>\\2',s) s=regsub.gsub(code,' <code>\\1</code>\\3',s) s=regsub.gsub(em,' <em>\\1</em>\\2',s) return s
return self._str(self.structure,self.level)
s=self._str(self.structure,self.level) s=regsub.gsub(extra_dl,'\n',s) s=regsub.gsub(extra_ul,'\n',s) s=regsub.gsub(extra_ol,'\n',s) return s
def __str__(self):
if level > 0 and level < 6: return ('%s<h%d>%s</h%d>\n%s\n' % (before,level,ctag(t),level,d))
def head(self, before, t, level, d):
r=self.ul(r,p,self._str(s[1],level))
r=self.ol(r,p,self._str(s[1],level))
def _str(self,structure,level):
r=self.head(r,t,level,self._str(s[1],level+1))
r=self.head(r,t,level, self._str(s[1],level and level+1))
def _str(self,structure,level):
'[\0\n].. \[\([0-9_a-zA-Z]+\)\]',
'[\0\n].. \[\([-_0-9_a-zA-Z]+\)\]',
def html_with_references(text): import regsub text = regsub.gsub( '[\0\n].. \[\([0-9_a-zA-Z]+\)\]', '\n <a name="\\1">[\\1]</a>', text) text = regsub.gsub( '\([\0- ,]\)\[\([0-9_a-zA-Z]+\)\]\([\0- ,.:]\)', '\\1<a href="#\\2">[\\2]</a>\\3', text) text = regsub.gsub( '\([\0- ]\)\([a-z]+://[^\0- ]+\)', '\\1<a href="\\2">\\2</a>', text) return HTML(text)
return HTML(text)
return HTML(text,level=1)
def html_with_references(text): import regsub text = regsub.gsub( '[\0\n].. \[\([0-9_a-zA-Z]+\)\]', '\n <a name="\\1">[\\1]</a>', text) text = regsub.gsub( '\([\0- ,]\)\[\([0-9_a-zA-Z]+\)\]\([\0- ,.:]\)', '\\1<a href="#\\2">[\\2]</a>\\3', text) text = regsub.gsub( '\([\0- ]\)\([a-z]+://[^\0- ]+\)', '\\1<a href="\\2">\\2</a>', text) return HTML(text)
else: raise HTMLParserError('neither < nor & ??', self.getpos())
def goahead(self, end): rawdata = self.rawdata i = 0 n = len(rawdata) while i < n: if self.nomoretags: self.handle_data(rawdata[i:n]) i = self.updatepos(i, n) break match = interesting.search(rawdata, i) if match: j = match.start(0) else: j = n if i < j: self.handle_data(rawdata[i:j]) i = self.updatepos(i, j) if i == n: break if rawdata[i] == '<': if starttagopen.match(rawdata, i): if self.literal: self.handle_data(rawdata[i]) i = self.updatepos(i, i+1) continue k = self.parse_starttag(i) if k < 0: break i = self.updatepos(i, k) continue if endtagopen.match(rawdata, i): k = self.parse_endtag(i) if k < 0: break i = self.updatepos(i, k) self.literal = 0 continue if commentopen.match(rawdata, i): if self.literal: self.handle_data(rawdata[i]) i = self.updatepos(i, i+1) continue k = self.parse_comment(i) if k < 0: break i = self.updatepos(i, i+k) continue if piopen.match(rawdata, i): if self.literal: self.handle_data(rawdata[i]) i = self.updatepos(i, i+1) continue k = self.parse_pi(i) if k < 0: break i = self.updatepos(i, i+k) continue match = special.match(rawdata, i) if match: if self.literal: self.handle_data(rawdata[i]) i = self.updatepos(i, i+1) continue # This is some sort of declaration; in "HTML as # deployed," this should only be the document type # declaration ("<!DOCTYPE html...>"). k = self.parse_declaration(i) if k < 0: break i = self.updatepos(i, k) continue elif rawdata[i] == '&': match = charref.match(rawdata, i) if match: name = match.group(1) self.handle_charref(name) k = match.end(0) if rawdata[k-1] != ';': k = k-1 i = self.updatepos(i, k) continue match = entityref.match(rawdata, i) if match: name = match.group(1) self.handle_entityref(name) k = match.end(0) if rawdata[k-1] != ';': k = k-1 i = self.updatepos(i, k) continue else: raise HTMLParserError('neither < nor & ??', self.getpos()) # We get here only if incomplete matches but # nothing else match = incomplete.match(rawdata, i) if not match: self.handle_data(rawdata[i]) i = self.updatepos(i, i+1) continue j = match.end(0) if j == n: break # Really incomplete self.handle_data(rawdata[i:j]) i = self.updatepos(i, j) # end while if end and i < n: self.handle_data(rawdata[i:n]) i = self.updatepos(i, n) self.rawdata = rawdata[i:] # XXX if end: check for empty stack
if rawdata[i:i+4] != '<!--': raise HTMLParseError('unexpected call to parse_comment()', self.getpos())
assert rawdata[i:i+4] == '<!--', 'unexpected call to parse_comment()'
def parse_comment(self, i): rawdata = self.rawdata if rawdata[i:i+4] != '<!--': raise HTMLParseError('unexpected call to parse_comment()', self.getpos()) match = commentclose.search(rawdata, i+4) if not match: return -1 j = match.start(0) self.handle_comment(rawdata[i+4: j]) j = match.end(0) return j-i
if rawdata[i:i+2] != '<?': raise HTMLParseError('unexpected call to parse_pi()', self.getpos())
assert rawdata[i:i+2] == '<?', 'unexpected call to parse_pi()'
def parse_pi(self, i): rawdata = self.rawdata if rawdata[i:i+2] != '<?': raise HTMLParseError('unexpected call to parse_pi()', self.getpos()) match = piclose.search(rawdata, i+2) if not match: return -1 j = match.start(0) self.handle_pi(rawdata[i+2: j]) j = match.end(0) return j-i
if not match: raise HTMLParseError('unexpected call to parse_starttag()', self.getpos())
assert match, 'unexpected call to parse_starttag()'
def parse_starttag(self, i): self.__starttag_text = None rawdata = self.rawdata m = locatestarttagend.match(rawdata, i) if not m: return -1 endpos = m.end(0) self.__starttag_text = rawdata[i:endpos]
"""Create a tuple consisting of a single instance whos attributes are
"""Create a tuple consisting of a single instance whose attributes are
def namespace(self, **kw): """Create a tuple consisting of a single instance whos attributes are provided as keyword arguments.""" # NOTE: the self argument needs to be a TemplateDict instance. return apply(self, (), kw)