Esempio n. 1
0
    def get_user_details(self, event):
        """Gets the user's information and settings."""

        if not self.logged_in:
            show_error_dialog(self, "Get Account Details",
                              "Must be logged in to view a user's details.")
            return

        try:
            # Get the user's details
            info = pastebin_api.get_user_info(self.dev_key, self.user_key)
        except urllib2.URLError:
            show_error_dialog(
                self, "Get Account Details",
                "Details could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down."
            )
            return

        # If Beautiful Soup is installed, get some extra info.
        extra_info = []
        if bs4_installed:
            extra_info = pastebin_extras.get_user_details_extra(self.user_name)

        # Show the user's details.
        user_dlg = UserDetailsDialog(self, "Account Details", info, extra_info)
        response = user_dlg.run()
        user_dlg.destroy()

        # If the user pressed "View Profile", open the profile in a web browser.
        if response == 9:
            webbrowser.open("https://pastebin.com/u/" + info["name"])
Esempio n. 2
0
    def get_user_details(self, event):
        """Gets the user's information and settings."""

        if not self.logged_in:
            show_error_dialog(self, "Get Account Details", "Must be logged in to view a user's details.")
            return

        try:
            # Get the user's details
            info = pastebin_api.get_user_info(self.dev_key, self.user_key)
        except urllib2.URLError:
            show_error_dialog(self, "Get Account Details", "Details could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down.")
            return

        # If Beautiful Soup is installed, get some extra info.
        extra_info = []
        if bs4_installed:
            extra_info = pastebin_extras.get_user_details_extra(self.user_name)

        # Show the user's details.
        user_dlg = UserDetailsDialog(self, "Account Details", info, extra_info)
        response = user_dlg.run()
        user_dlg.destroy()

        # If the user pressed "View Profile", open the profile in a web browser.
        if response == 9:
            webbrowser.open("https://pastebin.com/u/" + info["name"])
Esempio n. 3
0
    def get_paste_info(self, event, key=None):
        """Gets info on a provided paste."""

        if not bs4_installed:
            show_alert_dialog(self, "Get Paste Info", "This feature requires the BeautifulSoup 4 HTML parsing library to be installed.")
            return

        if key is None:

            # Get the key.
            get_dlg = GetPasteDialog(self, title="Get Paste Info")
            response = get_dlg.run()
            key = get_dlg.key_ent.get_text()
            if key.startswith("http") or key.startswith("www.") or key.startswith("pastebin"):
                key = key.rsplit("/", 1)[-1]
            get_dlg.destroy()

            if response != Gtk.ResponseType.OK:
                return

        # Get the paste info.
        try:
            info = pastebin_extras.get_paste_info("https://pastebin.com/" + key)
        except urllib2.URLError:
            show_error_dialog(self, "Get Paste Info", "Paste could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down.")
            return

        # Show the paste info.
        paste_dlg = PasteDetailsDialog(self, "Paste Info", info["name"], info["username"], "https://pastebin.com/" + key, info["views"], info["uploaded"], info["delete"])
        response = paste_dlg.run()
        paste_dlg.destroy()

        # If the user pressed "Get Paste", open the paste.
        if response == DialogResponse.GET_PASTE:
            self.get_paste(event=None, key=key)
Esempio n. 4
0
    def get_paste(self, event, key=""):
        """Gets an existing paste."""

        # If the key hasn't been specified, prompt the user.
        if not key:

            # Get the key.
            get_dlg = GetPasteDialog(self)
            response = get_dlg.run()
            key = get_dlg.key_ent.get_text()
            if key.startswith("http") or key.startswith("www.") or key.startswith("pastebin"):
                key = key.rsplit("/", 1)[-1]
            get_dlg.destroy()

            if response != Gtk.ResponseType.OK:
                return

        try:
            # Get the paste.
            paste = pastebin_api.get_paste(pastekey=key)

        except urllib2.URLError:
            show_error_dialog(self, "Get Paste", "Paste could not be retrieved.\n\nThis likely means that an invalid paste was specified, you are not connected to the internet, or the pastebin.com website is down.")

        else:

            # Did we try to load a private paste?
            if paste == "Error, this is a private paste. If this is your private paste, please login to Pastebin first.":
                show_alert_dialog(self, "Get Paste", "Due to API restrictions PastebinGTK is unable to load private pastes.")
                return

            # Delete the current text and insert the new.
            self.text_buffer.delete(self.text_buffer.get_start_iter(), self.text_buffer.get_end_iter())
            self.text_buffer.insert(self.text_buffer.get_start_iter(), paste)
            self.text_buffer.place_cursor(self.text_buffer.get_start_iter())
