How to use set_option method in yandex-tank

Best Python code snippet using yandex-tank

libraddask_test.py

Source:libraddask_test.py Github

copy

Full Screen

...54 print('\nOptions:')55 for fn in aerosol_options.setup_aerosol_group():56 print(fn.name)57 print('\nTesting set_option:')58 case.set_option('aerosol_default',1)59 case.set_option('aerosol_file','gg','aerosol_file',1)60 case.set_option('aerosol_profile_modtran',True)61 case.set_option('aerosol_angstrom',10.,10,1)62 case.set_option('aerosol_king_byrne',1.,1.,1.,1)63 case.set_option('aerosol_modify','gg','scale',1,1)64 case.set_option('aerosol_haze',1)65 case.set_option('aerosol_set_tau_at_wvl',1.,1.,'Input.aer.tau_wvl_tau',1)66 case.set_option('aerosol_season',10,1)67 case.set_option('aerosol_species_file','continental_clean',1,1)68 case.set_option('aerosol_species_library','OPAC')69 case.set_option('aerosol_visibility',10.)70 case.set_option('aerosol_sizedist_file','aerosol_sizedist_file')71 case.set_option('aerosol_refrac_index',3.,5.,1)72 print(f'Case contents:\n{case}')73#==================================================74if doAllTests:75 case = librad.Case(casename='TestCase')76 print(50*'='+'\n'+50*'=')77 print('cloud_options')78 print(f'\nOptions documented:')79 for key in cloud_options.get_documentation().keys():80 print(key)81 print('\nOptions:')82 for fn in cloud_options.setup_cloud_group():83 print(fn.name)84 print('\nTesting set_option:')85 case.set_option('wc_file',option_definition.CaothType('wc'),'CAOTH_FROM_','str')86 case.set_option('wc_properties',option_definition.CaothType('wc'),'echam4','interpolate')87 case.set_option('wc_modify',option_definition.CaothType('wc'),'tau','scale',45.)88 case.set_option('ic_file',option_definition.CaothType('ic'),'CAOTH_FROM_',io.IOBase)89 case.set_option('ic_properties',option_definition.CaothType('ic'),'yang','interpolate')90 case.set_option('ic_modify',option_definition.CaothType('ic'),'tau550','scale',5.)91 case.set_option('ic_habit',option_definition.CaothType('ic'),'hollow-column')92 case.set_option('ic_habit_yang2013',option_definition.CaothType('ic'),'column_8elements','severe')93 case.set_option('ic_fu',option_definition.CaothType('ic'),'reff_def','off','id2')94 case.set_option('ic_raytracing_file',option_definition.CaothType('ic'),io.IOBase)95 case.set_option('cloud_fraction_file',io.IOBase)96 case.set_option('cloud_overlap','maxrand')97 case.set_option('cloudcover',option_definition.CaothType('ic'),4.,1,1)98 print(f'Case contents:\n{case}')99#==================================================100if doAllTests:101 case = librad.Case(casename='TestCase')102 print(50*'='+'\n'+50*'=')103 print('general_atmosphere_options')104 print(f'\nOptions documented:')105 for key in general_atmosphere_options.get_documentation().keys():106 print(key)107 print('\nOptions:')108 for fn in general_atmosphere_options.setup_general_atm_group():109 print(fn.name)110 print('\nTesting set_option:')111 # case.set_option('atmos_region',5,6,7,8)112 case.set_option('no_absorption','?????',option_definition.CaothoffType,1)113 case.set_option('no_scattering','?????',option_definition.CaothoffType,1)114 case.set_option('interpret_as_level',option_definition.CaothType,'FALSE')115 case.set_option('zout_interpolate','ZOUT_INTERPOLATE')116 case.set_option('z_interpolate')117 case.set_option('atm_z_grid',-5.,'ntokens')118 case.set_option('reverse_atmosphere',0)119 print(f'Case contents:\n{case}')120#==================================================121if doAllTests:122 case = librad.Case(casename='TestCase')123 print(50*'='+'\n'+50*'=')124 print('geometry_options')125 print(f'\nOptions documented:')126 for key in geometry_options.get_documentation().keys():127 print(key)128 print('\nOptions:')129 for fn in geometry_options.setup_geometry_group():130 print(fn.name)131 print('\nTesting set_option:')132 case.set_option('sza',4.,'SZA_DIRECT_INPUT')133 case.set_option('sza_file',io.IOBase,'SZA_BY_TIME_AND_LOCATION')134 case.set_option('phi0',4.)135 case.set_option('phi',-5.,6.,7.)136 case.set_option('umu',-5.,6.,7.)137 # case.set_option('mc_bw_umu_file',io.IOBase,True)138 case.set_option('earth_radius',7.)139 case.set_option('latitude','LATITUDE_SIGNUM_',5.,6.,7.)140 case.set_option('longitude','LONGITUDE_SIGNUM_',5.,6.,7.)141 case.set_option('day_of_year',7)142 case.set_option('mc_bcond','periodic')143 # case.set_option('mc_sample_grid',4,5,6.,7.)144 case.set_option('mc_spherical','1D',1,'1d')145 # case.set_option('mc_spherical3D_scene',1,5.,6.,.7,.8)146 case.set_option('mc_satellite_view','pointer', 1.,2.,3.,4.,'PAN_MODE_SATELLITE',True)147 # case.set_option('mc_satellite_position','SZA_DIRECT_INPUT',4.,5.)148 case.set_option('mc_sensordirection',1.,2.,3.,4)149 # case.set_option('mc_sensorposition',1.,2.,3.,'MC_SENSORPOSITION_CARTESIAN')150 case.set_option('mc_reference_to_nn',1)151 case.set_option('mc_panorama_forward','pointer',0,360,0,180,1,True)152 # case.set_option('mc_panorama_view','pointer',0.,360.,0.,180.,'PAN_MODE_CAMERA',True)153 case.set_option('mc_panorama_alignment','mu')154 # case.set_option('mc_panorama','no_pixel',1)155 # case.set_option('mc_blitz_position','pointer',0.,1.,2.,3.,4.,5.,'SRC_BLITZ',True)156 print(f'Case contents:\n{case}')157#==================================================158if doAllTests:159 case = librad.Case(casename='TestCase')160 print(50*'='+'\n'+50*'=')161 print('mc_options')162 print(f'\nOptions documented:')163 for key in mc_options.get_documentation().keys():164 print(key)165 print('\nOptions:')166 for fn in mc_options.setup_mc_group():167 print(fn.name)168 print('\nTesting set_option:')169 case.set_option('mc_escape','str')170 case.set_option('mc_core',1,'???','???','CAOTH_FROM_3D','filename','PROP_HU','str')171 case.set_option('mc_core_threshold',6.)172 case.set_option('mc_core_scale',-1)173 case.set_option('mc_core_savefile','str')174 case.set_option('mc_vroom',1,'on')175 # case.set_option('mc_visualize',1,'hiddenline')176 case.set_option('mc_truncate',1,4.)177 case.set_option('mc_backward',1,2,3,4,5)178 # case.set_option('mc_sample_cldprp',1,1)179 case.set_option('mc_surface_reflectalways',1)180 # case.set_option('mc_DoLE',1)181 case.set_option('mc_spectral_is',True,3.)182 # case.set_option('mc_aerosol_is',io.IOBase,True)183 case.set_option('mc_boxairmass','1D',1)184 case.set_option('mc_albedo_spectral',1)185 case.set_option('mc_azimuth_old','MCAZIMUTH_OLD')186 # case.set_option('mc_backward_heat','EMABS')187 case.set_option('mc_backward_sunshape_file',io.IOBase)188 case.set_option('mc_backward_writeback',1)189 case.set_option('mc_coherent_backscatter',1,2,3)190 # case.set_option('mc_delta_scaling',0.99,0,4,5)191 case.set_option('mc_maxscatters',3)192 case.set_option('mc_minscatters',1)193 case.set_option('mc_minphotons',4)194 case.set_option('mc_photons',4)195 case.set_option('mc_photons_file',io.IOBase)196 case.set_option('mc_polarisation',1,1,3)197 case.set_option('mc_rad_alpha',5.)198 # case.set_option('mc_radial_pathlength',5,6)199 case.set_option('mc_radial_pathlength_dt',.1)200 # case.set_option('mc_readrandomstatus',1,1)201 case.set_option('mc_randomseed',5)202 case.set_option('mc_refraction',1)203 # case.set_option('mc_ris','MC_RIS_',5.)204 print(f'Case contents:\n{case}')205#==================================================206if doAllTests:207 case = librad.Case(casename='TestCase')208 print(50*'='+'\n'+50*'=')209 print('molecular_options')210 print(f'\nOptions documented:')211 for key in molecular_options.get_documentation().keys():212 print(key)213 print('\nOptions:')214 for fn in molecular_options.setup_molecular_group():215 print(fn.name)216 print('\nTesting set_option:')217 case.set_option('atmosphere_file','str')218 # case.set_option('atmosphere_file_3D','str',True,'???','CAOTH_FROM_3D','"profile_mol3d_dummy.dat"','PROP_HU')219 case.set_option('radiosonde')220 case.set_option('radiosonde_levels_only','FALSE')221 case.set_option('mol_file','CO2',io.IOBase,'cm_3')222 case.set_option('pressure',1000)223 case.set_option('refractive_index_file','str')224 case.set_option('crs_model','o3','Bodhaine')225 case.set_option('crs_file','O3','O3')226 case.set_option('rayleigh_depol',.4)227 case.set_option('mol_abs_param','kato','str')228 case.set_option('reptran_file',io.IOBase)229 case.set_option('ck_lowtran_absorption','O4','on')230 case.set_option('ck_fu_h2o_continuum','on')231 case.set_option('mol_tau_file','FN_MOL_TAU_',io.IOBase)232 case.set_option('mol_modify','O2',5.,'CM_2')233 case.set_option('mixing_ratio','CO2',5.)234 print(f'Case contents:\n{case}')235#==================================================236if doAllTests:237 case = librad.Case(casename='TestCase')238 print(50*'='+'\n'+50*'=')239 print('output_options')240 print(f'\nOptions documented:')241 for key in output_options.get_documentation().keys():242 print(key)243 print('\nOptions:')244 for fn in output_options.setup_output_group():245 print(fn.name)246 print('\nTesting set_option:')247 case.set_option('quiet',1)248 case.set_option('verbose',1)249 # case.set_option('write_ext_to_file',1)250 case.set_option('test_optical_properties',1)251 case.set_option('print_disort_info',1)252 case.set_option('data_files_path',io.IOBase)253 case.set_option('output_process','sum')254 case.set_option('output_file','str')255 case.set_option('output_format','netCDF')256 case.set_option('output_user','str')257 case.set_option('output_quantity','brightness')258 case.set_option('heating_rate','HEAT_LAYER_CD','local')259 # case.set_option('write_output_as_netcdf',)260 case.set_option('slit_function_file',io.IOBase,1)261 case.set_option('spline',1.,1.,1.,1)262 case.set_option('spline_file',io.IOBase,1)263 case.set_option('filter_function_file',io.IOBase,'normalize')264 case.set_option('pressure_out')265 case.set_option('zout','str')266 case.set_option('zout_sea','str')267 case.set_option('mc_backward_output','edir','W_per_m3')268 case.set_option('mc_forward_output','absorption','W_per_m3')269 case.set_option('mc_basename',io.IOBase)270 # case.set_option('mc_backward_writeallpixels',1)271 case.set_option('mc_std',1)272 # case.set_option('mc_surfaceparallel',1)273 case.set_option('mc_jacobian',1)274 # case.set_option('mc_jacobian_std',1)275 print(f'Case contents:\n{case}')276#==================================================277if doAllTests:278 case = librad.Case(casename='TestCase')279 print(50*'='+'\n'+50*'=')280 print('profile_options')281 print(f'\nOptions documented:')282 for key in profile_options.get_documentation().keys():283 print(key)284 print('\nOptions:')285 for fn in profile_options.setup_cloud_group():286 print(fn.name)287 print('\nTesting set_option:') 288 case.set_option('profile_file',option_definition.CaothType,'???',io.IOBase)289 case.set_option('profile_properties',option_definition.CaothType,'hu','interpolate')290 case.set_option('profile_modify',option_definition.CaothType,'gg','set',5.)291 print(f'Case contents:\n{case}')292#==================================================293if doAllTests:294 case = librad.Case(casename='TestCase')295 print(50*'='+'\n'+50*'=')296 print('solver_options')297 print(f'\nOptions documented:')298 for key in solver_options.get_documentation().keys():299 print(key)300 print('\nOptions:')301 for fn in solver_options.setup_solver_group():302 print(fn.name)303 print('\nTesting set_option:') 304 case.set_option('rte_solver','disort')305 case.set_option('pseudospherical',1)306 case.set_option('disort_spherical_albedo',1,0)307 case.set_option('disort_intcor','phase')308 case.set_option('isotropic_source_toa',1)309 case.set_option('raman','RAMAN_CALC','CK_RAMAN','SOLVER_DISORT','PROCESS_RAMAN','original')310 case.set_option('number_of_streams',4)311 case.set_option('polradtran','aziorder',1)312 case.set_option('polradtran_quad_type','G')313 case.set_option('polradtran_max_delta_tau',5.)314 case.set_option('sdisort','ichapman',4)315 case.set_option('sos_nscat',5)316 case.set_option('deltam','on')317 # case.set_option('ipa_3d',1)318 # case.set_option('mc_tenstream',1,'str')319 case.set_option('mc_ipa',1)320 case.set_option('mc_tipa',1,'dirdiff')321 case.set_option('tipa','dirdiff')322 case.set_option('sslidar','area',5.)323 case.set_option('sslidar_nranges',5)324 case.set_option('sslidar_polarisation',1)325 case.set_option('tzs_cloud_top_height','str')326 case.set_option('mc_nca',1,'str')327 print(f'Case contents:\n{case}')328#==================================================329if doAllTests:330 case = librad.Case(casename='TestCase')331 print(50*'='+'\n'+50*'=')332 print('special_options')333 print(f'\nOptions documented:')334 for key in special_options.get_documentation().keys():335 print(key)336 print('\nOptions:')337 for fn in special_options.setup_special_group():338 print(fn.name)339 print('\nTesting set_option:') 340 case.set_option('albedo_library','str')341 case.set_option('cloud_fraction_map',io.IOBase)342 case.set_option('albedo_map','ALBEDO_FROM_ALBEDO_MAP',io.IOBase,io.IOBase,'str')343 case.set_option('altitude_map','ALT_FROM_MAP',io.IOBase,io.IOBase,5.)344 case.set_option('cox_and_munk_u10_map',io.IOBase,'BRDF_NONE')345 case.set_option('cox_and_munk_pcl_map','BRDF_CAM',io.IOBase,io.IOBase,5.)346 case.set_option('cox_and_munk_sal_map','BRDF_CAM',io.IOBase,io.IOBase,5.)347 case.set_option('emissivity_map','ALBEDO_FROM_EMISSIVITY_MAP',io.IOBase,io.IOBase,5.)348 case.set_option('surface_temperature_map',io.IOBase,io.IOBase)349 case.set_option('surface_type_map','TRUE',io.IOBase,io.IOBase)350 case.set_option('ECHAM_sza',io.IOBase,'NOT_DEFINED_FLOAT','SZA_ECHAM')351 case.set_option('ECMWF_ozone_climatology','TRUE')352 case.set_option('ECMWF_wc_file',option_definition.CaothType('wc'),'CAOTH_FROM_ECMWF',io.IOBase)353 case.set_option('ECMWF_ic_file',option_definition.CaothType('ic'),'CAOTH_FROM_ECMWF',io.IOBase)354 case.set_option('ECMWF_levels_only','FALSE')355 case.set_option('ECMWF_wind_file',io.IOBase)356 case.set_option('satellite_geometry',io.IOBase)357 case.set_option('satellite_pixel',5,5)358 print(f'Case contents:\n{case}')359#==================================================360if doAllTests:361 case = librad.Case(casename='TestCase')362 print(50*'='+'\n'+50*'=')363 print('spectral_options')364 print(f'\nOptions documented:')365 for key in spectral_options.get_documentation().keys():366 print(key)367 print('\nOptions:')368 for fn in spectral_options.setup_spectral_group():369 print(fn.name)370 print('\nTesting set_option:')371 case.set_option('wavelength',500.,600.)372 # case.set_option('wavelength_step')373 case.set_option('wavelength_index',5,6)374 case.set_option('wavelength_grid_file','wavelength_grid_file')375 case.set_option('thermal_bands_file','thermal_bands_file')376 case.set_option('thermal_bandwidth',500,'nm')377 case.set_option('source','thermal','source','per_cm-1')378 case.set_option('mc_sun_angular_size',3.14)379 # case.set_option('mc_lidar','SRC_LIDAR',0,'MCLIDAR_SPACE','polarize')380 case.set_option('mc_lidar_file','mc_lidar_file')381 # case.set_option('mc_radar','SRC_LIDAR',0,'MCRADAR')382 print(f'Case contents:\n{case}')383#==================================================384if doAllTests:385 case = librad.Case(casename='TestCase')386 print(50*'='+'\n'+50*'=')387 print('surface_options')388 print(f'\nOptions documented:')389 for key in surface_options.get_documentation().keys():390 print(key)391 print('\nOptions:')392 for fn in surface_options.setup_surface_group():393 print(fn.name)394 print('\nTesting set_option:') 395 # case.set_option('altitude','ALT_NOT_DEFINED',3.,4.)396 case.set_option('altitude',3.,4.)397 # case.set_option('mc_elevation_file',io.IOBase)398 case.set_option('albedo',.5,'NOT_DEFINED_INTEGER')399 case.set_option('albedo_file',io.IOBase,False,1)400 case.set_option('brdf_cam','pcl',6.,'BRDF_CAM')401 case.set_option('brdf_cam_solar_wind',1)402 case.set_option('brdf_hapke','b0',5.)403 case.set_option('brdf_hapke_file',io.IOBase,'HAPKE_FROM_HAPKE_FILE')404 case.set_option('brdf_rossli','iso',4.)405 case.set_option('brdf_rossli_hotspot','BRDF_ROSSLI_HOTSPOT_ON')406 case.set_option('brdf_rossli_file',io.IOBase,'ROSSLI_FROM_ROSSLI_FILE')407 case.set_option('brdf_ambrals','ROSSLI_AMBRALS_CONSTANT','vol',5.)408 case.set_option('brdf_ambrals_hotspot','BRDF_ROSSLI_HOTSPOT_ON')409 case.set_option('brdf_ambrals_file',io.IOBase,'ROSSLI_FROM_AMBRALS_FILE')410 case.set_option('fluorescence',5.,'FLUORESCENCE_CONSTANT')411 case.set_option('fluorescence_file',io.IOBase,'FLUORESCENCE_FROM_FLUORESCENCE_FILE')412 case.set_option('brdf_rpv_file',io.IOBase,'RPV_FROM_RPV_FILE')413 case.set_option('brdf_rpv','sigma',4.)414 case.set_option('brdf_rpv_library','str')415 case.set_option('brdf_rpv_type',5,False)416 case.set_option('sur_temperature',5900.)417 # case.set_option('sur_temperature_file',io.IOBase)418 # case.set_option('mc_albedo_file',io.IOBase)419 # case.set_option('mc_albedo_type',io.IOBase)420 case.set_option('mc_albedo_spectral_file',io.IOBase)421 # case.set_option('mc_rossli_file',io.IOBase)422 # case.set_option('mc_ambrals_file',io.IOBase)423 case.set_option('mc_ambrals_type',io.IOBase)424 # case.set_option('mc_ambrals_spectral_file',io.IOBase)425 # case.set_option('mc_rpv_file',io.IOBase)426 case.set_option('mc_rpv_spectral_file',io.IOBase)427 case.set_option('mc_triangular_surface_file',io.IOBase)428 case.set_option('bpdf_tsang_u10',5.,'BPDF_TSANG')...

