@@ -1471,7 +1471,7 @@ def file_has_crlf_endings(self, src):
1471
1471
content = src_file .read (1024 )
1472
1472
1473
1473
while content :
1474
- # In EBCDIC , \r is bytes 0d
1474
+ # In UTF-8 , \r is bytes 0d
1475
1475
if b'\x0d ' in content :
1476
1476
return True
1477
1477
content = src_file .read (1024 )
@@ -3183,8 +3183,8 @@ def allocate_destination_data_set(
3183
3183
3184
3184
3185
3185
def normalize_line_endings (src , encoding = None ):
3186
- """Normalizes src's encoding to IBM-037 (a dataset's default) and then normalizes
3187
- its line endings to LF.
3186
+ """Normalizes src's encoding to UTF-8, then normalizes
3187
+ its line endings to LF and after encodes back as per encoding param .
3188
3188
3189
3189
Parameters
3190
3190
----------
@@ -3201,7 +3201,7 @@ def normalize_line_endings(src, encoding=None):
3201
3201
# Before copying into a destination dataset, we'll make sure that
3202
3202
# the source file doesn't contain any carriage returns that would
3203
3203
# result in empty records in the destination.
3204
- # Due to the differences between encodings, we'll normalize to IBM-037
3204
+ # Due to the differences between encodings, we'll normalize to UTF-8
3205
3205
# before checking the EOL sequence.
3206
3206
enc_utils = encode .EncodeUtils ()
3207
3207
src_tag = enc_utils .uss_file_tag (src )
@@ -3211,25 +3211,40 @@ def normalize_line_endings(src, encoding=None):
3211
3211
# This should only be true when src is a remote file and no encoding
3212
3212
# was specified by the user.
3213
3213
if not encoding :
3214
- encoding = {"from" : encode .Defaults .get_default_system_charset ()}
3215
- src_tag = encoding ["from" ]
3216
-
3217
- if src_tag != "IBM-037" :
3214
+ src_tag = encode .Defaults .get_default_system_charset ()
3215
+ else :
3216
+ src_tag = encoding ["to" ]
3217
+ is_convertedto_utf8 = False
3218
+ if src_tag != "UTF-8" :
3218
3219
fd , converted_src = tempfile .mkstemp (dir = os .environ ['TMPDIR' ])
3219
3220
os .close (fd )
3220
3221
3221
3222
enc_utils .uss_convert_encoding (
3222
3223
src ,
3223
3224
converted_src ,
3224
3225
src_tag ,
3225
- "IBM-037 "
3226
+ "UTF-8 "
3226
3227
)
3227
- copy_handler ._tag_file_encoding (converted_src , "IBM-037 " )
3228
+ copy_handler ._tag_file_encoding (converted_src , "UTF-8 " )
3228
3229
src = converted_src
3230
+ is_convertedto_utf8 = True
3229
3231
3230
3232
if copy_handler .file_has_crlf_endings (src ):
3231
3233
src = copy_handler .create_temp_with_lf_endings (src )
3232
3234
3235
+ if is_convertedto_utf8 :
3236
+ fd , converted_source = tempfile .mkstemp (dir = os .environ ['TMPDIR' ])
3237
+ os .close (fd )
3238
+
3239
+ enc_utils .uss_convert_encoding (
3240
+ src ,
3241
+ converted_source ,
3242
+ "UTF-8" ,
3243
+ src_tag
3244
+ )
3245
+ copy_handler ._tag_file_encoding (converted_src , src_tag )
3246
+ src = converted_source
3247
+
3233
3248
return src
3234
3249
3235
3250
@@ -3346,6 +3361,17 @@ def run_module(module, arg_def):
3346
3361
# Verify the validity of module args. BetterArgParser raises ValueError
3347
3362
# when a parameter fails its validation check
3348
3363
# ********************************************************************
3364
+ originalsrc = module .params .get ('src' )
3365
+ originaldest = module .params .get ('dest' )
3366
+ issrcpoundexists = False
3367
+ isdestpoundexists = False
3368
+ # Replacing pound with dollar in src and dest if exists
3369
+ if "£" in module .params ["src" ]:
3370
+ issrcpoundexists = True
3371
+ module .params ["src" ] = module .params ["src" ].replace ("£" , "$" )
3372
+ if "£" in module .params ["dest" ]:
3373
+ isdestpoundexists = True
3374
+ module .params ["dest" ] = module .params ["dest" ].replace ("£" , "$" )
3349
3375
try :
3350
3376
parser = better_arg_parser .BetterArgParser (arg_def )
3351
3377
parser .parse_args (module .params )
@@ -3952,8 +3978,8 @@ def run_module(module, arg_def):
3952
3978
3953
3979
res_args .update (
3954
3980
dict (
3955
- src = module . params . get ( 'src' ) if is_src_alias else src ,
3956
- dest = module . params . get ( 'dest' ) if is_dest_alias else dest ,
3981
+ src = originalsrc if issrcpoundexists or is_src_alias else src ,
3982
+ dest = originaldest if isdestpoundexists or is_dest_alias else dest ,
3957
3983
ds_type = dest_ds_type ,
3958
3984
dest_exists = dest_exists ,
3959
3985
backup_name = backup_name ,
0 commit comments