def replace_nonprintables(string):
 new_string = ''
 modified = 0
 for c in string:
  o = ord(c)
  if (o <= 31):
   new_string += ('^' + chr((ord('@') + o)))
   modified += 1
  elif (o == 127):
   new_string += '^?'
   modified += 1
  else:
   new_string += c
 if (modified and (S3.Config.Config().urlencoding_mode != 'fixbucket')):
  warning(('%d non-printable characters replaced in: %s' % (modified, new_string)))
 return new_string

def replace_nonprintables ( string ) : new_string = '' modified = 0 for c in string : o = ord ( c ) if ( o <= 31 ) : new_string += ( '^' + chr ( ( ord ( '@' ) + o ) ) ) modified += 1 elif ( o == 127 ) : new_string += '^?' modified += 1 else : new_string += c if ( modified and ( S3 . Config . Config ( ) . urlencoding_mode != 'fixbucket' ) ) : warning ( ( '%d non-printable characters replaced in: %s' % ( modified , new_string ) ) ) return new_string
replace_nonprintables replaces all non-printable characters ch in string where ord <= 26 with ^@ .