Skip to content

Commit

Permalink
Reorder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv-ru committed Feb 23, 2013
1 parent fe945a4 commit ce8b590
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions datashield2keepass.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ def ParseNote(note_soup):
result = {'note': note}
return result

def ParseValues(values):
""" Parse Values"""
#print "Values ", values
if len(values):
return dict(map(lambda x: (unescape(x['id']),unescape(x.string)),
values[0].findAll('value'))
)
else:
return {}

def ParseRecords(records_soup):
"""Parse records
return: (records, statistic)
Expand Down Expand Up @@ -143,16 +153,6 @@ def dict_merge(*args):
for d in args: result.update(d)
return result

def ParseValues(values):
""" Parse Values"""
#print "Values ", values
if len(values):
return dict(map(lambda x: (unescape(x['id']),unescape(x.string)),
values[0].findAll('value'))
)
else:
return {}

def openfile(Filename):
"""Open file as BeautifulStoneSoup"""
# with open(Filename) as file: #not supported in python before 2.6
Expand All @@ -172,6 +172,8 @@ def unescape(str):
"""
return unicode(urllib.unquote(str.strip().encode(charset)), charset)

# Conversion formats

def importformats(filename):
"""
formats = {'template': {'t_name': 'template name (for reference)',
Expand Down Expand Up @@ -235,6 +237,15 @@ def AllFieldsInFormat(fields, templates):
format += '%s: %%(%s)s\n' % (fields[k]['FieldName'], k)
return format

def add_default(record, templates):
""" Add to record all fields presented in template
"""
for key in templates[record['template']]['fields'].keys():
record.setdefault(key, '')


# CSV output

class UnicodeWriter:
"""
A CSV writer which will write rows to CSV file "f",
Expand Down Expand Up @@ -276,12 +287,6 @@ class KeepassDialect(csv.Dialect):
quoting = csv.QUOTE_ALL
escapechar = '\\'

def add_default(record, templates):
""" Add to record all fields presented in template
"""
for key in templates[record['template']]['fields'].keys():
record.setdefault(key, '')

def outputCSV(File, records, templates, formats):
"""Output in Keepass CSV
"""
Expand All @@ -295,11 +300,6 @@ def outputCSV(File, records, templates, formats):
try:
writer.writerow(map(lambda x: Keepass1CSVEscape(format[x] % record),
['1_Account', '2_Login Name', '3_Password', '4_Web Site', '5_Comments']))
# (Keepass1CSVEscape(format['1_Account'] % record) ,
# Keepass1CSVEscape(format['2_Login Name'] % record) ,
# Keepass1CSVEscape(format['3_Password'] % record) ,
# Keepass1CSVEscape(format['4_Web Site'] % record) ,
# Keepass1CSVEscape(format['5_Comments'] % record)))
except:
# except KeyError:
print("\nError in converting record:")
Expand Down

0 comments on commit ce8b590

Please sign in to comment.