Esempio n. 5
0
    def list_recent(self, event):
        """Lists recently created pastes."""

        if not bs4_installed:
            show_alert_dialog(
                self, "List Recent Pastes",
                "This feature requires the BeautifulSoup 4 HTML parsing library to be installed."
            )
            return

        # Get the list of most recently created pastes.
        try:
            pastes = pastebin_extras.list_recent_pastes()

        except urllib2.URLError:
            show_error_dialog(
                self, "List Recent Pastes",
                "Pastes could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down."
            )
            return

        # Reformat the data into something the dialog can use.
        data = []
        for i in pastes:
            row = [
                i["name"], i["key"],
                i["format"] if i["format"] != "-" else "Unknown",
                i["time_created"], i["link"]
            ]
            data.append(row)

        # Show the list of pastes.
        list_dlg = ListRecentDialog(self, "List Recent Pastes", data)
        response = list_dlg.run()
        model, treeiter = list_dlg.treeview.get_selection().get_selected()
        list_dlg.destroy()

        # If the user clicked "Get Paste", load the selected paste.
        if response == DialogResponse.GET_PASTE:

            if treeiter is None:
                return

            # Get the key and load the paste.
            key = model[treeiter][1]
            self.get_paste(event=None, key=key)

        # If the user clicked "Get Details", get the paste details.
        elif response == DialogResponse.VIEW_DETAILS:

            if treeiter is None:
                return

            # Get the key and paste details
            key = model[treeiter][1]
            self.get_paste_info(event=None, key=key)
Esempio n. 6
0
    def delete_paste(self, event):
        """Deletes an existing paste."""

        if not self.logged_in:
            show_error_dialog(self, "Delete Paste", "Must be logged in to delete a paste.")
            return

        # Get the list of the user's pastes.
        try:
            pastes = pastebin_api.list_users_pastes(self.config["dev_key"], self.user_key)

            if len(pastes) == 0:
                show_alert_dialog(self, "Delete Paste", "The currently logged in user has no pastes.")
                return

        except urllib2.URLError:
            show_error_dialog(self, "Delete Paste", "Pastes could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down.")
            return

        # Create the list of data.
        data = []
        for i in pastes:
            new = [
                i["title"] if i["title"] else "Untitled",
                i["key"],
                i["format_long"],
                time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(i["expire_date"])))
            ]
            data.append(new)

        # Get the paste to delete.
        del_dlg = DeletePasteDialog(self, data)
        response = del_dlg.run()
        model, treeiter = del_dlg.treeview.get_selection().get_selected()
        del_dlg.destroy()

        if response != Gtk.ResponseType.OK or treeiter is None:
            return

        # Get the name and key.
        paste_name = model[treeiter][0]
        key = model[treeiter][1]

        # Ask the user for confirmation.
        del_conf = show_question_dialog(self, "Delete Paste", "Are you sure you want to delete the selected paste?")
        if del_conf != Gtk.ResponseType.OK:
            return

        try:
            # Get the paste.
            paste = pastebin_api.delete_paste(self.config["dev_key"], self.user_key, key)

        except urllib2.URLError:
            show_error_dialog(self, "Delete Paste", "Paste could not be deleted.\n\nThis likely means that an invalid paste was specified, you are not connected to the internet, or the pastebin.com website is down.")

        else:
            if paste == "Paste Removed":
                show_alert_dialog(self, "Delete Paste", "%s was successfully deleted." % ("Paste \"%s\"" % paste_name if paste_name != "" else "Untitled paste"))
            else:
                show_error_dialog(self, "Delete Paste", "Paste could not be deleted.\n\nThis likely means that you do not have the ability to delete the specified paste.")
