Python Forum
Remove double quotes from the list ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove double quotes from the list ?
#14
(Nov-01-2020, 09:18 PM)buran Wrote: the problem you have is somewhere before the code you show here

i.e.
how it happened that cgi.FieldStorage instance
FieldStorage (None, None, [MiniFieldStorage ('v_name', 'John'), MiniFieldStorage ('v_sname', 'Aguiar')])
become a str

"FieldStorage (None, None, [MiniFieldStorage ('v_name', 'John'), MiniFieldStorage ('v_sname', 'Aguiar')])"
somewhere you converted cgi.FieldStorage object int str object and that is where the problem is.

there are appropriate methods to parse cgi.FieldStorage and acceess the MiniFiledStorage objects in the list and their values. Don't manipulate strings


import cgi
# let recreate what you SHOULD have instead of str
array_input = cgi.FieldStorage()
array_input.list = [cgi.MiniFieldStorage('v_name', 'John'), cgi.MiniFieldStorage('v_sname', 'Aguiar')]

# what we have and how we access data
print(type(array_input))
print(type(array_input['v_name']))
print(array_input.getvalue('v_name'))
Output:
<class 'cgi.FieldStorage'> <class 'cgi.MiniFieldStorage'> John

It all starts with the code below:
# Retrieves form field entries in the environment variable (wsgi.input) and assigns the variable (array_input):
array_input = cgi.FieldStorage(environ["wsgi.input"], environ=environ)
After that I send the variable array_input via parameter to the method of another class that processes deconstruction of the value of the variable (array_input) so that I can remove the characters that conflict in the threat detection (xss), because I don't know if it is possible to manipulate the type <class 'cgi.FieldStorage'> using regular expressions from the python re module, below is the code that receives the parameter and decouples the variable:

# Function -> Importa module cgi que trata form request e re (regex)
import re

# Class Function ->
class ProcessInputPost:

     # Method Function ->
     def spark (v_response, v_uri, array_input):

         # Function -> Convert to tuple
         a_inp = (array_input)
         # Function -> Convert tuple to string:
         o_inp = str(a_inp)
         # Function -> Remove parentheses for checking data:
         v_inp = re.sub ("[()]", "", o_inp)
         # Function ->
         from cern.safe.threatdetect import ThreatDetect
         # Function ->
         return ThreatDetect.m_post (v_response, v_uri, array_input)


User has been warned for this post. Reason: Edit post content after receiving reply
Reply


Messages In This Thread
Remove double quotes from the list ? - by PythonDev - Oct-31-2020, 01:12 AM
RE: Remove double quotes from the list ? - by buran - Nov-01-2020, 09:18 PM
RE: Remove double quotes from the list ? - by PythonDev - Nov-01-2020, 10:56 PM
RE: Remove double quotes from the list ? - by buran - Nov-02-2020, 08:36 AM
RE: Remove double quotes from the list ? - by buran - Nov-02-2020, 05:41 PM
RE: Remove double quotes from the list ? - by buran - Nov-02-2020, 05:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  remove duplicates from dicts with list values wardancer84 27 6,540 May-27-2024, 04:54 PM
Last Post: wardancer84
  unable to remove all elements from list based on a condition sg_python 3 1,807 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 3,917 Nov-13-2022, 01:27 AM
Last Post: menator01
  Reading list items without brackets and quotes jesse68 6 7,166 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Remove empty keys in a python list python_student 7 5,903 Jan-12-2022, 10:23 PM
Last Post: python_student
  Remove an item from a list contained in another item in python CompleteNewb 19 9,209 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  Remove single and double quotes from a csv file in 3 to 4 column shantanu97 0 8,791 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Two types of single quotes Led_Zeppelin 2 2,692 Mar-15-2021, 07:55 PM
Last Post: BashBedlam
  .remove() from a list - request for explanation InputOutput007 3 3,097 Jan-28-2021, 04:21 PM
Last Post: InputOutput007
  Remove specific elements from list with a pattern Xalagy 3 3,739 Oct-11-2020, 07:18 AM
Last Post: Xalagy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020