.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.webutils.CSVWriter Class Reference

Public Member Functions

 __init__ (self, f, dialect=csv.excel, encoding="utf-8", **kwds)
 
 writerow (self, row)
 
 writerows (self, rows)
 

Public Attributes

 queue = StringIO()
 
 writer = csv.writer(self.queue, dialect=dialect, **kwds)
 
 stream = f
 
 encoder = getincrementalencoder(encoding)()
 

Detailed Description

A CSV writer which will write rows to CSV file "f", which is encoded in
the given encoding.

Definition at line 84 of file webutils.py.

Constructor & Destructor Documentation

◆ __init__()

searx.webutils.CSVWriter.__init__ ( self,
f,
dialect = csv.excel,
encoding = "utf-8",
** kwds )

Definition at line 88 of file webutils.py.

88 def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
89 # Redirect output to a queue
90 self.queue = StringIO()
91 self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
92 self.stream = f
93 self.encoder = getincrementalencoder(encoding)()
94

Member Function Documentation

◆ writerow()

searx.webutils.CSVWriter.writerow ( self,
row )

Definition at line 95 of file webutils.py.

95 def writerow(self, row):
96 self.writer.writerow(row)
97 # Fetch UTF-8 output from the queue ...
98 data = self.queue.getvalue()
99 data = data.strip('\x00')
100 # ... and re-encode it into the target encoding
101 data = self.encoder.encode(data)
102 # write to the target stream
103 self.stream.write(data.decode())
104 # empty queue
105 self.queue.truncate(0)
106

References encoder, queue, stream, writer, and writerow().

Referenced by writerow(), and writerows().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ writerows()

searx.webutils.CSVWriter.writerows ( self,
rows )

Definition at line 107 of file webutils.py.

107 def writerows(self, rows):
108 for row in rows:
109 self.writerow(row)
110
111

References writerow().

+ Here is the call graph for this function:

Member Data Documentation

◆ encoder

searx.webutils.CSVWriter.encoder = getincrementalencoder(encoding)()

Definition at line 93 of file webutils.py.

Referenced by writerow().

◆ queue

searx.webutils.CSVWriter.queue = StringIO()

Definition at line 90 of file webutils.py.

Referenced by writerow().

◆ stream

searx.webutils.CSVWriter.stream = f

Definition at line 92 of file webutils.py.

Referenced by writerow().

◆ writer

searx.webutils.CSVWriter.writer = csv.writer(self.queue, dialect=dialect, **kwds)

Definition at line 91 of file webutils.py.

Referenced by writerow().


The documentation for this class was generated from the following file: