def sfdisk_escape_string(value: str):
    chars = []
    for char in map(chr, value.encode("utf-8")):
        if not isprint(char) or iscntrl(char) or char in ['"', "\\", "`", "$"]:
            hex_val = hex(int(char))
            chars.append(f"\\x{hex_val}")
        else:
            chars.append(char)
    return '"' + "".join(chars) + '"'
예제 #2
0
 def handleEvent(self, event: Event):
     if self.state & sfSelected and event.what == evKeyDown:
         key = event.keyDown.charScan.charCode
         if not iscntrl(key):
             if self.newCase:
                 key = self.newCase(key)
             if self.keySet and not re.match(self.keySet, key):
                 logger.info('No regex match')
                 Screen.beep()
                 self.clearEvent(event)
                 return
     super().handleEvent(event)
예제 #3
0
def scrub_literal(value):
    """
    Scrubs control characters from the incoming values to remove
    things like form feeds (\f) and line breaks (\n) which might 
    cause problems with Jena.

    Data with these characters was found in the Backstage data.
    """
    from curses import ascii
    import unicodedata
    if not value:
        return
    if (type(value) == long) or (type(value) == int):
        return value
    n = ''.join([c for c in value if not ascii.iscntrl(c)\
                if not ascii.isctrl(c)])
    #n = ''.join(new)
    n = n.replace('"', '')
    n = n.replace('\ufffd', '')
    n = clean_text(n)
    if type(n) != unicode:
        n = unicode(n, errors='replace')
    return n.strip()
예제 #4
0
                     break
                 except:
                     continue
         break
 header_pos = sorted(header_pos,key=lambda hp: hp["pos"])
 #print header_pos
 if in_header:
     previous_line_header = True
     in_header = False
     if len(wsa_head) == len(wsa_first):
         #print wsa_head
         wsa_first = wsa_head
     continue
 else:
     previous_line_header = False
 if len(line) > 0 and iscntrl(line[0]):
     continue
 # check if line contains a tendering option at beginning or under "Procedure"
 for opt in tendering_opts:
     if procedure_pos < 20 and opt in line[0:procedure_pos+16] or opt in line[procedure_pos:procedure_pos+16]:
         tendering_opt = opt
         break
 # If this line starts with text, but the previous is empty or starts with space or contains a tendering opts word in the first 20
 if len(wsa) > 0 and wsa[0][0] > 0 and (len(ws[i-1]) == 0 or (len(ws[i-1]) > 0 and ws[i-1][0][0] == 0) or tendering_opt is not None):
     if not started_infos:
         started_infos = True
     #print str(i) + " " + line + " " + str(wsa)
     if entry is None or entry is not None and len(entry) > 0:
         if entry is not None:
             e_not_empty = 0
             for e in entry:
예제 #5
0
                     break
                 except:
                     continue
         break
 header_pos = sorted(header_pos, key=lambda hp: hp["pos"])
 #print header_pos
 if in_header:
     previous_line_header = True
     in_header = False
     if len(wsa_head) == len(wsa_first):
         #print wsa_head
         wsa_first = wsa_head
     continue
 else:
     previous_line_header = False
 if len(line) > 0 and iscntrl(line[0]):
     continue
 # check if line contains a tendering option at beginning or under "Procedure"
 for opt in tendering_opts:
     if procedure_pos < 20 and opt in line[
             0:procedure_pos +
             16] or opt in line[procedure_pos:procedure_pos + 16]:
         tendering_opt = opt
         break
 # If this line starts with text, but the previous is empty or starts with space or contains a tendering opts word in the first 20
 if len(wsa) > 0 and wsa[0][0] > 0 and (len(
         ws[i - 1]) == 0 or (len(ws[i - 1]) > 0 and ws[i - 1][0][0] == 0)
                                        or tendering_opt is not None):
     if not started_infos:
         started_infos = True
     #print str(i) + " " + line + " " + str(wsa)