# -*- coding: utf-8 -*-
""" Copy + Paste in OS X
"""

import subprocess
import os

from .base import *


def copy(string):
    """Copy given string into system clipboard."""
    try:
        env = os.environ.copy()
        env['LANG'] = 'en_US.utf-8'
        subprocess.Popen(['pbcopy'],
                         stdin=subprocess.PIPE,
                         env=env).communicate(
                             string.encode("utf-8"))
    except OSError as why:
        raise XcodeNotFound

    return


def paste():
    """Returns system clipboard contents."""
    try:
        env = os.environ.copy()
        env['LANG'] = 'en_US.utf-8'
        return subprocess.Popen(
            ['pbpaste'],
            stdout=subprocess.PIPE,
            env=env).communicate()[0].decode('utf-8')

    except OSError as why:
        raise XcodeNotFound
