Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: /leo/plugins/

leo
Discussion topic

Back to topic list

CVS update: /leo/plugins/

Author terry_n_brown
Full name Terry Brown
Date 2006-10-04 10:12:52 PDT
Message User: terry_n_brown
Date: 2006-10-04 10:12:52-0700
Modified:
   leo/plugins/leoOPML.py
   leo/plugins/leoOPML.leo

Log:
 Submitted by: Terry Brown
 
 Added unknownAttribute export, leo: instead of : for namespace
 Fixed SAX content read as directed by EKR

File Changes:

Directory: /leo/plugins/
========================

File [changed]: leoOPML.py
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/leoOPML.py?r​1=1.22&r2=1.23
Delta lines: +66 -37
---------------------
--- leoOPML.py 2006-09-22 09:14:12-0700 1.22
+++ leoOPML.py 2006-10-04 10:12:49-0700 1.23
@@ -23,8 +23,8 @@
 
 - @bool opml_use_outline_elements = True
 
-- If True, Leo writes body text to <:body> elements nested in <outline> elements.
-Otherwise, Leo writes body text to :body attributes of <outline> elements.
+- If True, Leo writes body text to <leo:body> elements nested in <outline> elements.
+Otherwise, Leo writes body text to leo:body attributes of <outline> elements.
 
 - @string opml_version = 2.0
 