Esempio n. 7
0
    def get_paste_info(self, event, key=None):
        """Gets info on a provided paste."""

        if not bs4_installed:
            show_alert_dialog(
                self, "Get Paste Info",
                "This feature requires the BeautifulSoup 4 HTML parsing library to be installed."
            )
            return

        if key is None:

            # Get the key.
            get_dlg = GetPasteDialog(self, title="Get Paste Info")
            response = get_dlg.run()
            key = get_dlg.key_ent.get_text()
            if key.startswith("http") or key.startswith(
                    "www.") or key.startswith("pastebin"):
                key = key.rsplit("/", 1)[-1]
            get_dlg.destroy()

            if response != Gtk.ResponseType.OK:
                return

        # Get the paste info.
        try:
            info = pastebin_extras.get_paste_info("https://pastebin.com/" +
                                                  key)
        except urllib2.URLError:
            show_error_dialog(
                self, "Get Paste Info",
                "Paste could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down."
            )
            return

        # Show the paste info.
        paste_dlg = PasteDetailsDialog(self, "Paste Info", info["name"],
                                       info["username"],
                                       "https://pastebin.com/" + key,
                                       info["views"], info["uploaded"],
                                       info["delete"])
        response = paste_dlg.run()
        paste_dlg.destroy()

        # If the user pressed "Get Paste", open the paste.
        if response == DialogResponse.GET_PASTE:
            self.get_paste(event=None, key=key)
Esempio n. 8
0
    def list_recent(self, event):
        """Lists recently created pastes."""

        if not bs4_installed:
            show_alert_dialog(self, "List Recent Pastes", "This feature requires the BeautifulSoup 4 HTML parsing library to be installed.")
            return

        # Get the list of most recently created pastes.
        try:
            pastes = pastebin_extras.list_recent_pastes()

        except urllib2.URLError:
            show_error_dialog(self, "List Recent Pastes", "Pastes could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down.")
            return

        # Reformat the data into something the dialog can use.
        data = []
        for i in pastes:
            row = [i["name"], i["key"], i["format"] if i["format"] != "-" else "Unknown", i["time_created"], i["link"]]
            data.append(row)

        # Show the list of pastes.
        list_dlg = ListRecentDialog(self, "List Recent Pastes", data)
        response = list_dlg.run()
        model, treeiter = list_dlg.treeview.get_selection().get_selected()
        list_dlg.destroy()

        # If the user clicked "Get Paste", load the selected paste.
        if response == DialogResponse.GET_PASTE:

            if treeiter is None:
                return

            # Get the key and load the paste.
            key = model[treeiter][1]
            self.get_paste(event=None, key=key)

        # If the user clicked "Get Details", get the paste details.
        elif response == DialogResponse.VIEW_DETAILS:

            if treeiter is None:
                return

            # Get the key and paste details
            key = model[treeiter][1]
            self.get_paste_info(event=None, key=key)
Esempio n. 9
0
    def get_paste(self, event, key=""):
        """Gets an existing paste."""

        # If the key hasn't been specified, prompt the user.
        if not key:

            # Get the key.
            get_dlg = GetPasteDialog(self)
            response = get_dlg.run()
            key = get_dlg.key_ent.get_text()
            if key.startswith("http") or key.startswith(
                    "www.") or key.startswith("pastebin"):
                key = key.rsplit("/", 1)[-1]
            get_dlg.destroy()

            if response != Gtk.ResponseType.OK:
                return

        try:
            # Get the paste.
            paste = pastebin_api.get_paste(pastekey=key)

        except urllib2.URLError:
            show_error_dialog(
                self, "Get Paste",
                "Paste could not be retrieved.\n\nThis likely means that an invalid paste was specified, you are not connected to the internet, or the pastebin.com website is down."
            )

        else:

            # Did we try to load a private paste?
            if paste == "Error, this is a private paste. If this is your private paste, please login to Pastebin first.":
                show_alert_dialog(
                    self, "Get Paste",
                    "Due to API restrictions PastebinGTK is unable to load private pastes."
                )
                return

            # Delete the current text and insert the new.
            self.text_buffer.delete(self.text_buffer.get_start_iter(),
                                    self.text_buffer.get_end_iter())
            self.text_buffer.insert(self.text_buffer.get_start_iter(), paste)
            self.text_buffer.place_cursor(self.text_buffer.get_start_iter())
Esempio n. 10
0
    def login(self, event):
        """Logs the user in."""

        # Logout:
        if self.logged_in:
            self.logged_in = False
            self.user_key = ""
            self.status_lbl.set_text("Not logged in")
            self.login_btn.set_label("Log in")

        # Login:
        else:

            # Get the username and password.
            user_name = self.login_username_entry.get_text()
            password = self.login_password_entry.get_text()

            # If the username and password are valid, get the user key
            if user_name != "" and password != "":

                try:
                    self.user_key = pastebin_api.create_user_key(
                        self.config["dev_key"], user_name, password)
                    if self.user_key == "Bad API request, invalid login":
                        raise TypeError
                    self.user_name = user_name
                    self.logged_in = True
                    self.status_lbl.set_text("Logged in as %s." % user_name)
                    self.login_password_entry.set_text("")
                    self.login_btn.set_label("Log out")

                except TypeError:
                    self.user_key = ""
                    show_error_dialog(
                        self, "Login",
                        "Invalid username or password specified.\n\nNot logged in."
                    )

                except urllib2.URLError:
                    show_error_dialog(
                        self, "Login",
                        "User authentication could not be sent.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down."
                    )

            else:
                show_error_dialog(
                    self, "Login", "No %s entered.\n\nNot logged in." %
                    ("username" if user_name == "" else "password"))
Esempio n. 11
0
    def login(self, event):
        """Logs the user in."""

        # Logout:
        if self.logged_in:
            self.logged_in = False
            self.user_key = ""
            self.status_lbl.set_text("Not logged in")
            self.login_btn.set_label("Log in")

        # Login:
        else:

            # Get the username and password.
            user_name = self.login_username_entry.get_text()
            password = self.login_password_entry.get_text()

            # If the username and password are valid, get the user key
            if user_name != "" and password != "":

                try:
                    self.user_key = pastebin_api.create_user_key(self.config["dev_key"], user_name, password)
                    if self.user_key == "Bad API request, invalid login":
                        raise TypeError
                    self.user_name = user_name
                    self.logged_in = True
                    self.status_lbl.set_text("Logged in as %s." % user_name)
                    self.login_password_entry.set_text("")
                    self.login_btn.set_label("Log out")

                except TypeError:
                    self.user_key = ""
                    show_error_dialog(self, "Login", "Invalid username or password specified.\n\nNot logged in.")

                except urllib2.URLError:
                    show_error_dialog(self, "Login", "User authentication could not be sent.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down.")

            else:
                show_error_dialog(self, "Login", "No %s entered.\n\nNot logged in." % ("username" if user_name == "" else "password"))
Esempio n. 12
0
    def list_pastes(self, source):
        """Get's the user's pastes or the currently trending pastes."""

        title1 = "List User's Pastes" if source == "user" else "List Trending Pastes"
        title2 = "%s's Pastes" % self.user_name if source == "user" else "Trending Pastes"

        # If getting the user's pastes, the user must be logged in.
        if source == "user" and not self.logged_in:
            show_error_dialog(self, title1,
                              "Must be logged in to view a user's pastes.")
            return

        try:
            # Get the list of pastes.
            if source == "user":
                pastes = pastebin_api.list_users_pastes(
                    self.dev_key,
                    self.user_key,
                    results_limit=int(self.config["pastes_retrieve"]))
            else:
                pastes = pastebin_api.list_trending_pastes(self.dev_key)

        except urllib2.URLError:
            show_error_dialog(
                self, title1,
                "Pastes could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down."
            )
            return

        if len(pastes) == 0:
            show_alert_dialog(self, title1,
                              "The currently logged in user has no pastes.")
            return

        # Create the list of data.
        data = []
        for i in pastes:
            new = []
            if not i["title"]:
                new.append("Untitled")
            else:
                new.append(i["title"])
            new.append(i["key"])
            if source == "user":
                new.append(i["format_long"])
            new.append(
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.localtime(int(i["date"]))))
            if i["expire_date"] == "0":
                new.append("Never")
            else:
                new.append(
                    time.strftime("%Y-%m-%d %H:%M:%S",
                                  time.localtime(int(i["expire_date"]))))
            new.append(EXPOSURE_REVERSED[i["private"]])
            size = int(i["size"])
            if size < 1000:
                new.append("%d bytes" % size)
            elif size < 1000 * 1000:
                new.append("%d kB" % (size / 1000))
            else:
                new.append("%d MB" % (size / (1000 * 1000)))
            new.append(i["hits"])
            new.append(i["url"])

            data.append(new)

        # Show the list of pastes.
        if source == "user":
            list_dlg = ListUserPastesDialog(self, title2, data)
        else:
            list_dlg = ListTrendingPastesDialog(self, title2, data)
        response = list_dlg.run()
        model, treeiter = list_dlg.treeview.get_selection().get_selected()
        list_dlg.destroy()

        # If the user clicked "Get Paste", load the selected paste.
        if response == DialogResponse.GET_PASTE:

            if treeiter is None:
                return

            # Can't load private pastes due to API restrictions.
            if (source == "user" and model[treeiter][5] == "Private") or \
               (source == "trending" and model[treeiter][4] == "Private"):
                show_alert_dialog(
                    self, title2,
                    "Due to API restrictions PastebinGTK is unable to load private pastes."
                )
                return

            # Get the key and load the paste.
            key = model[treeiter][1]
            self.get_paste(event=None, key=key)

        # If the user clicked "Get Details", get the paste details.
        elif response == DialogResponse.VIEW_DETAILS:

            if treeiter is None:
                return

            # Can't load private pastes due to API restrictions.
            if (source == "user" and model[treeiter][5] == "Private") or \
                    (source == "trending" and model[treeiter][4] == "Private"):
                show_alert_dialog(
                    self, title2,
                    "Due to API restrictions PastebinGTK is unable to load private pastes."
                )
                return

            # Get the key and paste details
            key = model[treeiter][1]
            self.get_paste_info(event=None, key=key)
