/
usr
/
lib
/
python2.6
/
site-packages
/
tablib
/
packages
/
odf3
/
/usr/lib/python2.6/site-packages/tablib/packages/odf3
mkdir
upload
Name
Size
Mode
Actions
anim.py
1872
0644
edit
dl
rm
anim.pyc
2724
0644
edit
dl
rm
attrconverters.py
68210
0644
edit
dl
rm
attrconverters.pyc
57355
0644
edit
dl
rm
chart.py
2636
0644
edit
dl
rm
chart.pyc
4624
0644
edit
dl
rm
config.py
1420
0644
edit
dl
rm
config.pyc
1391
0644
edit
dl
rm
dc.py
2225
0644
edit
dl
rm
dc.pyc
1464
0644
edit
dl
rm
dr3d.py
1448
0644
edit
dl
rm
dr3d.pyc
1524
0644
edit
dl
rm
draw.py
5590
0644
edit
dl
rm
draw.pyc
10343
0644
edit
dl
rm
easyliststyle.py
3773
0644
edit
dl
rm
easyliststyle.pyc
2312
0644
edit
dl
rm
element.py
20473
0755
edit
dl
rm
element.pyc
22250
0644
edit
dl
rm
elementtypes.py
9933
0755
edit
dl
rm
elementtypes.pyc
8729
0644
edit
dl
rm
form.py
3270
0644
edit
dl
rm
form.pyc
6390
0644
edit
dl
rm
grammar.py
193388
0644
edit
dl
rm
grammar.pyc
106458
0644
edit
dl
rm
load.py
3963
0755
edit
dl
rm
load.pyc
3409
0644
edit
dl
rm
manifest.py
1389
0755
edit
dl
rm
manifest.pyc
1344
0644
edit
dl
rm
math.py
1068
0644
edit
dl
rm
math.pyc
459
0644
edit
dl
rm
meta.py
2138
0644
edit
dl
rm
meta.pyc
3243
0644
edit
dl
rm
namespaces.py
3943
0644
edit
dl
rm
namespaces.pyc
3314
0644
edit
dl
rm
number.py
3137
0644
edit
dl
rm
number.pyc
5743
0644
edit
dl
rm
odf2moinmoin.py
18192
0644
edit
dl
rm
odf2moinmoin.pyc
18774
0644
edit
dl
rm
odf2xhtml.py
65058
0755
edit
dl
rm
odf2xhtml.pyc
64620
0644
edit
dl
rm
odfmanifest.py
3570
0755
edit
dl
rm
odfmanifest.pyc
4072
0644
edit
dl
rm
office.py
3346
0644
edit
dl
rm
office.pyc
5895
0644
edit
dl
rm
opendocument.py
25907
0644
edit
dl
rm
opendocument.pyc
25530
0644
edit
dl
rm
presentation.py
2716
0644
edit
dl
rm
presentation.pyc
4555
0644
edit
dl
rm
script.py
1106
0644
edit
dl
rm
script.pyc
484
0644
edit
dl
rm
style.py
4672
0644
edit
dl
rm
style.pyc
9062
0644
edit
dl
rm
svg.py
1790
0644
edit
dl
rm
svg.pyc
2406
0644
edit
dl
rm
table.py
9408
0644
edit
dl
rm
table.pyc
20593
0644
edit
dl
rm
teletype.py
5181
0644
edit
dl
rm
teletype.pyc
4460
0644
edit
dl
rm
text.py
17215
0644
edit
dl
rm
text.pyc
39126
0644
edit
dl
rm
thumbnail.py
31736
0755
edit
dl
rm
thumbnail.pyc
31864
0644
edit
dl
rm
userfield.py
5394
0755
edit
dl
rm
userfield.pyc
5159
0644
edit
dl
rm
xforms.py
1233
0644
edit
dl
rm
xforms.pyc
873
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
__init__.pyc
148
0644
edit
dl
rm
Edit:
/usr/lib/python2.6/site-packages/tablib/packages/odf3/userfield.py
(5394B)
#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (C) 2006-2009 Søren Roug, European Environment Agency # # This is free software. You may redistribute it under the terms # of the Apache license and the GNU General Public License Version # 2 or at your option any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # Contributor(s): Michael Howitz, gocept gmbh & co. kg # # $Id: userfield.py 447 2008-07-10 20:01:30Z roug $ """Class to show and manipulate user fields in odf documents.""" import sys import zipfile from odf.text import UserFieldDecl from odf.namespaces import OFFICENS from odf.opendocument import load OUTENCODING = "utf-8" # OpenDocument v.1.0 section 6.7.1 VALUE_TYPES = { 'float': (OFFICENS, 'value'), 'percentage': (OFFICENS, 'value'), 'currency': (OFFICENS, 'value'), 'date': (OFFICENS, 'date-value'), 'time': (OFFICENS, 'time-value'), 'boolean': (OFFICENS, 'boolean-value'), 'string': (OFFICENS, 'string-value'), } class UserFields(object): """List, view and manipulate user fields.""" # these attributes can be a filename or a file like object src_file = None dest_file = None def __init__(self, src=None, dest=None): """Constructor src ... source document name, file like object or None for stdin dest ... destination document name, file like object or None for stdout """ self.src_file = src self.dest_file = dest self.document = None def loaddoc(self): if isinstance(self.src_file, str): # src_file is a filename, check if it is a zip-file if not zipfile.is_zipfile(self.src_file): raise TypeError("%s is no odt file." % self.src_file) elif self.src_file is None: # use stdin if no file given self.src_file = sys.stdin self.document = load(self.src_file) def savedoc(self): # write output if self.dest_file is None: # use stdout if no filename given self.document.save('-') else: self.document.save(self.dest_file) def list_fields(self): """List (extract) all known user-fields. Returns list of user-field names. """ return [x[0] for x in self.list_fields_and_values()] def list_fields_and_values(self, field_names=None): """List (extract) user-fields with type and value. field_names ... list of field names to show or None for all. Returns list of tuples (<field name>, <field type>, <value>). """ self.loaddoc() found_fields = [] all_fields = self.document.getElementsByType(UserFieldDecl) for f in all_fields: value_type = f.getAttribute('valuetype') if value_type == 'string': value = f.getAttribute('stringvalue') else: value = f.getAttribute('value') field_name = f.getAttribute('name') if field_names is None or field_name in field_names: found_fields.append((field_name.encode(OUTENCODING), value_type.encode(OUTENCODING), value.encode(OUTENCODING))) return found_fields def list_values(self, field_names): """Extract the contents of given field names from the file. field_names ... list of field names Returns list of field values. """ return [x[2] for x in self.list_fields_and_values(field_names)] def get(self, field_name): """Extract the contents of this field from the file. Returns field value or None if field does not exist. """ values = self.list_values([field_name]) if not values: return None return values[0] def get_type_and_value(self, field_name): """Extract the type and contents of this field from the file. Returns tuple (<type>, <field-value>) or None if field does not exist. """ fields = self.list_fields_and_values([field_name]) if not fields: return None field_name, value_type, value = fields[0] return value_type, value def update(self, data): """Set the value of user fields. The field types will be the same. data ... dict, with field name as key, field value as value Returns None """ self.loaddoc() all_fields = self.document.getElementsByType(UserFieldDecl) for f in all_fields: field_name = f.getAttribute('name') if field_name in data: value_type = f.getAttribute('valuetype') value = data.get(field_name) if value_type == 'string': f.setAttribute('stringvalue', value) else: f.setAttribute('value', value) self.savedoc()
Save
cmd:
run