I need to get the filename out of an File-Object. However every method I use ends up in a different result when it comes to special cases like these:
Example 1: Bildschirmfoto 2017-03-14 um 21.28.42.png
Example 2: Jagdfasan+1+m%C3%A4nnl..jpg
There are different object properties to get a filename of an object. See https://estk.aenhancers.com/3%20-%20File%20System%20Access/file-object.html
i.e. when I try file.fsName I get
Example 1: Bildschirmfoto 2017-03-14 um 21.28.42.png (correct)
Example 2: Jagdfasan+1+männl..jpg (wrong)
but when I use file.name I get
Example 1: Bildschirmfoto%202017-03-14%20um%2021.28.42.png (wrong)
Example 2: Jagdfasan+1+m%C3%A4nnl..jpg (correct)
Here is a simple script that outputs the paths of a selected file using File.decode(file.name)
function rei_Testfunction() {
// Testfunction
var file = File.openDialog("Choose File...");
if(file === null){
}else{
alert("File.decode(file.name): " + File.decode(file.name) + "\n");
}
}
rei_Testfunction();
I expect to get the real filename for further operations and not some decoded/encoded variations of it.
Related
I have a json output (y) like this below.
{
"WebACL":{
"Name":"aBlockKnownBadInputs-WebAcl",
"Id":"4312a5d0-9878-4feb-a083-09d7a9cfcfbb",
"ARN":"arn:aws:wafv2:us-east-1:100467320728:regional/webacl/aBlockKnownBadInputs-WebAcl/4312a5d0-9878-4feb-a083-09d7a9cfcfbb",
"DefaultAction":{
"Allow":{
}
},
"Description":"",
"Rules":[
{
"Name":"AWS-AWSManagedRulesKnownBadInputsRuleSet",
"Priority":500,
"Statement":{
"ManagedRuleGroupStatement":{
"VendorName":"AWS",
"Name":"AWSManagedRulesKnownBadInputsRuleSet"
}
},
"OverrideAction":{
"None":{
}
},
"VisibilityConfig":{
"SampledRequestsEnabled":true,
"CloudWatchMetricsEnabled":true,
"MetricName":"AWS-AWSManagedRulesKnownBadInputsRuleSet"
}
}
]
}
}
I want to extract "AWS-AWSManagedRulesKnownBadInputsRuleSet" from the section:-
"Name":"AWS-AWSManagedRulesKnownBadInputsRuleSet",
"Priority":500,
"Statement":{
"ManagedRuleGroupStatement":{
"VendorName":"AWS",
"Name":"AWSManagedRulesKnownBadInputsRuleSet"*
At the minute my code is returning a key error:
KeyError: 'Rules[].Statement[].ManagedRuleGroupStatement[].Name'
The format of this line is clearly wrong, but I don't know why.
ruleset = y['Rules[].Statement[].ManagedRuleGroupStatement[].Name']
My code block:
respons = client.get_web_acl(Name=(acl),Scope='REGIONAL',Id=(ids))
for y in response['WebACLs']:
ruleset = y['Rules[].Statement[].ManagedRuleGroupStatement[].Name']
Does anyone know what I'm doing wrong here?
UPDATE :- In case anyone else comes up against this problem, I fixed this by doing it a slightly different way.
#Requesting the info from AWS via get_web_acl request
respons = client.get_web_acl(Name=(acl),Scope='REGIONAL',Id=(ids))
#Converting the dict output to a string to make it searchable
result = json.dumps(respons)
#Defining what I want to search for
fullstring = "AWS-AWSManagedRulesKnownBadInputsRuleSet"
#Searching the output & printing the result: if = true / else = false
if fullstring in result:
print("Found WAF ruleset: AWS-AWSManagedRulesKnownBadInputsRuleSet!")
else:
print("WAF ruleset not found!")
Also, as part of my research I found a cool thing called jello.
(https://github.com/kellyjonbrazil/jello).
jello is similar to jq in that it processes JSON and JSON Lines data except it uses standard python dict and list syntax.
So, I copied my json into a file called file.json
Ran cat file.json | jello -s to print a grep-able schema by using the -s option
Found the bit I was interested in - in my case the name of the ManagedRuleGroupStatement and ran the following:
cat file.json | jello -s _.WebACL.Rules[0].Statement.ManagedRuleGroupStatement.Name
This gave me exactly what I wanted!
It doesn't work inside a python script but was something new and interesting to learn!
I am using free version of soapui. In my load test, I want to read request field value from a text file. The file looks like following
0401108937
0401109140
0401109505
0401110330
0401111204
0401111468
0401111589
0401111729
0401111768
In load test, for each request I want to read this file sequentially. I am using the code mentioned in Unique property per SoapUI request using groovy to read the file. How can I use the values from the file in a sequential manner?
I have following test setup script to read the file
def projectDir = context.expand('${projectDir}') + File.separator
def dataFile = "usernames.txt"
try
{
File file = new File(projectDir + dataFile)
context.data = file.readLines()
context.dataCount = context.data.size
log.info " data count" + context.dataCount
context.index = 0; //index to read data array in sequence
}
catch (Exception e)
{
testRunner.fail("Failed to load " + dataFile + " from project directory.")
return
}
In my test, I have following script as test step. I want to read the current index record from array and then increment the index value
def randUserAccount = context.data.get(context.index);
context.setProperty("randUserAccount", randUserAccount)
context.index = ((int)context.index) + 1;
But with this script, I always get 2nd record of the array. The index value is not incrementing.
You defined the variable context.index to 0 and just do +1
You maybe need a loop to read all values.
something like this :
for(int i=0; i <context.data.size; i++){
context.setProperty("randUserAccount", i);
//your code
}
You can add this setup script to the setup script section for load test and access the values in the groovy script test step using:
context.LoadTestContext.index =((int)context.LoadTestContext.index)+1
This might be a late reply but I was facing the same problem for my load testing for some time. Using index as global property solved the issue for me.
Index is set as -1 initially. The below code would increment the index by 1, set the incremented value as global property and then pick the context data for that index.
<confirmationNumber>${=com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "index", (com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "index" ).toLong()+1 ).toString()); return (context.data.get( (com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "index" )).toInteger())) }</confirmationNumber>
if I save the lines below and run like ./node saved.js
var that = this;
that.val1 = 109;
var f1 = function(){return this;}
var f2 = function(){return this;}
var that1 = f1();
var that2 = f2();
console.log(that1.val1)//undefined
that1.val2=111;
console.log(that2.val2)//111
I get this result
undefined
111
But if I paste it to already started shell ./node, I get
...
...
> console.log(that1.val1)//undefined
109
undefined
> that1.val2=111;
111
> console.log(that2.val2)//111
111
Why is the output of the first console.log different?
When you run it in the script, this inside of your functions refers to a different object than it does outside your functions. For example, I made this change to the beginning of your script:
var that = this;
console.log(this)
that.val1 = 109;
var f1 = function(){console.log(this); console.log("eq: " + (this === that));return this;}
When that second line executes running it as node test.js, I get an empty object, whereas then the one inside of f1 is executed a few lines deeper, it's a much different object.
When that's run from the Node REPL, I get an object matching the one from inside f1 in the node test.js version in both places. Thus, that.va1 = 109 is acting on different objects in the 2 cases and is why you see the difference.
Edit: And see Jonathan Lonowski's comment on the question for what the 2 different objects are.
I am trying to write output to a text file stored in my azure container.
Following is my woker role snippet for it :
string copyTemp="";
copyTemp += "hi" + "\n";
copyTemp += "hello" + "\n";
if (String.IsNullOrEmpty(copyTemp))
return;
using (var memoryStream = new MemoryStream())
{
memoryStream.Write(System.Text.Encoding.UTF8.GetBytes(copyTemp), 0, System.Text.Encoding.UTF8.GetBytes(copyTemp).Length);
memoryStream.Position = 0;
blockBlob.UploadFromStream(memoryStream);
}
Now, when i download and check my blob,the output doesn't feature a new line.
"hihello"
Does anyone have an idea,what's goin wrong ?
Have you tried using Environment.NewLine rather than adding "\n" to your strings?
It might just be that your "\n" is not a full new line in the place you are reading it. In windows I believe you need a "\r\n" to get a proper new line character.
You can read about the differences between new line (\n) and carriage return (\r) and which systems use which on Wikipedia but that clarifies h that windows uses a carriage return and a line feed to signify a new line.
So if you had downloaded your blob on a Mac or on Linux it probably would have displayed as you expected.
The best solution for C# is to use the static string property Environment.NewLine. You can use it for writing text content to files, to azure blobs, to console output, and you will never have to think whether it is \n or \r\n. In your case the code will be:
string copyTemp="";
copyTemp += "hi" + Environment.NewLine;
copyTemp += "hello" + Environment.NewLine;
I've been tasked with creating a new server modification for Crysis Wars. I have ran into a particular issue that it cannot read the old ban-file (this is required in order to keep the server consistent). The Lua code itself does not seem to have any errors, but it's just not getting any of the data.
Looking at the code I'm using for this below, can you find anything wrong with it?
This is the code I'm using for this:
function rX.CheckBanlist(player)
local Root = System.GetCVar("sys_root");
local File = ""..Root.."System/Bansystem/Raptor.xml";
local FileHnd = io.open(File, "r");
for line in FileHnd:lines() do
if (not string.find(line, "User:Read")) then
System.Log("[rX] File Read Error: System/Raptor/Banfile.xml, The contents are unexpected.");
return false;
end
local Msg, Date, Reason, Type, Domain = string.match(line, "User:Read( '(.*)', { Date='(.*)'; Reason='(.*)'; Typ='(.*)'; Info='(.*)'; } );");
local rldomain = g_gameRules.game:GetDomain(player.id);
if (Domain == rldomain) then
return true;
else
return false;
end
end
end
Also, the actual file reads as this, but I can't get the " to work in Lua properly. Could this be the issue?
User:Read( "Banned", { Date="31.03.2011"; Reason="WEBSTREAM"; Typ="Inetnum"; Info="COMPUTER.SED.gg"; } );
You may prefer using Lua's [[ for multiline string when you want to include quotes inside quotes etc.
Also, you'd have to escape the ( and ) while matching:
local Msg, Date, Reason, Type, Domain = line:match([[User:Read%( "(.-)", { Date="(.+)"; Reason="(.+)"; Typ="(.+)"; Info="(.+)"; } %);]])
And the results will be as expected: http://codepad.org/gN8kSL6H