Full Screen

Full Screen

curlcontrol.py

Source:curlcontrol.py Github

copy

Full Screen

...50 self.payload = ""51 self.header = StringIO()52 self.fakeheaders = fakeheaders53 self.headers = None54 self.set_option(pycurl.SSL_VERIFYHOST, 0)55 self.set_option(pycurl.SSL_VERIFYPEER, 0)56 self.set_option(pycurl.SSLVERSION, pycurl.SSLVERSION_SSLv3)57 self.set_option(pycurl.FOLLOWLOCATION, 0)58 self.set_option(pycurl.MAXREDIRS, 50)59 # this is 'black magic'60 self.set_option(pycurl.COOKIEFILE, '/dev/null')61 self.set_option(pycurl.COOKIEJAR, '/dev/null')62 self.set_timeout(30)63 self.set_option(pycurl.NETRC, 1)64 self.set_nosignals(1)65 def payload_callback(x):66 self.payload += x67 self.set_option(pycurl.WRITEFUNCTION, payload_callback)68 def header_callback(x):69 self.header.write(x)70 self.set_option(pycurl.HEADERFUNCTION, header_callback)71 def set_url(self, url):72 """73 Set the base url.74 """75 self.base_url = url76 self.set_option(pycurl.URL, self.base_url)77 return url78 def set_cookie(self, cookie):79 """80 Set the app cookie.81 """82 self.cookie = cookie83 self.dropcookie = dropcookie84 if dropcookie:85 self.set_option(pycurl.COOKIELIST, 'ALL')86 self.set_option(pycurl.COOKIE, None)87 else:88 self.set_option(pycurl.COOKIELIST, '')89 self.set_option(pycurl.COOKIE, self.cookie)90 return cookie91 def set_agent(self, agent):92 """93 Set the user agent.94 """95 self.agent = agent96 self.set_option(pycurl.USERAGENT, self.agent)97 return agent98 def set_referer(self, referer):99 """100 Set the referer.101 """102 self.referer = referer103 self.set_option(pycurl.REFERER, self.referer)104 return referer105 def set_headers(self, headers):106 """107 Set extra headers.108 """109 self.headers = headers110 self.headers = self.headers.split("\n")111 for headerValue in self.headers:112 header, value = headerValue.split(": ")113 if header and value:114 self.set_option(pycurl.HTTPHEADER, (header, value))115 return headers116 def set_proxy(self, ignoreproxy, proxy):117 """118 Set the proxy to use.119 """120 self.proxy = proxy121 self.ignoreproxy = ignoreproxy122 if ignoreproxy:123 self.set_option(pycurl.PROXY, "")124 else:125 self.set_option(pycurl.PROXY, self.proxy)126 return proxy127 def set_option(self, *args):128 """129 Set the given option.130 """131 apply(self.handle.setopt, args)132 def set_verbosity(self, level):133 """134 Set the verbosity level.135 """136 self.set_option(pycurl.VERBOSE, level)137 def set_nosignals(self, signals="1"):138 """139 Disable signals.140 curl will be using other means besides signals to timeout141 """142 self.signals = signals143 self.set_option(pycurl.NOSIGNAL, self.signals)144 return signals145 def set_tcp_nodelay(self, tcp_nodelay):146 """147 Set the TCP_NODELAY option.148 """149 self.tcp_nodelay = tcp_nodelay150 self.set_option(pycurl.TCP_NODELAY, tcp_nodelay)151 return tcp_nodelay152 def set_timeout(self, timeout):153 """154 Set timeout for requests.155 """156 self.set_option(pycurl.CONNECTTIMEOUT,timeout)157 self.set_option(pycurl.TIMEOUT, timeout)158 return timeout159 def set_follow_redirections(self, followred, fli):160 """161 Set follow locations parameters to follow redirection pages (302)162 """163 self.followred = followred164 self.fli = fli165 if followred:166 self.set_option(pycurl.FOLLOWLOCATION , 1)167 self.set_option(pycurl.MAXREDIRS, 50)168 if fli:169 self.set_option(pycurl.MAXREDIRS, fli)170 else:171 self.set_option(pycurl.FOLLOWLOCATION , 0)172 return followred173 def do_head_check(self, urls):174 """175 Send a HEAD request before to start to inject to verify stability of the target176 """177 for u in urls:178 self.set_option(pycurl.URL, u) 179 self.set_option(pycurl.NOBODY,1)180 self.set_option(pycurl.FOLLOWLOCATION, 0)181 self.set_option(pycurl.MAXREDIRS, 50)182 self.set_option(pycurl.SSL_VERIFYHOST, 0)183 self.set_option(pycurl.SSL_VERIFYPEER, 0)184 if self.fakeheaders:185 from XSSer.randomip import RandomIP186 if self.xforw:187 generate_random_xforw = RandomIP()188 xforwip = generate_random_xforw._generateip('')189 xforwfakevalue = ['X-Forwarded-For: ' + str(xforwip)]190 if self.xclient:191 generate_random_xclient = RandomIP()192 xclientip = generate_random_xclient._generateip('')193 xclientfakevalue = ['X-Client-IP: ' + str(xclientip)]194 if self.xforw:195 self.set_option(pycurl.HTTPHEADER, self.fakeheaders + xforwfakevalue)196 if self.xclient:197 self.set_option(pycurl.HTTPHEADER, self.fakeheaders + xforwfakevalue + xclientfakevalue)198 elif self.xclient:199 self.set_option(pycurl.HTTPHEADER, self.fakeheaders + xclientfakevalue)200 if self.headers:201 self.fakeheaders = self.fakeheaders + self.headers202 self.set_option(pycurl.HTTPHEADER, self.fakeheaders)203 if self.agent:204 self.set_option(pycurl.USERAGENT, self.agent)205 if self.referer:206 self.set_option(pycurl.REFERER, self.referer)207 if self.proxy:208 self.set_option(pycurl.PROXY, self.proxy)209 if self.ignoreproxy:210 self.set_option(pycurl.PROXY, "")211 if self.timeout:212 self.set_option(pycurl.CONNECTTIMEOUT, self.timeout)213 self.set_option(pycurl.TIMEOUT, self.timeout)214 if self.signals:215 self.set_option(pycurl.NOSIGNAL, self.signals)216 if self.tcp_nodelay:217 self.set_option(pycurl.TCP_NODELAY, self.tcp_nodelay)218 if self.cookie:219 self.set_option(pycurl.COOKIE, self.cookie)220 try:221 self.handle.perform()222 except:223 return224 if str(self.handle.getinfo(pycurl.HTTP_CODE)) in ["302", "301"]:225 self.set_option(pycurl.FOLLOWLOCATION, 1)226 def __request(self, relative_url=None):227 """228 Perform a request and returns the payload.229 """230 if self.fakeheaders:231 from XSSer.randomip import RandomIP232 if self.xforw:233 """234 Set the X-Forwarded-For to use.235 """236 generate_random_xforw = RandomIP()237 xforwip = generate_random_xforw._generateip('')238 #xforwip = '127.0.0.1'239 xforwfakevalue = ['X-Forwarded-For: ' + str(xforwip)]240 if self.xclient:241 """ 242 Set the X-Client-IP to use.243 """244 generate_random_xclient = RandomIP()245 xclientip = generate_random_xclient._generateip('')246 #xclientip = '127.0.0.1'247 xclientfakevalue = ['X-Client-IP: ' + str(xclientip)]248 if self.xforw:249 self.set_option(pycurl.HTTPHEADER, self.fakeheaders + xforwfakevalue)250 if self.xclient:251 self.set_option(pycurl.HTTPHEADER, self.fakeheaders + xforwfakevalue + xclientfakevalue)252 elif self.xclient:253 self.set_option(pycurl.HTTPHEADER, self.fakeheaders + xclientfakevalue)254 if self.headers:255 # XXX sanitize user input256 self.fakeheaders = self.fakeheaders + self.headers257 self.set_option(pycurl.HTTPHEADER, self.fakeheaders)258 if self.agent:259 self.set_option(pycurl.USERAGENT, self.agent)260 if self.referer:261 self.set_option(pycurl.REFERER, self.referer)262 if self.proxy:263 self.set_option(pycurl.PROXY, self.proxy)264 if self.ignoreproxy:265 self.set_option(pycurl.PROXY, "")266 if relative_url:267 self.set_option(pycurl.URL,os.path.join(self.base_url,relative_url))268 if self.timeout:269 self.set_option(pycurl.CONNECTTIMEOUT, self.timeout)270 self.set_option(pycurl.TIMEOUT, self.timeout)271 if self.signals:272 self.set_option(pycurl.NOSIGNAL, self.signals)273 if self.tcp_nodelay:274 self.set_option(pycurl.TCP_NODELAY, self.tcp_nodelay)275 if self.cookie:276 self.set_option(pycurl.COOKIE, self.cookie)277 if self.followred:278 self.set_option(pycurl.FOLLOWLOCATION , 1)279 self.set_option(pycurl.MAXREDIRS, 50)280 if self.fli:281 self.set_option(pycurl.MAXREDIRS, int(self.fli))282 else:283 self.set_option(pycurl.FOLLOWLOCATION , 0)284 if self.fli:285 print "\n[E] You must launch --follow-redirects command to set correctly this redirections limit\n"286 return287 """ 288 Set the HTTP authentication method: Basic, Digest, GSS, NTLM or Certificate289 """290 if self.atype and self.acred:291 atypelower = self.atype.lower()292 if atypelower not in ( "basic", "digest", "ntlm", "gss" ):293 print "\n[E] HTTP authentication type value must be: Basic, Digest, GSS or NTLM\n"294 return295 acredregexp = re.search("^(.*?)\:(.*?)$", self.acred)296 if not acredregexp:297 print "\n[E] HTTP authentication credentials value must be in format username:password\n"298 return299 user = acredregexp.group(1)300 password = acredregexp.group(2)301 self.set_option(pycurl.USERPWD, "%s:%s" % (user,password))302 if atypelower == "basic":303 self.set_option(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)304 elif atypelower == "digest":305 self.set_option(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST)306 elif atypelower == "ntlm":307 self.set_option(pycurl.HTTPAUTH, pycurl.HTTPAUTH_NTLM)308 elif atypelower == "gss":309 self.set_option(pycurl.HTTPAUTH, pycurl.HTTPAUTH_GSSNEGOTIATE)310 else:311 self.set_option(pycurl.HTTPAUTH, None)312 self.set_option(pycurl.HTTPHEADER, ["Accept:"])313 elif self.atype and not self.acred:314 print "\n[E] You specified the HTTP authentication type, but did not provide the credentials\n"315 return316 elif not self.atype and self.acred:317 print "\n[E] You specified the HTTP authentication credentials, but did not provide the type\n"318 return319 #if self.acert:320 # acertregexp = re.search("^(.+?),\s*(.+?)$", self.acert)321 # if not acertregexp:322 # print "\n[E] HTTP authentication certificate option must be 'key_file,cert_file'\n"323 # return324 # # os.path.expanduser for support of paths with ~325 # key_file = os.path.expanduser(acertregexp.group(1))326 # cert_file = os.path.expanduser(acertregexp.group(2))327 # self.set_option(pycurl.SSL_VERIFYHOST, 0)328 # self.set_option(pycurl.SSL_VERIFYPEER, 1)329 # self.set_option(pycurl.SSH_PUBLIC_KEYFILE, key_file)330 # self.set_option(pycurl.CAINFO, cert_file)331 # self.set_option(pycurl.SSLCERT, cert_file)332 # self.set_option(pycurl.SSLCERTTYPE, 'p12')333 # self.set_option(pycurl.SSLCERTPASSWD, '1234')334 # self.set_option(pycurl.SSLKEY, key_file)335 # self.set_option(pycurl.SSLKEYPASSWD, '1234')336 # for file in (key_file, cert_file):337 # if not os.path.exists(file):338 # print "\n[E] File '%s' doesn't exist\n" % file339 # return340 341 self.set_option(pycurl.SSL_VERIFYHOST, 0)342 self.set_option(pycurl.SSL_VERIFYPEER, 0)343 self.header.seek(0,0)344 self.payload = ""345 for count in range(0, self.retries):346 time.sleep(self.delay)347 if self.dropcookie:348 self.set_option(pycurl.COOKIELIST, 'ALL')349 nocookie = ['Set-Cookie: ', '']350 self.set_option(pycurl.HTTPHEADER, self.fakeheaders + nocookie)351 try:352 self.handle.perform()353 except:354 return355 return self.payload356 def get(self, url="", params=None):357 """358 Get a url.359 """360 if params:361 url += "?" + urllib.urlencode(params)362 self.set_option(pycurl.HTTPGET, 1)363 return self.__request(url)364 def post(self, cgi, params):365 """366 Post a url.367 """368 self.set_option(pycurl.POST, 1)369 self.set_option(pycurl.POSTFIELDS, params)370 return self.__request(cgi)371 def body(self):372 """373 Get the payload from the latest operation.374 """375 return self.payload376 def info(self):377 """378 Get an info dictionary from the selected url.379 """380 self.header.seek(0,0)381 url = self.handle.getinfo(pycurl.EFFECTIVE_URL)382 if url[:5] == 'http:':383 self.header.readline()...

