Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: csv.py
[0] Fix | Delete
"""
[1] Fix | Delete
csv.py - read/write/investigate CSV files
[2] Fix | Delete
"""
[3] Fix | Delete
[4] Fix | Delete
import re
[5] Fix | Delete
from _csv import Error, __version__, writer, reader, register_dialect, \
[6] Fix | Delete
unregister_dialect, get_dialect, list_dialects, \
[7] Fix | Delete
field_size_limit, \
[8] Fix | Delete
QUOTE_MINIMAL, QUOTE_ALL, QUOTE_NONNUMERIC, QUOTE_NONE, \
[9] Fix | Delete
__doc__
[10] Fix | Delete
from _csv import Dialect as _Dialect
[11] Fix | Delete
[12] Fix | Delete
from collections import OrderedDict
[13] Fix | Delete
from io import StringIO
[14] Fix | Delete
[15] Fix | Delete
__all__ = ["QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
[16] Fix | Delete
"Error", "Dialect", "__doc__", "excel", "excel_tab",
[17] Fix | Delete
"field_size_limit", "reader", "writer",
[18] Fix | Delete
"register_dialect", "get_dialect", "list_dialects", "Sniffer",
[19] Fix | Delete
"unregister_dialect", "__version__", "DictReader", "DictWriter",
[20] Fix | Delete
"unix_dialect"]
[21] Fix | Delete
[22] Fix | Delete
class Dialect:
[23] Fix | Delete
"""Describe a CSV dialect.
[24] Fix | Delete
[25] Fix | Delete
This must be subclassed (see csv.excel). Valid attributes are:
[26] Fix | Delete
delimiter, quotechar, escapechar, doublequote, skipinitialspace,
[27] Fix | Delete
lineterminator, quoting.
[28] Fix | Delete
[29] Fix | Delete
"""
[30] Fix | Delete
_name = ""
[31] Fix | Delete
_valid = False
[32] Fix | Delete
# placeholders
[33] Fix | Delete
delimiter = None
[34] Fix | Delete
quotechar = None
[35] Fix | Delete
escapechar = None
[36] Fix | Delete
doublequote = None
[37] Fix | Delete
skipinitialspace = None
[38] Fix | Delete
lineterminator = None
[39] Fix | Delete
quoting = None
[40] Fix | Delete
[41] Fix | Delete
def __init__(self):
[42] Fix | Delete
if self.__class__ != Dialect:
[43] Fix | Delete
self._valid = True
[44] Fix | Delete
self._validate()
[45] Fix | Delete
[46] Fix | Delete
def _validate(self):
[47] Fix | Delete
try:
[48] Fix | Delete
_Dialect(self)
[49] Fix | Delete
except TypeError as e:
[50] Fix | Delete
# We do this for compatibility with py2.3
[51] Fix | Delete
raise Error(str(e))
[52] Fix | Delete
[53] Fix | Delete
class excel(Dialect):
[54] Fix | Delete
"""Describe the usual properties of Excel-generated CSV files."""
[55] Fix | Delete
delimiter = ','
[56] Fix | Delete
quotechar = '"'
[57] Fix | Delete
doublequote = True
[58] Fix | Delete
skipinitialspace = False
[59] Fix | Delete
lineterminator = '\r\n'
[60] Fix | Delete
quoting = QUOTE_MINIMAL
[61] Fix | Delete
register_dialect("excel", excel)
[62] Fix | Delete
[63] Fix | Delete
class excel_tab(excel):
[64] Fix | Delete
"""Describe the usual properties of Excel-generated TAB-delimited files."""
[65] Fix | Delete
delimiter = '\t'
[66] Fix | Delete
register_dialect("excel-tab", excel_tab)
[67] Fix | Delete
[68] Fix | Delete
class unix_dialect(Dialect):
[69] Fix | Delete
"""Describe the usual properties of Unix-generated CSV files."""
[70] Fix | Delete
delimiter = ','
[71] Fix | Delete
quotechar = '"'
[72] Fix | Delete
doublequote = True
[73] Fix | Delete
skipinitialspace = False
[74] Fix | Delete
lineterminator = '\n'
[75] Fix | Delete
quoting = QUOTE_ALL
[76] Fix | Delete
register_dialect("unix", unix_dialect)
[77] Fix | Delete
[78] Fix | Delete
[79] Fix | Delete
class DictReader:
[80] Fix | Delete
def __init__(self, f, fieldnames=None, restkey=None, restval=None,
[81] Fix | Delete
dialect="excel", *args, **kwds):
[82] Fix | Delete
self._fieldnames = fieldnames # list of keys for the dict
[83] Fix | Delete
self.restkey = restkey # key to catch long rows
[84] Fix | Delete
self.restval = restval # default value for short rows
[85] Fix | Delete
self.reader = reader(f, dialect, *args, **kwds)
[86] Fix | Delete
self.dialect = dialect
[87] Fix | Delete
self.line_num = 0
[88] Fix | Delete
[89] Fix | Delete
def __iter__(self):
[90] Fix | Delete
return self
[91] Fix | Delete
[92] Fix | Delete
@property
[93] Fix | Delete
def fieldnames(self):
[94] Fix | Delete
if self._fieldnames is None:
[95] Fix | Delete
try:
[96] Fix | Delete
self._fieldnames = next(self.reader)
[97] Fix | Delete
except StopIteration:
[98] Fix | Delete
pass
[99] Fix | Delete
self.line_num = self.reader.line_num
[100] Fix | Delete
return self._fieldnames
[101] Fix | Delete
[102] Fix | Delete
@fieldnames.setter
[103] Fix | Delete
def fieldnames(self, value):
[104] Fix | Delete
self._fieldnames = value
[105] Fix | Delete
[106] Fix | Delete
def __next__(self):
[107] Fix | Delete
if self.line_num == 0:
[108] Fix | Delete
# Used only for its side effect.
[109] Fix | Delete
self.fieldnames
[110] Fix | Delete
row = next(self.reader)
[111] Fix | Delete
self.line_num = self.reader.line_num
[112] Fix | Delete
[113] Fix | Delete
# unlike the basic reader, we prefer not to return blanks,
[114] Fix | Delete
# because we will typically wind up with a dict full of None
[115] Fix | Delete
# values
[116] Fix | Delete
while row == []:
[117] Fix | Delete
row = next(self.reader)
[118] Fix | Delete
d = OrderedDict(zip(self.fieldnames, row))
[119] Fix | Delete
lf = len(self.fieldnames)
[120] Fix | Delete
lr = len(row)
[121] Fix | Delete
if lf < lr:
[122] Fix | Delete
d[self.restkey] = row[lf:]
[123] Fix | Delete
elif lf > lr:
[124] Fix | Delete
for key in self.fieldnames[lr:]:
[125] Fix | Delete
d[key] = self.restval
[126] Fix | Delete
return d
[127] Fix | Delete
[128] Fix | Delete
[129] Fix | Delete
class DictWriter:
[130] Fix | Delete
def __init__(self, f, fieldnames, restval="", extrasaction="raise",
[131] Fix | Delete
dialect="excel", *args, **kwds):
[132] Fix | Delete
self.fieldnames = fieldnames # list of keys for the dict
[133] Fix | Delete
self.restval = restval # for writing short dicts
[134] Fix | Delete
if extrasaction.lower() not in ("raise", "ignore"):
[135] Fix | Delete
raise ValueError("extrasaction (%s) must be 'raise' or 'ignore'"
[136] Fix | Delete
% extrasaction)
[137] Fix | Delete
self.extrasaction = extrasaction
[138] Fix | Delete
self.writer = writer(f, dialect, *args, **kwds)
[139] Fix | Delete
[140] Fix | Delete
def writeheader(self):
[141] Fix | Delete
header = dict(zip(self.fieldnames, self.fieldnames))
[142] Fix | Delete
self.writerow(header)
[143] Fix | Delete
[144] Fix | Delete
def _dict_to_list(self, rowdict):
[145] Fix | Delete
if self.extrasaction == "raise":
[146] Fix | Delete
wrong_fields = rowdict.keys() - self.fieldnames
[147] Fix | Delete
if wrong_fields:
[148] Fix | Delete
raise ValueError("dict contains fields not in fieldnames: "
[149] Fix | Delete
+ ", ".join([repr(x) for x in wrong_fields]))
[150] Fix | Delete
return (rowdict.get(key, self.restval) for key in self.fieldnames)
[151] Fix | Delete
[152] Fix | Delete
def writerow(self, rowdict):
[153] Fix | Delete
return self.writer.writerow(self._dict_to_list(rowdict))
[154] Fix | Delete
[155] Fix | Delete
def writerows(self, rowdicts):
[156] Fix | Delete
return self.writer.writerows(map(self._dict_to_list, rowdicts))
[157] Fix | Delete
[158] Fix | Delete
# Guard Sniffer's type checking against builds that exclude complex()
[159] Fix | Delete
try:
[160] Fix | Delete
complex
[161] Fix | Delete
except NameError:
[162] Fix | Delete
complex = float
[163] Fix | Delete
[164] Fix | Delete
class Sniffer:
[165] Fix | Delete
'''
[166] Fix | Delete
"Sniffs" the format of a CSV file (i.e. delimiter, quotechar)
[167] Fix | Delete
Returns a Dialect object.
[168] Fix | Delete
'''
[169] Fix | Delete
def __init__(self):
[170] Fix | Delete
# in case there is more than one possible delimiter
[171] Fix | Delete
self.preferred = [',', '\t', ';', ' ', ':']
[172] Fix | Delete
[173] Fix | Delete
[174] Fix | Delete
def sniff(self, sample, delimiters=None):
[175] Fix | Delete
"""
[176] Fix | Delete
Returns a dialect (or None) corresponding to the sample
[177] Fix | Delete
"""
[178] Fix | Delete
[179] Fix | Delete
quotechar, doublequote, delimiter, skipinitialspace = \
[180] Fix | Delete
self._guess_quote_and_delimiter(sample, delimiters)
[181] Fix | Delete
if not delimiter:
[182] Fix | Delete
delimiter, skipinitialspace = self._guess_delimiter(sample,
[183] Fix | Delete
delimiters)
[184] Fix | Delete
[185] Fix | Delete
if not delimiter:
[186] Fix | Delete
raise Error("Could not determine delimiter")
[187] Fix | Delete
[188] Fix | Delete
class dialect(Dialect):
[189] Fix | Delete
_name = "sniffed"
[190] Fix | Delete
lineterminator = '\r\n'
[191] Fix | Delete
quoting = QUOTE_MINIMAL
[192] Fix | Delete
# escapechar = ''
[193] Fix | Delete
[194] Fix | Delete
dialect.doublequote = doublequote
[195] Fix | Delete
dialect.delimiter = delimiter
[196] Fix | Delete
# _csv.reader won't accept a quotechar of ''
[197] Fix | Delete
dialect.quotechar = quotechar or '"'
[198] Fix | Delete
dialect.skipinitialspace = skipinitialspace
[199] Fix | Delete
[200] Fix | Delete
return dialect
[201] Fix | Delete
[202] Fix | Delete
[203] Fix | Delete
def _guess_quote_and_delimiter(self, data, delimiters):
[204] Fix | Delete
"""
[205] Fix | Delete
Looks for text enclosed between two identical quotes
[206] Fix | Delete
(the probable quotechar) which are preceded and followed
[207] Fix | Delete
by the same character (the probable delimiter).
[208] Fix | Delete
For example:
[209] Fix | Delete
,'some text',
[210] Fix | Delete
The quote with the most wins, same with the delimiter.
[211] Fix | Delete
If there is no quotechar the delimiter can't be determined
[212] Fix | Delete
this way.
[213] Fix | Delete
"""
[214] Fix | Delete
[215] Fix | Delete
matches = []
[216] Fix | Delete
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
[217] Fix | Delete
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
[218] Fix | Delete
r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
[219] Fix | Delete
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
[220] Fix | Delete
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
[221] Fix | Delete
matches = regexp.findall(data)
[222] Fix | Delete
if matches:
[223] Fix | Delete
break
[224] Fix | Delete
[225] Fix | Delete
if not matches:
[226] Fix | Delete
# (quotechar, doublequote, delimiter, skipinitialspace)
[227] Fix | Delete
return ('', False, None, 0)
[228] Fix | Delete
quotes = {}
[229] Fix | Delete
delims = {}
[230] Fix | Delete
spaces = 0
[231] Fix | Delete
groupindex = regexp.groupindex
[232] Fix | Delete
for m in matches:
[233] Fix | Delete
n = groupindex['quote'] - 1
[234] Fix | Delete
key = m[n]
[235] Fix | Delete
if key:
[236] Fix | Delete
quotes[key] = quotes.get(key, 0) + 1
[237] Fix | Delete
try:
[238] Fix | Delete
n = groupindex['delim'] - 1
[239] Fix | Delete
key = m[n]
[240] Fix | Delete
except KeyError:
[241] Fix | Delete
continue
[242] Fix | Delete
if key and (delimiters is None or key in delimiters):
[243] Fix | Delete
delims[key] = delims.get(key, 0) + 1
[244] Fix | Delete
try:
[245] Fix | Delete
n = groupindex['space'] - 1
[246] Fix | Delete
except KeyError:
[247] Fix | Delete
continue
[248] Fix | Delete
if m[n]:
[249] Fix | Delete
spaces += 1
[250] Fix | Delete
[251] Fix | Delete
quotechar = max(quotes, key=quotes.get)
[252] Fix | Delete
[253] Fix | Delete
if delims:
[254] Fix | Delete
delim = max(delims, key=delims.get)
[255] Fix | Delete
skipinitialspace = delims[delim] == spaces
[256] Fix | Delete
if delim == '\n': # most likely a file with a single column
[257] Fix | Delete
delim = ''
[258] Fix | Delete
else:
[259] Fix | Delete
# there is *no* delimiter, it's a single column of quoted data
[260] Fix | Delete
delim = ''
[261] Fix | Delete
skipinitialspace = 0
[262] Fix | Delete
[263] Fix | Delete
# if we see an extra quote between delimiters, we've got a
[264] Fix | Delete
# double quoted format
[265] Fix | Delete
dq_regexp = re.compile(
[266] Fix | Delete
r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \
[267] Fix | Delete
{'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE)
[268] Fix | Delete
[269] Fix | Delete
[270] Fix | Delete
[271] Fix | Delete
if dq_regexp.search(data):
[272] Fix | Delete
doublequote = True
[273] Fix | Delete
else:
[274] Fix | Delete
doublequote = False
[275] Fix | Delete
[276] Fix | Delete
return (quotechar, doublequote, delim, skipinitialspace)
[277] Fix | Delete
[278] Fix | Delete
[279] Fix | Delete
def _guess_delimiter(self, data, delimiters):
[280] Fix | Delete
"""
[281] Fix | Delete
The delimiter /should/ occur the same number of times on
[282] Fix | Delete
each row. However, due to malformed data, it may not. We don't want
[283] Fix | Delete
an all or nothing approach, so we allow for small variations in this
[284] Fix | Delete
number.
[285] Fix | Delete
1) build a table of the frequency of each character on every line.
[286] Fix | Delete
2) build a table of frequencies of this frequency (meta-frequency?),
[287] Fix | Delete
e.g. 'x occurred 5 times in 10 rows, 6 times in 1000 rows,
[288] Fix | Delete
7 times in 2 rows'
[289] Fix | Delete
3) use the mode of the meta-frequency to determine the /expected/
[290] Fix | Delete
frequency for that character
[291] Fix | Delete
4) find out how often the character actually meets that goal
[292] Fix | Delete
5) the character that best meets its goal is the delimiter
[293] Fix | Delete
For performance reasons, the data is evaluated in chunks, so it can
[294] Fix | Delete
try and evaluate the smallest portion of the data possible, evaluating
[295] Fix | Delete
additional chunks as necessary.
[296] Fix | Delete
"""
[297] Fix | Delete
[298] Fix | Delete
data = list(filter(None, data.split('\n')))
[299] Fix | Delete
[300] Fix | Delete
ascii = [chr(c) for c in range(127)] # 7-bit ASCII
[301] Fix | Delete
[302] Fix | Delete
# build frequency tables
[303] Fix | Delete
chunkLength = min(10, len(data))
[304] Fix | Delete
iteration = 0
[305] Fix | Delete
charFrequency = {}
[306] Fix | Delete
modes = {}
[307] Fix | Delete
delims = {}
[308] Fix | Delete
start, end = 0, min(chunkLength, len(data))
[309] Fix | Delete
while start < len(data):
[310] Fix | Delete
iteration += 1
[311] Fix | Delete
for line in data[start:end]:
[312] Fix | Delete
for char in ascii:
[313] Fix | Delete
metaFrequency = charFrequency.get(char, {})
[314] Fix | Delete
# must count even if frequency is 0
[315] Fix | Delete
freq = line.count(char)
[316] Fix | Delete
# value is the mode
[317] Fix | Delete
metaFrequency[freq] = metaFrequency.get(freq, 0) + 1
[318] Fix | Delete
charFrequency[char] = metaFrequency
[319] Fix | Delete
[320] Fix | Delete
for char in charFrequency.keys():
[321] Fix | Delete
items = list(charFrequency[char].items())
[322] Fix | Delete
if len(items) == 1 and items[0][0] == 0:
[323] Fix | Delete
continue
[324] Fix | Delete
# get the mode of the frequencies
[325] Fix | Delete
if len(items) > 1:
[326] Fix | Delete
modes[char] = max(items, key=lambda x: x[1])
[327] Fix | Delete
# adjust the mode - subtract the sum of all
[328] Fix | Delete
# other frequencies
[329] Fix | Delete
items.remove(modes[char])
[330] Fix | Delete
modes[char] = (modes[char][0], modes[char][1]
[331] Fix | Delete
- sum(item[1] for item in items))
[332] Fix | Delete
else:
[333] Fix | Delete
modes[char] = items[0]
[334] Fix | Delete
[335] Fix | Delete
# build a list of possible delimiters
[336] Fix | Delete
modeList = modes.items()
[337] Fix | Delete
total = float(chunkLength * iteration)
[338] Fix | Delete
# (rows of consistent data) / (number of rows) = 100%
[339] Fix | Delete
consistency = 1.0
[340] Fix | Delete
# minimum consistency threshold
[341] Fix | Delete
threshold = 0.9
[342] Fix | Delete
while len(delims) == 0 and consistency >= threshold:
[343] Fix | Delete
for k, v in modeList:
[344] Fix | Delete
if v[0] > 0 and v[1] > 0:
[345] Fix | Delete
if ((v[1]/total) >= consistency and
[346] Fix | Delete
(delimiters is None or k in delimiters)):
[347] Fix | Delete
delims[k] = v
[348] Fix | Delete
consistency -= 0.01
[349] Fix | Delete
[350] Fix | Delete
if len(delims) == 1:
[351] Fix | Delete
delim = list(delims.keys())[0]
[352] Fix | Delete
skipinitialspace = (data[0].count(delim) ==
[353] Fix | Delete
data[0].count("%c " % delim))
[354] Fix | Delete
return (delim, skipinitialspace)
[355] Fix | Delete
[356] Fix | Delete
# analyze another chunkLength lines
[357] Fix | Delete
start = end
[358] Fix | Delete
end += chunkLength
[359] Fix | Delete
[360] Fix | Delete
if not delims:
[361] Fix | Delete
return ('', 0)
[362] Fix | Delete
[363] Fix | Delete
# if there's more than one, fall back to a 'preferred' list
[364] Fix | Delete
if len(delims) > 1:
[365] Fix | Delete
for d in self.preferred:
[366] Fix | Delete
if d in delims.keys():
[367] Fix | Delete
skipinitialspace = (data[0].count(d) ==
[368] Fix | Delete
data[0].count("%c " % d))
[369] Fix | Delete
return (d, skipinitialspace)
[370] Fix | Delete
[371] Fix | Delete
# nothing else indicates a preference, pick the character that
[372] Fix | Delete
# dominates(?)
[373] Fix | Delete
items = [(v,k) for (k,v) in delims.items()]
[374] Fix | Delete
items.sort()
[375] Fix | Delete
delim = items[-1][1]
[376] Fix | Delete
[377] Fix | Delete
skipinitialspace = (data[0].count(delim) ==
[378] Fix | Delete
data[0].count("%c " % delim))
[379] Fix | Delete
return (delim, skipinitialspace)
[380] Fix | Delete
[381] Fix | Delete
[382] Fix | Delete
def has_header(self, sample):
[383] Fix | Delete
# Creates a dictionary of types of data in each column. If any
[384] Fix | Delete
# column is of a single type (say, integers), *except* for the first
[385] Fix | Delete
# row, then the first row is presumed to be labels. If the type
[386] Fix | Delete
# can't be determined, it is assumed to be a string in which case
[387] Fix | Delete
# the length of the string is the determining factor: if all of the
[388] Fix | Delete
# rows except for the first are the same length, it's a header.
[389] Fix | Delete
# Finally, a 'vote' is taken at the end for each column, adding or
[390] Fix | Delete
# subtracting from the likelihood of the first row being a header.
[391] Fix | Delete
[392] Fix | Delete
rdr = reader(StringIO(sample), self.sniff(sample))
[393] Fix | Delete
[394] Fix | Delete
header = next(rdr) # assume first row is header
[395] Fix | Delete
[396] Fix | Delete
columns = len(header)
[397] Fix | Delete
columnTypes = {}
[398] Fix | Delete
for i in range(columns): columnTypes[i] = None
[399] Fix | Delete
[400] Fix | Delete
checked = 0
[401] Fix | Delete
for row in rdr:
[402] Fix | Delete
# arbitrary number of rows to check, to keep it sane
[403] Fix | Delete
if checked > 20:
[404] Fix | Delete
break
[405] Fix | Delete
checked += 1
[406] Fix | Delete
[407] Fix | Delete
if len(row) != columns:
[408] Fix | Delete
continue # skip rows that have irregular number of columns
[409] Fix | Delete
[410] Fix | Delete
for col in list(columnTypes.keys()):
[411] Fix | Delete
[412] Fix | Delete
for thisType in [int, float, complex]:
[413] Fix | Delete
try:
[414] Fix | Delete
thisType(row[col])
[415] Fix | Delete
break
[416] Fix | Delete
except (ValueError, OverflowError):
[417] Fix | Delete
pass
[418] Fix | Delete
else:
[419] Fix | Delete
# fallback to length of string
[420] Fix | Delete
thisType = len(row[col])
[421] Fix | Delete
[422] Fix | Delete
if thisType != columnTypes[col]:
[423] Fix | Delete
if columnTypes[col] is None: # add new column type
[424] Fix | Delete
columnTypes[col] = thisType
[425] Fix | Delete
else:
[426] Fix | Delete
# type is inconsistent, remove column from
[427] Fix | Delete
# consideration
[428] Fix | Delete
del columnTypes[col]
[429] Fix | Delete
[430] Fix | Delete
# finally, compare results against first row and "vote"
[431] Fix | Delete
# on whether it's a header
[432] Fix | Delete
hasHeader = 0
[433] Fix | Delete
for col, colType in columnTypes.items():
[434] Fix | Delete
if type(colType) == type(0): # it's a length
[435] Fix | Delete
if len(header[col]) != colType:
[436] Fix | Delete
hasHeader += 1
[437] Fix | Delete
else:
[438] Fix | Delete
hasHeader -= 1
[439] Fix | Delete
else: # attempt typecast
[440] Fix | Delete
try:
[441] Fix | Delete
colType(header[col])
[442] Fix | Delete
except (ValueError, TypeError):
[443] Fix | Delete
hasHeader += 1
[444] Fix | Delete
else:
[445] Fix | Delete
hasHeader -= 1
[446] Fix | Delete
[447] Fix | Delete
return hasHeader > 0
[448] Fix | Delete
[449] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function