示例#1
0
    def setUp(self):
        profiler.Profile_Set('ENCODING', locale.getpreferredencoding())

        self.app = common.EdApp(False)
        self.path = common.GetDataFilePath(u'test_read_utf8.txt')
        self.file = ed_txt.EdFile(self.path)
        self.mtime = ebmlib.GetFileModTime(self.path)

        self.rpath = common.GetDataFilePath(u'embedded_nulls.txt')
        self.rfile = ed_txt.EdFile(self.rpath)

        self.ipath = common.GetDataFilePath(u'image_test.png')
        self.img = ed_txt.EdFile(self.ipath)

        self.bpath = common.GetDataFilePath(u'test_read_utf8_bom.txt')
        self.utf8_bom_file = ed_txt.EdFile(self.bpath)
示例#2
0
 def testReadUTF32Bom(self):
     """Test reading a file that has a UTF32 BOM"""
     fname = common.GetDataFilePath('test_read_utf32_bom.txt')
     fileutf32 = ed_txt.EdFile(fname)
     data = fileutf32.Read()
     self.assertTrue(fileutf32.HasBom(), "UTF-32 BOM not detected!")
     self.assertTrue(fileutf32.Encoding in ("utf-32", "utf_32"),
                     "Incorrect Encoding detected: %s" % fileutf32.Encoding)
    def __init__(self,
                 parent,
                 id_=wx.ID_ANY,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=0):
        wx.stc.StyledTextCtrl.__init__(self, parent, id_, pos, size, style)
        ed_style.StyleMgr.__init__(self, self.GetStyleSheet())

        # Attributes
        self.file = ed_txt.EdFile()
        self._code = dict(
            compsvc=autocomp.AutoCompService.GetCompleter(self),
            synmgr=syntax.SyntaxMgr(ed_glob.CONFIG['CACHE_DIR']),
            keywords=[' '],
            comment=list(),
            clexer=None,  # Container lexer method
            indenter=None,  # Auto indenter
            lang_id=0)  # Language ID from syntax module

        self.vert_edit = vertedit.VertEdit(self, markerNumber=MARKER_VERT_EDIT)
        self._line_num = True  # Show line numbers
        self._last_cwidth = 1  # one pixel

        # Set Up Margins
        ## Outer Left Margin Bookmarks
        self.SetMarginType(MARK_MARGIN, wx.stc.STC_MARGIN_SYMBOL)
        self.SetMarginMask(MARK_MARGIN, EditraBaseStc.ED_STC_MASK_MARKERS)
        self.SetMarginSensitive(MARK_MARGIN, True)
        self.SetMarginWidth(MARK_MARGIN, 16)

        ## Middle Left Margin Line Number Indication
        self.SetMarginType(NUM_MARGIN, wx.stc.STC_MARGIN_NUMBER)
        self.SetMarginMask(NUM_MARGIN, 0)

        ## Inner Left Margin Setup Folders
        self.SetMarginType(FOLD_MARGIN, wx.stc.STC_MARGIN_SYMBOL)
        self.SetMarginMask(FOLD_MARGIN, wx.stc.STC_MASK_FOLDERS)
        self.SetMarginSensitive(FOLD_MARGIN, True)

        # Set Mac specific keybindings
        if wx.Platform == '__WXMAC__':
            for keys in _GetMacKeyBindings():
                self.CmdKeyAssign(*keys)

        # Set default EOL format
        if wx.Platform != '__WXMSW__':
            self.SetEOLMode(wx.stc.STC_EOL_LF)

        # Setup Auto-comp images
        # TODO: should be called on theme change messages
        self.RegisterImages()

        # Event Handlers
        self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy, self)
        self.Bind(wx.stc.EVT_STC_CHANGE, self.OnChanged)
        self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModified)
        self.Bind(wx.stc.EVT_STC_AUTOCOMP_SELECTION, self.OnAutoCompSel)
示例#4
0
 def testGetEncoding(self):
     """Test the encoding detection"""
     txt = self.file.Read()
     self.assertTrue(self.file.GetEncoding() == 'utf-8')
     fobj16 = ed_txt.EdFile(self.path_utf16)
     txt = fobj16.Read()
     enc = fobj16.GetEncoding()
     self.assertTrue(enc in ('utf-16', 'utf_16', 'utf_16_le', 'utf-16-le'),
                     "Encoding Found: %s" % enc)
示例#5
0
 def testReadNonPrintChars(self):
     """Test reading a plain text file that has a non printable
     character in it.
     """
     path = common.GetDataFilePath(u'non_print_char.txt')
     fileobj = ed_txt.EdFile(path)
     txt = fileobj.Read()
     self.assertTrue(type(txt) == types.UnicodeType)
     self.assertFalse(fileobj.IsRawBytes())
     self.assertFalse(fileobj.IsReadOnly())
示例#6
0
    def setUp(self):
        # NEED this otherwise GetApp calls fail for some yet to be
        # determined reason even though an App has been created earlier
        # in runUnitTests...
        self.app = common.EdApp(False)

        self.path = common.GetDataFilePath(u'test_read_utf8.txt')
        self.file = ed_txt.EdFile(self.path)
        self.mtime = ebmlib.GetFileModTime(self.path)

        self.path_utf16 = common.GetDataFilePath(u'test_read_utf16.txt')
        self.mtime_utf16 = ebmlib.GetFileModTime(self.path_utf16)

        self.path_utf16_big = common.GetDataFilePath(u'test_read_utf16_big.txt')

        self.ipath = common.GetDataFilePath(u'image_test.png')
        self.img = ed_txt.EdFile(self.ipath)

        self.bpath = common.GetDataFilePath(u'test_read_utf8_bom.txt')
        self.utf8_bom_file = ed_txt.EdFile(self.bpath)
示例#7
0
    def testIsRawBytes(self):
        """Test reading a file that can't be properly encoded and was
        read as raw bytes.

        """
        txt = self.file.Read()
        self.assertTrue(ebmlib.IsUnicode(txt))
        self.assertFalse(self.file.IsRawBytes())

        rpath = common.GetDataFilePath(u'embedded_nulls.txt')
        rfile = ed_txt.EdFile(rpath)
        txt = rfile.Read()
        self.assertTrue(ebmlib.IsUnicode(txt))
        self.assertFalse(rfile.IsRawBytes())

        bytes_value = self.img.Read()
        self.assertTrue(self.img.IsRawBytes())
示例#8
0
    def __init__(self,
                 parent,
                 id_,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 style=0):
        wx.stc.StyledTextCtrl.__init__(self, parent, id_, pos, size, style)
        ed_style.StyleMgr.__init__(self, self.GetStyleSheet())

        # Attributes
        self.file = ed_txt.EdFile()
        self._code = dict(
            compsvc=autocomp.AutoCompService.GetCompleter(self),
            synmgr=syntax.SyntaxMgr(ed_glob.CONFIG['CACHE_DIR']),
            keywords=[' '],
            comment=list(),
            clexer=None,  # Container lexer method
            indenter=None,  # Auto indenter
            lang_id=0)  # Language ID from syntax module

        self.vert_edit = vertedit.VertEdit(self)

        # Set Up Margins
        ## Outer Left Margin Bookmarks
        self.SetMarginType(MARK_MARGIN, wx.stc.STC_MARGIN_SYMBOL)
        self.SetMarginMask(MARK_MARGIN, self.ED_STC_MASK_MARKERS)
        self.SetMarginSensitive(MARK_MARGIN, True)
        self.SetMarginWidth(MARK_MARGIN, 12)

        ## Middle Left Margin Line Number Indication
        self.SetMarginType(NUM_MARGIN, wx.stc.STC_MARGIN_NUMBER)
        self.SetMarginMask(NUM_MARGIN, 0)

        ## Inner Left Margin Setup Folders
        self.SetMarginType(FOLD_MARGIN, wx.stc.STC_MARGIN_SYMBOL)
        self.SetMarginMask(FOLD_MARGIN, wx.stc.STC_MASK_FOLDERS)
        self.SetMarginSensitive(FOLD_MARGIN, True)

        # Set Mac specific keybindings
        if wx.Platform == '__WXMAC__':
            for keys in _GetMacKeyBindings():
                self.CmdKeyAssign(*keys)

        # Event Handlers
        self.Bind(wx.stc.EVT_STC_CHANGE, self.OnChanged)
        self.Bind(wx.stc.EVT_STC_MODIFIED, self.OnModified)
示例#9
0
    def testWriteUTF16File(self):
        """Test that input and output bytes match"""
        fobj = ed_txt.EdFile(self.path_utf16)
        txt = fobj.Read()
        self.assertTrue(type(txt) == types.UnicodeType)
        self.assertTrue(fobj.Encoding in ('utf-16', 'utf_16'))
        self.assertFalse(fobj.HasBom())  # test file has no BOM

        # Get original raw bytes
        raw_bytes = common.GetFileContents(fobj.GetPath())

        # Write the unicode back out to disk
        out = common.GetTempFilePath('utf_16_output.txt')
        fobj.SetPath(out)
        self.assertFalse(fobj.HasBom())  # test file has no BOM
        fobj.Write(txt)

        # Get raw bytes that were just written
        new_bytes = common.GetFileContents(out)
        self.assertEquals(raw_bytes, new_bytes)
示例#10
0
 def setUp(self):
     self.app = common.EdApp(False)
     self.path = os.path.abspath('./data/test_read_utf8.txt')
     self.file = ed_txt.EdFile(self.path)
     self.mtime = util.GetFileModTime(self.path)
示例#11
0
            control.SetFileName(path2file)
            result = True

        # Check if there was encoding errors
        if not result and not self._ses_load:
            result = self._HandleEncodingError(control)

        # Cleanup after errors
        if not result:
            if new_pg:
                # We created a new one so destroy it
                control.Destroy()
            else:
                # We where using an existing buffer so reset it
                control.SetText('')
                control.SetDocument(ed_txt.EdFile())
                control.SetSavePoint()

            self.GetTopLevelParent().Thaw()
            return

        # Put control into page an place page in notebook
        if new_pg:
            control.Show()
            self.control = control

        # Setup Document
        self.control.FindLexer()
        self.control.CheckEOL()
        self.control.EmptyUndoBuffer()
        doc = self.control.GetDocument()
示例#12
0
 def setUp(self):
     self.app = common.EdApp(False)
     self.path = common.GetDataFilePath(u'test_read_utf8.txt')
     self.file = ed_txt.EdFile(self.path)
     self.mtime = ebmlib.GetFileModTime(self.path)