Full Screen

Full Screen

test_options.py

Source:test_options.py Github

copy

Full Screen

...4curdir = os.path.dirname(__file__)5output_dir = os.path.join(curdir, 'test_output')6class Test_options(unittest.TestCase):7 def tearDown(self):8 ql.set_option('log_level', 'LOG_NOTHING')9 ql.set_option('optimize', 'no')10 ql.set_option('scheduler', 'ALAP')11 ql.set_option('scheduler_uniform', 'no')12 ql.set_option('use_default_gates', 'yes')13 ql.set_option('decompose_toffoli', 'no')14 def test_set_all_options(self):15 # try to set all legal values of options16 ql.set_option('log_level', 'LOG_NOTHING')17 ql.set_option('log_level', 'LOG_CRITICAL')18 ql.set_option('log_level', 'LOG_ERROR')19 ql.set_option('log_level', 'LOG_WARNING')20 ql.set_option('log_level', 'LOG_INFO')21 ql.set_option('log_level', 'LOG_DEBUG')22 ql.set_option('output_dir', output_dir)23 ql.set_option('optimize', 'yes')24 ql.set_option('optimize', 'no')25 ql.set_option('scheduler', 'ALAP')26 ql.set_option('scheduler', 'ASAP')27 ql.set_option('scheduler_uniform', 'yes')28 ql.set_option('scheduler_uniform', 'no')29 ql.set_option('use_default_gates', 'yes')30 ql.set_option('use_default_gates', 'no')31 32 ql.set_option('decompose_toffoli', 'no')33 ql.set_option('decompose_toffoli', 'NC')34 ql.set_option('decompose_toffoli', 'MA')35 def test_nok(self):36 # supress error printing first as the following will print errors37 ql.set_option('log_level', 'LOG_NOTHING')38 # illegal values for options should raise errors39 with self.assertRaises(Exception) as cm:40 ql.set_option('optimize', 'nope')41 self.assertEqual(str(cm.exception), 'Error parsing options. The value nope is not an allowed value for --optimize !')42 with self.assertRaises(Exception) as cm:43 ql.set_option('scheduler', 'best')44 self.assertEqual(str(cm.exception), 'Error parsing options. The value best is not an allowed value for --scheduler !')45 def test_get_values(self):46 # try to set a legal value and then test if it is indeed set47 ql.set_option('log_level', 'LOG_INFO')48 self.assertEqual(ql.get_option('log_level'), 'LOG_INFO')49 ql.set_option('output_dir', output_dir)50 self.assertEqual(ql.get_option('output_dir'), output_dir)51 ql.set_option('optimize', 'yes')52 self.assertEqual(ql.get_option('optimize'), 'yes')53 54 ql.set_option('scheduler', 'ALAP')55 self.assertEqual(ql.get_option('scheduler'), 'ALAP')56 ql.set_option('scheduler_uniform', 'yes')57 self.assertEqual(ql.get_option('scheduler_uniform'), 'yes')58 ql.set_option('use_default_gates', 'yes')59 self.assertEqual(ql.get_option('use_default_gates'), 'yes')60 61 ql.set_option('decompose_toffoli', 'NC')62 self.assertEqual(ql.get_option('decompose_toffoli'), 'NC')63 def test_default_scheduler(self):64 # tests if 'ALAP' is indeed the default scheduler policy65 self.assertEqual('ALAP', ql.get_option('scheduler'),66 'ALAP is not the default scheduler!')67if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful