Look at URLEncoder/URLDecoder. They're Java APIs but you can use them from 
Groovy.

-- 
Rachel Greenham
[email protected]

> On 23 Sep 2021, at 13:32, James McMahon <[email protected]> wrote:
> 
> Addendum, these examples illustrate what the use of encode and quote is doing 
> for us in the legacy python...
> 
> from urllib.parse import quote
> myString = "/Ted \\Las$o & Roy Kent, @ AFC Richmond, öööö !"
> print(myString) # result is /Ted \Las$o & Roy Kent, @ AFC Richmond, öööö !
> 
> myString_quoted = quote(myString)
> print(myString_quoted) # result is 
> /Ted%20%5CLas%24o%20%26%20Roy%20Kent%2C%20%40%20AFC%20Richmond%2C%20%C3%B6%C3%B6%C3%B6%C3%B6%20%21
> 
> myString_encoded = myString.encode('utf8')
> print(myString_encoded) # result is b'/Ted \\Las$o & Roy Kent, @ AFC 
> Richmond, \xc3\xb6\xc3\xb6\xc3\xb6\xc3\xb6 !'
> 
> myString_encoded_then_quoted = quote(myString.encode('utf8'))
> print(myString_encoded_then_quoted) # result is same as when we just 
> quote(myString)
> 
> myString_quoted_then_encoded = quote(myString).encode('utf8')
> print(myString_quoted_then_encoded) # result is 
> b'/Ted%20%5CLas%24o%20%26%20Roy%20Kent%2C%20%40%20AFC%20Richmond%2C%20%C3%B6%C3%B6%C3%B6%C3%B6%20%21'
> 
> On Thu, Sep 23, 2021 at 6:24 AM James McMahon <[email protected] 
> <mailto:[email protected]>> wrote:
> Hello. I am new to groovy, assigned an effort to convert legacy python 
> scripts to groovy replacements. We are doing this in an effort to decouple 
> from dependencies on the jython engine in NiFi for scripts we run from its 
> ExecuteScript processor.
> 
> In one of these python scripts, this gets done to an encoded string that 
> represents a disk file path:
> 
> import urllib
> .
> .
> .
> result['fileURL'] = urllib.quote(temp_result['fileURL'].encode('utf8'))
> 
> Based on my initial research (though very limited understanding), it appears 
> that the urllib.quote() is intended to quote reserved characters in a path. I 
> haven't been able to find the function that serves an equivalent purpose in 
> Groovy. Can anyone show me how this should be accomplished?
> 
> I should add that I have successfully replaced the python dictionary 
> structures you see above and calls to manipulate the same with Groovy Map 
> operations.
> 
> Thanks in advance for any help.  - Jim

Reply via email to