Esempio n. 13
0
    def delete_paste(self, event):
        """Deletes an existing paste."""

        if not self.logged_in:
            show_error_dialog(self, "Delete Paste",
                              "Must be logged in to delete a paste.")
            return

        # Get the list of the user's pastes.
        try:
            pastes = pastebin_api.list_users_pastes(self.config["dev_key"],
                                                    self.user_key)

            if len(pastes) == 0:
                show_alert_dialog(
                    self, "Delete Paste",
                    "The currently logged in user has no pastes.")
                return

        except urllib2.URLError:
            show_error_dialog(
                self, "Delete Paste",
                "Pastes could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down."
            )
            return

        # Create the list of data.
        data = []
        for i in pastes:
            new = [
                i["title"] if i["title"] else "Untitled", i["key"],
                i["format_long"],
                time.strftime("%Y-%m-%d %H:%M:%S",
                              time.localtime(int(i["expire_date"])))
            ]
            data.append(new)

        # Get the paste to delete.
        del_dlg = DeletePasteDialog(self, data)
        response = del_dlg.run()
        model, treeiter = del_dlg.treeview.get_selection().get_selected()
        del_dlg.destroy()

        if response != Gtk.ResponseType.OK or treeiter is None:
            return

        # Get the name and key.
        paste_name = model[treeiter][0]
        key = model[treeiter][1]

        # Ask the user for confirmation.
        del_conf = show_question_dialog(
            self, "Delete Paste",
            "Are you sure you want to delete the selected paste?")
        if del_conf != Gtk.ResponseType.OK:
            return

        try:
            # Get the paste.
            paste = pastebin_api.delete_paste(self.config["dev_key"],
                                              self.user_key, key)

        except urllib2.URLError:
            show_error_dialog(
                self, "Delete Paste",
                "Paste could not be deleted.\n\nThis likely means that an invalid paste was specified, you are not connected to the internet, or the pastebin.com website is down."
            )

        else:
            if paste == "Paste Removed":
                show_alert_dialog(
                    self, "Delete Paste", "%s was successfully deleted." %
                    ("Paste \"%s\"" %
                     paste_name if paste_name != "" else "Untitled paste"))
            else:
                show_error_dialog(
                    self, "Delete Paste",
                    "Paste could not be deleted.\n\nThis likely means that you do not have the ability to delete the specified paste."
                )
Esempio n. 14
0
    def create_paste(self, event):
        """Creates a new paste."""

        # Get the text.
        text = self.text_buffer.get_text(self.text_buffer.get_start_iter(),
                                         self.text_buffer.get_end_iter(),
                                         False)

        # If there's no text, don't create the paste.
        if not text:
            show_error_dialog(self, "Create Paste", "No text entered.")
            return

        # Get the name, format, expiration, and exposure for the paste.
        new_dlg = CreatePasteDialog(self)
        new_dlg.name_ent.set_text(self.config["default_name"])
        new_dlg.form_com.set_active(
            FORMATS_LIST.index(self.config["default_format"]))
        new_dlg.expi_com.set_active(
            EXPIRE_LIST.index(self.config["default_expiration"]))
        new_dlg.expo_com.set_active(
            EXPOSURE_LIST.index(self.config["default_exposure"]))
        response = new_dlg.run()
        name = new_dlg.name_ent.get_text()
        format_ = new_dlg.form_com.get_active_text()
        expire = new_dlg.expi_com.get_active_text()
        exposure = new_dlg.expo_com.get_active_text()
        userkey = self.user_key
        if new_dlg.guest_chk.get_active():
            userkey = ""
        new_dlg.destroy()

        # Get the paste values.
        format_ = FORMATS[format_]
        expire = EXPIRE[expire]
        exposure = EXPOSURE[exposure]

        # If the user isn't logged in, they can't create private pastes.
        if not self.user_key and exposure == EXPOSURE["Private"]:
            show_alert_dialog(self, "Create Paste",
                              "Anonymous users cannot create private pastes.")
            return

        # If the user clicked OK:
        if response == Gtk.ResponseType.OK:

            try:
                # Send the paste.
                url = pastebin_api.create_paste(self.config["dev_key"],
                                                data=text,
                                                name=name,
                                                format_=format_,
                                                private=exposure,
                                                expire=expire,
                                                userkey=userkey)

                # Check for the spam filter, if the user wants that.
                caught_spam = False
                if self.config["check_spam"]:

                    try:
                        paste = pastebin_api.get_paste(
                            pastekey=url.rsplit("/", 1)[-1])

                    except urllib2.URLError:
                        pass

                    else:
                        # Check if the paste doesn't match.
                        if paste != text:
                            caught_spam = True

                # Show the url.
                if not caught_spam or exposure == EXPOSURE["Private"]:
                    show_alert_dialog(
                        self, "Create Paste",
                        "Paste has been successfully created, and can be found at the following URL:\n\n%s"
                        % url)
                else:
                    show_alert_dialog(
                        self, "Create Paste",
                        "Paste triggered automatic spam detection filter. Verify that you are not a bot by filling out the captcha at the following URL:\n\n%s"
                        % url)

            except urllib2.URLError:
                # Show an error if the paste could not be sent. This will occur if the user isn't connected to the internet.
                show_error_dialog(
                    self, "Create Paste",
                    "Paste could not be sent.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down."
                )
Esempio n. 15
0
    def list_pastes(self, source):
        """Get's the user's pastes or the currently trending pastes."""

        title1 = "List User's Pastes" if source == "user" else "List Trending Pastes"
        title2 = "%s's Pastes" % self.user_name if source == "user" else "Trending Pastes"

        # If getting the user's pastes, the user must be logged in.
        if source == "user" and not self.logged_in:
            show_error_dialog(self, title1, "Must be logged in to view a user's pastes.")
            return

        try:
            # Get the list of pastes.
            if source == "user":
                pastes = pastebin_api.list_users_pastes(self.dev_key, self.user_key, results_limit=int(self.config["pastes_retrieve"]))
            else:
                pastes = pastebin_api.list_trending_pastes(self.dev_key)

        except urllib2.URLError:
            show_error_dialog(self, title1, "Pastes could not be retrieved.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down.")
            return

        if len(pastes) == 0:
            show_alert_dialog(self, title1, "The currently logged in user has no pastes.")
            return

        # Create the list of data.
        data = []
        for i in pastes:
            new = []
            if not i["title"]:
                new.append("Untitled")
            else:
                new.append(i["title"])
            new.append(i["key"])
            if source == "user":
                new.append(i["format_long"])
            new.append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(i["date"]))))
            if i["expire_date"] == "0":
                new.append("Never")
            else:
                new.append(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(i["expire_date"]))))
            new.append(EXPOSURE_REVERSED[i["private"]])
            size = int(i["size"])
            if size < 1000:
                new.append("%d bytes" % size)
            elif size < 1000 * 1000:
                new.append("%d kB" % (size / 1000))
            else:
                new.append("%d MB" % (size / (1000 * 1000)))
            new.append(i["hits"])
            new.append(i["url"])

            data.append(new)

        # Show the list of pastes.
        if source == "user":
            list_dlg = ListUserPastesDialog(self, title2, data)
        else:
            list_dlg = ListTrendingPastesDialog(self, title2, data)
        response = list_dlg.run()
        model, treeiter = list_dlg.treeview.get_selection().get_selected()
        list_dlg.destroy()

        # If the user clicked "Get Paste", load the selected paste.
        if response == DialogResponse.GET_PASTE:

            if treeiter is None:
                return

            # Can't load private pastes due to API restrictions.
            if (source == "user" and model[treeiter][5] == "Private") or \
               (source == "trending" and model[treeiter][4] == "Private"):
                show_alert_dialog(self, title2, "Due to API restrictions PastebinGTK is unable to load private pastes.")
                return

            # Get the key and load the paste.
            key = model[treeiter][1]
            self.get_paste(event=None, key=key)

        # If the user clicked "Get Details", get the paste details.
        elif response == DialogResponse.VIEW_DETAILS:

            if treeiter is None:
                return

            # Can't load private pastes due to API restrictions.
            if (source == "user" and model[treeiter][5] == "Private") or \
                    (source == "trending" and model[treeiter][4] == "Private"):
                show_alert_dialog(self, title2, "Due to API restrictions PastebinGTK is unable to load private pastes.")
                return

            # Get the key and paste details
            key = model[treeiter][1]
            self.get_paste_info(event=None, key=key)
Esempio n. 16
0
    def create_paste(self, event):
        """Creates a new paste."""

        # Get the text.
        text = self.text_buffer.get_text(self.text_buffer.get_start_iter(), self.text_buffer.get_end_iter(), False)

        # If there's no text, don't create the paste.
        if not text:
            show_error_dialog(self, "Create Paste", "No text entered.")
            return

        # Get the name, format, expiration, and exposure for the paste.
        new_dlg = CreatePasteDialog(self)
        new_dlg.name_ent.set_text(self.config["default_name"])
        new_dlg.form_com.set_active(FORMATS_LIST.index(self.config["default_format"]))
        new_dlg.expi_com.set_active(EXPIRE_LIST.index(self.config["default_expiration"]))
        new_dlg.expo_com.set_active(EXPOSURE_LIST.index(self.config["default_exposure"]))
        response = new_dlg.run()
        name = new_dlg.name_ent.get_text()
        format_ = new_dlg.form_com.get_active_text()
        expire = new_dlg.expi_com.get_active_text()
        exposure = new_dlg.expo_com.get_active_text()
        userkey = self.user_key
        if new_dlg.guest_chk.get_active():
            userkey = ""
        new_dlg.destroy()

        # Get the paste values.
        format_ = FORMATS[format_]
        expire = EXPIRE[expire]
        exposure = EXPOSURE[exposure]

        # If the user isn't logged in, they can't create private pastes.
        if not self.user_key and exposure == EXPOSURE["Private"]:
            show_alert_dialog(self, "Create Paste", "Anonymous users cannot create private pastes.")
            return

        # If the user clicked OK:
        if response == Gtk.ResponseType.OK:

            try:
                # Send the paste.
                url = pastebin_api.create_paste(self.config["dev_key"], data=text, name=name, format_=format_, private=exposure, expire=expire, userkey=userkey)

                # Check for the spam filter, if the user wants that.
                caught_spam = False
                if self.config["check_spam"]:

                    try:
                        paste = pastebin_api.get_paste(pastekey=url.rsplit("/", 1)[-1])

                    except urllib2.URLError:
                        pass

                    else:
                        # Check if the paste doesn't match.
                        if paste != text:
                            caught_spam = True

                # Show the url.
                if not caught_spam or exposure == EXPOSURE["Private"]:
                    show_alert_dialog(self, "Create Paste", "Paste has been successfully created, and can be found at the following URL:\n\n%s" % url)
                else:
                    show_alert_dialog(self, "Create Paste", "Paste triggered automatic spam detection filter. Verify that you are not a bot by filling out the captcha at the following URL:\n\n%s" % url)

            except urllib2.URLError:
                # Show an error if the paste could not be sent. This will occur if the user isn't connected to the internet.
                show_error_dialog(self, "Create Paste", "Paste could not be sent.\n\nThis likely means that you are not connected to the internet, or the pastebin.com website is down.")