예제 #1
0
 def __init__(self, width):
     TextWrapper.__init__(
         self, width,
         expand_tabs=False,
         replace_whitespace=False,
         drop_whitespace=False
     )
예제 #2
0
 def __init__(self, font, pixel_width, *args, **kwargs):
     TextWrapper.__init__(self, *args, **kwargs)
     self.font = font
     self.pixel_width = pixel_width
     # find widths of the printable ASCII characters
     self.char_pwid = [0] * 32 + \
                      [ font.measure(chr(n)) for n in range(32, 127) ]
     self.max_pwid = max(self.char_pwid)
     # map all non-ASCII characters (Unicode) to max width
     self.char_pwid.append(self.max_pwid)
     self.uchar_pwid = {}
     for c in (null_word_symb, clue_separator):
         self.uchar_pwid[ord(c)] = font.measure(c)
예제 #3
0
 def __init__(self, font, pixel_width, *args, **kwargs):
     TextWrapper.__init__(self, *args, **kwargs)
     self.font = font
     self.pixel_width = pixel_width
     # find widths of the printable ASCII characters
     self.char_pwid = [0] * 32 + \
                      [ font.measure(chr(n)) for n in range(32, 127) ]
     self.max_pwid = max(self.char_pwid)
     # map all non-ASCII characters (Unicode) to max width
     self.char_pwid.append(self.max_pwid)
     self.uchar_pwid = {}
     for c in (null_word_symb, clue_separator):
         self.uchar_pwid[ord(c)] = font.measure(c)
예제 #4
0
 def __init__(self,
              width=70,
              initial_indent="",
              subsequent_indent="",
              expand_tabs=True,
              replace_whitespace=True,
              fix_sentence_endings=False,
              break_long_words=True,
              drop_whitespace=True,
              break_on_hyphens=True,
              font=None):
     TextWrapper.__init__(self, width, initial_indent, subsequent_indent,
                          expand_tabs, replace_whitespace,
                          fix_sentence_endings, break_long_words,
                          drop_whitespace, break_on_hyphens)
     self._font = font
예제 #5
0
    def __init__(self, width=72, indent_re=r"^\s*(#+|//+|;+)?\s*", fix_sentence_endings=False, break_long_words=True):
        """ Init instance, use only subset of text wrapper options 

        Disabled TextWrapper options:
         - Indents -- should not be used, because this wrapper set them
                      automatically from the text.
         - expand_tabs -- Should not be used in code context.
         - replace_whitespace -- same, don't do things behind the back
        """
        TextWrapper.__init__(
            self,
            width=width,
            expand_tabs=False,
            replace_whitespace=False,
            fix_sentence_endings=fix_sentence_endings,
            break_long_words=break_long_words,
        )

        self.indent_re = re.compile(indent_re, re.UNICODE)
예제 #6
0
    def __init__(self,
                 width=72,
                 indent_re=r'^\s*(#+|//+|;+)?\s*',
                 fix_sentence_endings=False,
                 break_long_words=True):
        """ Init instance, use only subset of text wrapper options 

        Disabled TextWrapper options:
         - Indents -- should not be used, because this wrapper set them
                      automatically from the text.
         - expand_tabs -- Should not be used in code context.
         - replace_whitespace -- same, don't do things behind the back
        """
        TextWrapper.__init__(self,
                             width=width,
                             expand_tabs=False,
                             replace_whitespace=False,
                             fix_sentence_endings=fix_sentence_endings,
                             break_long_words=break_long_words)
        
        self.indent_re = re.compile(indent_re, re.UNICODE)
예제 #7
0
    def __init__(self, width: Optional[int] = None, subsequent_indent: str = ""):
        """

        :param width:             wrap width. Defaults to environment variable
                                  COLUMNS (minus 1), or 79.
        :param subsequent_indent: indent prefix for subsequent lines. Defaults
                                  to empty string.
        """
        if not width:
            columns = os.environ.get("COLUMNS", "80")
            try:
                width = int(columns) - 1
            except ValueError:
                print(
                    f'*** Ignoring non-numeric COLUMNS value of "{columns}"". '
                    "Defaulting to 80.",
                    file=sys.stderr,
                )
                os.environ["COLUMNS"] = "80"
                width = 79

        TextWrapper.__init__(self, width=width, subsequent_indent=subsequent_indent)