[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Updated some of Damian's suggested revisions. Not sure of others.



commit 305f7fdb30f420a751f2de29f250170c19569bb6
Author: Erik <eislo@xxxxxxxxxxxx>
Date:   Thu Jul 12 15:24:50 2012 -0400

    Updated some of Damian's suggested revisions.  Not sure of others.
---
 stem/descriptor/export.py |   36 ++++++++++++++++++------------------
 1 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/stem/descriptor/export.py b/stem/descriptor/export.py
index 2859fee..c847b81 100644
--- a/stem/descriptor/export.py
+++ b/stem/descriptor/export.py
@@ -1,19 +1,19 @@
 import os, csv, sets, cStringIO
 
 
-def descriptor_csv_exp(descr, incl_fields=[], excl_fields=[]):
+def get_csv_line(descriptor, include_fields=[], exclude_fields=[]):
   """
   Takes a single descriptor object, puts it in a list, and passes it to
   descriptors_csv_exp to build a csv.
 
   :param object descr: single descriptor object to export as csv.
   """
-  descriptor = [descr]
-  for desc in descriptors_csv_exp(descriptor, incl_fields, excl_fields):
+  descr = [descriptor]
+  for desc in get_csv_lines(descr, include_fields, exclude_fields):
     return desc
 
 
-def descriptors_csv_exp(descrs, incl_fields=[], excl_fields=[], head=False):
+def get_csv_lines(descriptors, include_fields=[], exclude_fields=[], head=False):
   """
   Builds a csv file based on attributes of descriptors.
 
@@ -25,12 +25,12 @@ def descriptors_csv_exp(descrs, incl_fields=[], excl_fields=[], head=False):
 
   :returns: generator for csv strings, one line per descr object.
   """
-  
+
   _temp_file = cStringIO.StringIO()
 
   first = True
 
-  for desc in descrs:
+  for desc in descriptors:
     attr = vars(desc)
 
     # Defining incl_fields and the dwriter object requires having access
@@ -38,18 +38,18 @@ def descriptors_csv_exp(descrs, incl_fields=[], excl_fields=[], head=False):
     if first:
       # define incl_fields, 4 cases where final case is incl_fields already
       # defined and excl_fields left blank, so no action is necessary.
-      if not incl_fields and excl_fields:
+      if not include_fields and exclude_fields:
         _incl = sets.Set(attr.keys())
-        incl_fields = list(_incl.difference(excl_fields))
+        include_fields = list(_incl.difference(exclude_fields))
 
-      elif not incl_fields and not excl_fields:
-        incl_fields = attr.keys()
+      elif not include_fields and not exclude_fields:
+        include_fields = attr.keys()
 
-      elif incl_fields and excl_fields:
-        _incl = sets.Set(incl_fields)
-        incl_fields = list(_incl.difference(excl_fields))
+      elif include_fields and exclude_fields:
+        _incl = sets.Set(include_fields)
+        include_fields = list(_incl.difference(exclude_fields))
 
-      dwriter = csv.DictWriter(_temp_file, incl_fields)
+      dwriter = csv.DictWriter(_temp_file, include_fields)
       first = False
 
       if head:
@@ -58,7 +58,7 @@ def descriptors_csv_exp(descrs, incl_fields=[], excl_fields=[], head=False):
     # Need to remove fields that aren't wanted for dwriter.
     final = {}
     for at in attr:
-      if at in incl_fields:
+      if at in include_fields:
         final[at] = attr[at]
 
     dwriter.writerow(final)
@@ -71,7 +71,7 @@ def descriptors_csv_exp(descrs, incl_fields=[], excl_fields=[], head=False):
       
   _temp_file.close()
 
-def csv_file_exp(descrs, doc_loc, header=True, incl_f=[], excl_f=[]):
+def csv_file_exp(descriptors, document_location, header=True, include_fields=[], exclude_fields=[]):
   """
   Writes descriptor attributes to a csv file on disk.
 
@@ -82,8 +82,8 @@ def csv_file_exp(descrs, doc_loc, header=True, incl_f=[], excl_f=[]):
   :param list incl_f: list of attribute fields to include in the csv line.
   :param list excl_f: list of attribute fields to exclude from csv line.
   """
-  doc = open(doc_loc, 'w')
+  doc = open(document_location, 'w')
 
-  for line in descriptors_csv_exp(descrs, incl_fields=incl_f, excl_fields=excl_f, head=header):
+  for line in get_csv_lines(descriptors, include_fields=include_fields, exclude_fields=exclude_fields, head=header):
     doc.write(line)
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits