Advertisement
campos20

Adapt requests

Apr 19th, 2022
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. def get_role(s: str):
  2.     return s.split(", ")[-1][:-1]
  3.  
  4. def find_closing(s: str, start: int):
  5.     c = 1
  6.     first = s.index('(')
  7.     for x in s[first+1:]:
  8.         if x == '(':
  9.             c += 1
  10.         elif x == ')':
  11.             c -= 1
  12.         if x == 0:
  13.             return c
  14.  
  15. def get_body(s: str):
  16.     start = s.index('Map.of')
  17.     end = find_closing(s, start)
  18.     return s[start:end]
  19.  
  20. text = []
  21. while 1:
  22.     try:
  23.         text.append(input())
  24.     except:
  25.         break
  26.  
  27. last_status = None
  28. current = 0
  29.  
  30. for s in text:
  31.     if 'withResponseStatusCodeAs' in s:
  32.         last_status = s[s.find("(")+1:s.find(")")]
  33.  
  34.     if not 'params' in s:
  35.         continue
  36.    
  37.     role = get_role(s)
  38.     body = get_body(s)
  39.     print(f'Arguments.of({current}, "", {last_status}, {role}, {body},')
  40.     current += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement