u"""Paste windows clipboard.
        Assume single line strip other lines and end of line markers and trailing spaces
342005
def paste(self,e):
        """ #(Control-v)
        if self.enable_win32_clipboard:
                txt=clipboard.get_clipboard_text_and_convert(False)
                txt=txt.split("\n")[0].strip("\r").strip("\n")
                log("paste: >%s<"%map(ord,txt))
                self.insert_text(txt)
        self.finalize()
217153
def highlight_spaces(self, text, offset=0):
        
        flags_text = self.document().defaultTextOption().flags()
        show_blanks =  flags_text & QTextOption.ShowTabsAndSpaces
        if show_blanks:
            format_leading = self.formats.get("leading", None)
            format_trailing = self.formats.get("trailing", None)
            match = self.BLANKPROG.search(text, offset)
            while match:
                start, end = match.span()
                start = max([0, start+offset])
                end = max([0, end+offset])
                # Format trailing spaces at the end of the line. 
                if end == len(text) and format_trailing is not None:
                    self.setFormat(start, end, format_trailing)
                # Format leading spaces, e.g. indentation.
                if start == 0 and format_leading is not None:
                    self.setFormat(start, end, format_leading)
                format = self.format(start)
                color_foreground = format.foreground().color()
                alpha_new = self.BLANK_ALPHA_FACTOR * color_foreground.alphaF()
                color_foreground.setAlphaF(alpha_new)
                self.setFormat(start, end-start, color_foreground)
                match = self.BLANKPROG.search(text, match.end())
1133151
def cut
      str = selection_text
      unless str.empty?
        Clipboard.copy str
        self.selection_text = '' if editable?
      end
    end
918967
def paste(self):
        
        html = QApplication.clipboard().text()
        if not self.isRichTextEditEnabled():
            self.insertPlainText(projex.text.toAscii(html))
        else:
            super(XTextEdit, self).paste()
1223795
function copyToClipBoard(content) {
  switch (process.platform) {
    case 'darwin': {
      const child = spawn('pbcopy', []);
      child.stdin.end(Buffer.from(content, 'utf8'));
      return true;
    }
    case 'win32': {
      const child = spawn('clip', []);
      child.stdin.end(Buffer.from(content, 'utf8'));
      return true;
    }
    case 'linux': {
      const child = spawn(xsel, ['--clipboard', '--input']);
      child.stdin.end(Buffer.from(content, 'utf8'));
      return true;
    }
    default:
      return false;
  }
}
452853
def paste(self):
        """"""
        if self.has_selected_text():
            self.remove_selected_text()
        self.insert_text(QApplication.clipboard().text())
601939
def _onShortcutCopyLine(self):
        
        lines = self.lines[self._selectedLinesSlice()]
        text = self._eol.join(lines)
        QApplication.clipboard().setText(text)
800194
def copy_to_clipboard(i): # pragma: no cover 
    

    s=i['string']

    failed=False
    ee=''

    # Try to load pyperclip (seems to work fine on Windows)
    try:
       import pyperclip
    except Exception as e:
       ee=format(e)
       failed=True
       pass

    if not failed:
       pyperclip.copy(s)
    else:
       failed=False

       # Try to load Tkinter
       try:
          from Tkinter import Tk
       except ImportError as e:
          ee=format(e)
          failed=True
          pass

       if failed:
          failed=False
          try:
             from tkinter import Tk
          except ImportError as e:
             ee=format(e)
             failed=True
             pass

       if failed:
          return {'return':1, 'error':'none of pyperclip/Tkinter/tkinter packages is installed'}

       # Copy to clipboard
       try:
          r = Tk()
          r.withdraw()
          r.clipboard_clear()
          r.clipboard_append(s)
          r.destroy()
       except Exception as e:
          return {'return':1, 'error':'problem copying string to clipboard ('+format(e)+')'}

    return {'return':0}
983645
def _paste_tokens_line_by_line(tokens, token_type, begin, end):
    """"""
    block_index = begin

    while block_index < end:
        rst_line = tokens[block_index].line
        line_traversal_index = block_index
        pasted = ""
        try:
            while tokens[line_traversal_index].line == rst_line:
                pasted += tokens[line_traversal_index].content
                line_traversal_index += 1
        except IndexError:
            assert line_traversal_index == end

        last_tokens_len = len(tokens)
        tokens = _replace_token_range(tokens,
                                      block_index,
                                      line_traversal_index,
                                      [Token(type=token_type,
                                             content=pasted,
                                             line=tokens[block_index].line,
                                             col=tokens[block_index].col)])
        end -= last_tokens_len - len(tokens)
        block_index += 1

    return (block_index, len(tokens), tokens)
753059
def save_file_clipboard(self, fnames=None):
        """"""
        if fnames is None:
            fnames = self.get_selected_filenames()
        if not isinstance(fnames, (tuple, list)):
            fnames = [fnames]
        if len(fnames) >= 1:
            try:
                selected_item = osp.commonpath(fnames)
            except AttributeError:
                #  py2 does not have commonpath
                if len(fnames) > 1:
                    selected_item = osp.normpath(
                            osp.dirname(osp.commonprefix(fnames)))
                else:
                    selected_item = fnames[0]
            if osp.isfile(selected_item):
                parent_path = osp.dirname(selected_item)
            else:
                parent_path = osp.normpath(selected_item)
            cb_data = QApplication.clipboard().mimeData()
            if cb_data.hasUrls():
                urls = cb_data.urls()
                for url in urls:
                    source_name = url.toLocalFile()
                    base_name = osp.basename(source_name)
                    if osp.isfile(source_name):
                        try:
                            while base_name in os.listdir(parent_path):
                                file_no_ext, file_ext = osp.splitext(base_name)
                                end_number = re.search(r'\d+$', file_no_ext)
                                if end_number:
                                    new_number = int(end_number.group()) + 1
                                else:
                                    new_number = 1
                                left_string = re.sub(r'\d+$', '', file_no_ext)
                                left_string += str(new_number)
                                base_name = left_string + file_ext
                                destination = osp.join(parent_path, base_name)
                            else:
                                destination = osp.join(parent_path, base_name)
                            shutil.copy(source_name, destination)
                        except Exception as e:
                            QMessageBox.critical(self, _('Error pasting file'),
                                                 _("Unsupported copy operation"
                                                   ". The error was:\n\n")
                                                 + to_text_string(e))
                    else:
                        try:
                            while base_name in os.listdir(parent_path):
                                end_number = re.search(r'\d+$', base_name)
                                if end_number:
                                    new_number = int(end_number.group()) + 1
                                else:
                                    new_number = 1
                                left_string = re.sub(r'\d+$', '', base_name)
                                base_name = left_string + str(new_number)
                                destination = osp.join(parent_path, base_name)
                            else:
                                destination = osp.join(parent_path, base_name)
                            if osp.realpath(destination).startswith(
                                    osp.realpath(source_name) + os.sep):
                                QMessageBox.critical(self,
                                                     _('Recursive copy'),
                                                     _("Source is an ancestor"
                                                       " of destination"
                                                       " folder."))
                                continue
                            shutil.copytree(source_name, destination)
                        except Exception as e:
                            QMessageBox.critical(self,
                                                 _('Error pasting folder'),
                                                 _("Unsupported copy"
                                                   " operation. The error was:"
                                                   "\n\n") + to_text_string(e))
            else:
                QMessageBox.critical(self, _("No file in clipboard"),
                                     _("No file in the clipboard. Please copy"
                                       " a file to the clipboard first."))
        else:
            if QApplication.clipboard().mimeData().hasUrls():
                QMessageBox.critical(self, _('Blank area'),
                                     _("Cannot paste in the blank area."))
            else:
                pass
413854
def find_cell_end(self, lines):
        """"""
        if self.in_region:
            self.cell_type = 'markdown'
            for i, line in enumerate(lines):
                if self.end_region_re.match(line):
                    return i, i + 1, True
        elif self.metadata is None:
            # default markdown: (last) two consecutive blank lines, except when in code blocks
            self.cell_type = 'markdown'
            prev_blank = 0
            in_explicit_code_block = False
            in_indented_code_block = False

            for i, line in enumerate(lines):
                if in_explicit_code_block and self.end_code_re.match(line):
                    in_explicit_code_block = False
                    continue

                if self.non_jupyter_code_re and self.non_jupyter_code_re.match(line):
                    in_explicit_code_block = True
                    prev_blank = 0
                    continue

                if prev_blank and line.startswith('    ') and not _BLANK_LINE.match(line):
                    in_indented_code_block = True
                    prev_blank = 0
                    continue

                if in_indented_code_block and not _BLANK_LINE.match(line) and not line.startswith('    '):
                    in_indented_code_block = False

                if in_indented_code_block or in_explicit_code_block:
                    continue

                if self.start_code_re.match(line) or self.start_region_re.match(line):
                    if i > 1 and prev_blank:
                        return i - 1, i, False
                    return i, i, False

                if self.split_at_heading and line.startswith('#') and prev_blank >= 1:
                    return i - 1, i, False

                if _BLANK_LINE.match(lines[i]):
                    prev_blank += 1
                elif i > 2 and prev_blank >= 2:
                    return i - 2, i, True
                else:
                    prev_blank = 0
        else:
            self.cell_type = 'code'
            for i, line in enumerate(lines):
                # skip cell header
                if i == 0:
                    continue
                if self.end_code_re.match(line):
                    return i, i + 1, True

        # End not found
        return len(lines), len(lines), False
982180
def copy_selection_to_clipboard(self): # ()
        '''
        if self.enable_win32_clipboard and self.enable_selection and self.selection_mark >= 0:
                selection_mark = min(self.selection_mark,len(self.line_buffer))
                cursor = min(self.point,len(self.line_buffer))
                if self.selection_mark == -1:
                        return
                begin = min(cursor, selection_mark)
                end = max(cursor, selection_mark)
                toclipboard = u"".join(self.line_buffer[begin:end])
                clipboard.SetClipboardText(toclipboard)
234042
def _shorten_line(tokens, source, indentation, indent_word,
                  aggressive=False, previous_line=''):
    
    for (token_type,
         token_string,
         start_offset,
         end_offset) in token_offsets(tokens):

        if (
            token_type == tokenize.COMMENT and
            not is_probably_part_of_multiline(previous_line) and
            not is_probably_part_of_multiline(source) and
            not source[start_offset + 1:].strip().lower().startswith(
                ('noqa', 'pragma:', 'pylint:'))
        ):
            # Move inline comments to previous line.
            first = source[:start_offset]
            second = source[start_offset:]
            yield (indentation + second.strip() + '\n' +
                   indentation + first.strip() + '\n')
        elif token_type == token.OP and token_string != '=':
            # Don't break on '=' after keyword as this violates PEP 8.

            assert token_type != token.INDENT

            first = source[:end_offset]

            second_indent = indentation
            if (first.rstrip().endswith('(') and
                    source[end_offset:].lstrip().startswith(')')):
                pass
            elif first.rstrip().endswith('('):
                second_indent += indent_word
            elif '(' in first:
                second_indent += ' ' * (1 + first.find('('))
            else:
                second_indent += indent_word

            second = (second_indent + source[end_offset:].lstrip())
            if (
                not second.strip() or
                second.lstrip().startswith('#')
            ):
                continue

            # Do not begin a line with a comma
            if second.lstrip().startswith(','):
                continue
            # Do end a line with a dot
            if first.rstrip().endswith('.'):
                continue
            if token_string in '+-*/':
                fixed = first + ' \\' + '\n' + second
            else:
                fixed = first + '\n' + second

            # Only fix if syntax is okay.
            if check_syntax(normalize_multiline(fixed)
                            if aggressive else fixed):
                yield indentation + fixed
715374
def copy(self):
        """"""
        cliptxt = self._sel_to_text( self.selectedIndexes() )
        clipboard = QApplication.clipboard()
        clipboard.setText(cliptxt)
166807
function parse_ClipboardFormatOrString(o, w/*:number*/)/*:string*/ {
	// $FlowIgnore
	var ClipFmt = {2:"BITMAP",3:"METAFILEPICT",8:"DIB",14:"ENHMETAFILE"};
	var m/*:number*/ = o.read_shift(4);
	switch(m) {
		case 0x00000000: return "";
		case 0xffffffff: case 0xfffffffe: return ClipFmt[o.read_shift(4)]||"";
	}
	if(m > 0x190) throw new Error("Unsupported Clipboard: " + m.toString(16));
	o.l -= 4;
	return o.read_shift(0, w == 1 ? "lpstr" : "lpwstr");
}
662396
def _clip_line(
        self,
        line_pt_1,
        line_pt_2
        ):

        

        x_min = min(line_pt_1[0], line_pt_2[0])
        x_max = max(line_pt_1[0], line_pt_2[0])
        y_min = min(line_pt_1[1], line_pt_2[1])
        y_max = max(line_pt_1[1], line_pt_2[1])

        extent = self.extent()

        if line_pt_1[0] == line_pt_2[0]:
            return (
                (line_pt_1[0], max(y_min, extent[1])),
                (line_pt_1[0], min(y_max, extent[3]))
            )

        if line_pt_1[1] == line_pt_2[1]:
            return (
                (max(x_min, extent[0]), line_pt_1[1]),
                (min(x_max, extent[2]), line_pt_1[1])
            )

        if ((extent[0] <= line_pt_1[0] < extent[2]) and
            (extent[1] <= line_pt_1[1] < extent[3]) and
            (extent[0] <= line_pt_2[0] < extent[2]) and
            (extent[1] <= line_pt_2[1] < extent[3])):
            return line_pt_1, line_pt_2

        ts = [0.0,
              1.0,
              float(extent[0] - line_pt_1[0]) / (line_pt_2[0] - line_pt_1[0]),
              float(extent[2] - line_pt_1[0]) / (line_pt_2[0] - line_pt_1[0]),
              float(extent[1] - line_pt_1[1]) / (line_pt_2[1] - line_pt_1[1]),
              float(extent[3] - line_pt_1[1]) / (line_pt_2[1] - line_pt_1[1])
              ]
        ts.sort()

        if (ts[2] < 0) or (ts[2] >= 1) or (ts[3] < 0) or (ts[2] >= 1):
            return None

        result =\
            [(pt_1 + t * (pt_2 - pt_1))\
                for t in (ts[2], ts[3])\
                    for (pt_1, pt_2) in zip(line_pt_1, line_pt_2)]

        return (result[:2], result[2:])
478416
function copyToClipBoard(content) {
  switch (process.platform) {
  case 'darwin':
    var child = spawn('pbcopy', []);
    child.stdin.end(new Buffer(content, 'utf8'));
    return true;
  case 'win32':
    var child = spawn('clip', []);
    child.stdin.end(new Buffer(content, 'utf8'));
    return true;
  default:
    return false;
  }
}