.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 85 of file webutils.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 89 of file webutils.py.

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

Member Function Documentation

◆ writerow()

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

Definition at line 96 of file webutils.py.

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

References searx.webutils.CSVWriter.encoder, searx.webutils.CSVWriter.queue, searx.network.network.Network.stream(), searx.webutils.CSVWriter.stream, searx.webutils.CSVWriter.writer, and searx.webutils.CSVWriter.writerow().

Referenced by searx.webutils.CSVWriter.writerow(), and searx.webutils.CSVWriter.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 108 of file webutils.py.

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

References searx.webutils.CSVWriter.writerow().

+ Here is the call graph for this function:

Member Data Documentation

◆ encoder

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

Definition at line 94 of file webutils.py.

Referenced by searx.webutils.CSVWriter.writerow().

◆ queue

searx.webutils.CSVWriter.queue = StringIO()

Definition at line 91 of file webutils.py.

Referenced by searx.webutils.CSVWriter.writerow().

◆ stream

searx.webutils.CSVWriter.stream = f

Definition at line 93 of file webutils.py.

Referenced by searx.webutils.CSVWriter.writerow().

◆ writer

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

Definition at line 92 of file webutils.py.

Referenced by searx.webutils.CSVWriter.writerow().


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