@@ -45,6 +45,21 @@
 
 If True, Leo writes body_outline_ratio` and global_window_position attributes to
 the <head> element of the .opml file.
+
+- @bool opml_write_ua_attributes
+
+If True, write unknownAttributes **NOTE** ua_attributes are not currently read from opml
+
+- @bool opml_expand_ua_dictionary
+
+If True, expand an unknownAttriubte 'x' of type dict to 'ua_x_key0', 'ua_x_key1' etc.
+**WARNING** using this feature may prevent reading these ua_attributes from opml,
+if that feature is implemented in the future.
+
+- @bool opml_skip_ua_dictionary_blanks
+
+If True, when expanding as above, skip blank dict entries.
+
 '''
 #@nonl
 #@-node:ekr.20060904​103412.1:<< docstring >>
@@ -121,11 +136,12 @@
 # - create c.fileCommands.tnodeDict before calling c.atFileCommands.readAll.
 # - Properly init t.fileIndex to an actual gnx using scanGnx.
 # 0.92 EKR: Support for opml_write_leo_globa​ls_attributes setting:
-# - Read and write :body_outline_ratio attribute and <:global_window_position>
-# element.
+# - Read and write leo:body_outline_ratio attribute and
+# <leo:global_windo​w_position> element.
 # 0.93 EKR: Support opml_read_derived_files & opml_write_derived_files
+# 0.94 TNB: write unknownAttributes, use leo: rather than just : for
+# namespace, tweaked SAX content reading
 #@-at
-#@nonl
 #@-node:ekr.20060904​103412.2:<< version history >>
 #@nl
 #@<< imports >>
@@ -182,7 +198,7 @@
     
     #@ @+others
     #@+node:ekr.20060919​172012.2:putToOPML & helpers
- # All elements and attributes prefixed by ':' are leo-specific.
+ # All elements and attributes prefixed by 'leo:' are leo-specific.
     # All other elements and attributes are specified by the OPML 1 spec.
     
     def putToOPML (self):
@@ -195,6 +211,9 @@
             'opml_write_leo_details',
             'opml_write_leo_glob​als_attributes',
             'opml_write_body_text',
+ 'opml_write_ua_attributes',
+ 'opml_expand_ua_dictionary',
+ 'opml_skip_ua_dictio​nary_blanks',
         ):
             setattr(self,ivar,c.​config.getBool(ivar)​)
         
@@ -210,7 +229,7 @@
         s = self.c.config.getStr​ing('opml_namespace'​) or 'leo:com:leo-opml'
         ver = self.c.config.getStr​ing('opml_version') or '2.0'
     
- self.put('<opml version="%s" xmlns="%s">' % (ver,s))
+ self.put('<opml version="%s" xmlns:leo="%s">' % (ver,s))
     #@-node:ekr.20060919​172012.3:putOPMLProl​og
     #@+node:ekr.20060919​172012.4:putOPMLHead​er
     def putOPMLHeader (self):
@@ -220,11 +239,11 @@
         c = self.c ; indent = ' ' * 4
     
         if self.opml_write_leo_​globals_attributes:
- self.put('\n<head :body_outline_ratio="%s">' % str(c.frame.ratio))
+ self.put('\n<head leo:body_outline_rat​io="%s">' % str(c.frame.ratio))
             
             width,height,left,top = c.frame.get_window_info()
     
- self.put('\n%s<:​global_window_positi​on' % indent)
+ self.put('\n%s<l​eo:global_window_pos​ition' % indent)
             self.put(' top="%s" left="%s" height="%s" width="%s"/>' % (
                 str(top),str(left),s​tr(height),str(width​)))
     
@@ -260,15 +279,15 @@
     
         if self.opml_write_leo_details: # Put leo-specific attributes.
             for name,val in (
- (':t', g.app.nodeIndices.to​String(p.v.t.fileInd​ex)),
- (':a', self.aAttributes(p)),
- (':tnodeList',self.t​nodeListAttributes(p​)),
+ ('leo:t', g.app.nodeIndices.to​String(p.v.t.fileInd​ex)),
+ ('leo:a', self.aAttributes(p)),
+ ('leo:tnodeList',sel​f.tnodeListAttribute​s(p)),
             ):
                 if val: self.put(attrFormat % (name,val))
             
             data = self.uAAttributes(p)
             if data:
- for name,val in data:
+ for name,val in data.iteritems():
                     self.put(attrFormat % (name,val))
         
         self.put(attrFormat % ('text',self.attribu​teEscape(head)))
@@ -277,9 +296,9 @@
         if body and self.opml_write_body_text:
             if self.opml_use_outline_elements:
                 self.put('>') ; closed = True
- self.put('<:body​>%s</:body>'​ % self.xmlEscape(body))
+ self.put('<leo:bo​dy>%s</leo:bod​y>' % self.xmlEscape(body))
             else:
- self.put(attrFormat % (':body',self.attrib​uteEscape(body)))
+ self.put(attrFormat % ('leo:body',self.att​ributeEscape(body)))​
     
         if p.hasChildren():
             if not closed:
@@ -349,12 +368,21 @@
         return s
     #@nonl
     #@-node:ekr.20060919​172012.9:tnodeListAt​tributes
- #@+node:ekr.20060919​172012.10:uAAttribut​es (Not yet, and maybe never)
- def uAAttributes (self,p):
-
- return ''
+ #@+node:tbrown.20061​004094757:uAAttribut​es
+ def uAAttributes(self, p):
+ """write unknownAttributes with various levels of expansion"""
+ data = {}
+ if self.opml_write_ua_attributes and hasattr(p.v, 'unknownAttributes'):
+ for uak, uav in p.v.unknownAttribute​s.iteritems():
+ if self.opml_expand_ua_dictionary and type(uav) == type({}):
+ for uakc, uavc in uav.iteritems():
+ if str(uavc)!='' or not self.opml_skip_ua_di​ctionary_blanks:
+ data['leo:ua_'+uak+'_'+uakc] = self.attributeEscape(str(uavc))
+ else:
+ data['leo:ua_'+uak] = self.attributeEscape(str(uav))
+ return data
     #@nonl
- #@-node:ekr.20060919​172012.10:uAAttribut​es (Not yet, and maybe never)
+ #@-node:tbrown.20061​004094757:uAAttribut​es
     #@-node:ekr.20060919​172012.6:putOPMLNode​
     #@+node:ekr.20060919​172012.11:putOPMLPos​tlog
     def putOPMLPostlog (self):
@@ -470,7 +498,7 @@
     #@+node:ekr.20060917​213611:handleVnodeAt​tributes
     def handleVnodeAttributes (self,node,v):
     
- a = node.attributes.get(':a')
+ a = node.attributes.get('leo:a')
         if a:
             # 'C' (clone) and 'D' bits are not used.
             if 'M' in a: v.setMarked()
@@ -479,7 +507,7 @@
             if 'T' in a: self.topVnode = v
             if 'V' in a: self.currentVnode = v
             
- s = node.attributes.get(​':tnodeList')
+ s = node.attributes.get(​'leo:tnodeList')
         tnodeList = s and s.split(',')
         if tnodeList:
             # This tnode list will be resolved later.
@@ -767,8 +795,8 @@
             'head': (self.startHead,None),
             'opml': (None,None),
             'outline': (self.startOutline,s​elf.endOutline),
- ':body': (self.startBodyText,​self.endBodyText),
- ':global_window_position': (self.startWinPos,None)
+ 'leo:body': (self.startBodyText,​self.endBodyText),
+ 'leo:global_window_position': (self.startWinPos,None)
         }
         #@nonl
         #@-node:ekr.20060917​185525:<< define dispatch dict >>
@@ -895,13 +923,14 @@
         
         # Opml elements should not have content: everything is carried in attributes.
         
- if content.strip():
- if name == ':body':
+ # if content.strip():
+ if name == 'leo:body':
                 if self.node:
- self.node.bodyString = content
+ self.content.append(content)
                 else:
- self.error('No node for :body content')
+ self.error('No node for leo:body content')
             else:
+ if content.strip():
                 print 'content:',name,repr(content)
     #@nonl
     #@-node:ekr.20060904​134958.178:character​s
@@ -928,7 +957,7 @@
     #@+node:ekr.20060919​193501:endBodyText
     def endBodyText (self):
         
- '''End a <:body> element.'''
+ '''End a <leo:body> element.'''
         
         if self.content:
             self.node.bodyString = ''.join(self.content)
@@ -965,7 +994,7 @@
     #@+node:ekr.20060919​193501.1:startBodyTe​xt
     def startBodyText (self,attrs):
         
- '''Start a <:body> element.'''
+ '''Start a <leo:body> element.'''
         
         self.content = []
     #@nonl
@@ -985,7 +1014,7 @@
         
         for bunch in self.attrsToList(attrs):
             name = bunch.name ; val = bunch.val
- if name == ':body_outline_ratio':
+ if name == 'leo:body_outline_ratio':
                 try:
                     ratio = float(val)
                     # g.trace(ratio)
@@ -1025,11 +1054,11 @@
     
             if name == 'text': # Text is the 'official' opml attribute for headlines.
                 node.headString = val
- elif name == ':body':
+ elif name == 'leo:body':
                 #g.trace(repr(val))
                 #g.es_dump (val[:30])
                 node.bodyString = val
- elif name == ':t':
+ elif name == 'leo:t':
                 node.tnx = val
             else:
                 node.attributes[name] = val
@@ -1040,7 +1069,7 @@
     def startWinPos (self,attrs):
         
         if not self.inElement('head'):
- self.error('<:glo​bal_window_position​> outside <body>')
+ self.error('<leo:​global_window_positi​on> outside <body>')
     
         self.doGlobalWindowA​ttributes(attrs)
     #@+node:ekr.20060922​071010.1:doGlobalWin​dowAttributes

File [changed]: leoOPML.leo
Url: http://leo.tigris.or​g/source/browse/leo/​plugins/leoOPML.leo?​r1=1.22&r2=1.23
Delta lines: +3 -2
-------------------
--- leoOPML.leo 2006-09-22 09:14:11-0700 1.22
+++ leoOPML.leo 2006-10-04 10:12:49-0700 1.23
@@ -3,13 +3,14 @@
 <leo_file>
 <leo_header file_format="2" tnodes="0" max_tnode_index="620" clone_windows="0"/>
 <globals body_outline_ratio="0.5">
- <global_window_position top="77" left="308" height="797" width="857"/>
+ <global_window_position top="10" left="68" height="840" width="1202"/>
     <global_log_window_position top="0" left="0" height="0" width="0"/>
 </globals>
 <preferences/>
 <find_panel_settings/>
 <vnodes>
-<v t="ekr.20060904103412" a="E"><vh>@thin leoOPML.py</vh></v>
+<v t="ekr.20060904103412" a="E"
+expanded="ekr.20060​904134958.164,ekr.20​060904134958.179,ekr​.20060904134958.180,​ekr.20060917190349,"​><vh>@thin leoOPML.py</vh></v>
 </vnodes>
 <tnodes>
 </tnodes>

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: /leo/plugins/ terry_n_brown Terry Brown 2006-10-04 10:12:52 PDT
Messages per page: