Permalink
Browse files

Combined ST2/ST3 version

Hipster Ipsum now runs equally well on both Sublime Text 2 and Sublime
Text 3, in one simple package.
  • Loading branch information...
1 parent 53098e6 commit abb43de5363a53b8d9813baa88b82da12aa31f36 Daniel Shannon committed Mar 23, 2013
Showing with 16,464 additions and 32 deletions.
  1. +3 −3 Main.sublime-menu
  2. +3 −3 README.mdown
  3. +27 −26 hipsteripsum.py
  4. +71 −0 requests/__init__.py
  5. +242 −0 requests/adapters.py
  6. +120 −0 requests/api.py
  7. +175 −0 requests/auth.py
  8. +3,290 −0 requests/cacert.pem
  9. +24 −0 requests/certs.py
  10. +113 −0 requests/compat.py
  11. +385 −0 requests/cookies.py
  12. +55 −0 requests/exceptions.py
  13. +45 −0 requests/hooks.py
  14. +663 −0 requests/models.py
  15. +3 −0 requests/packages/__init__.py
  16. +27 −0 requests/packages/charade/__init__.py
  17. +925 −0 requests/packages/charade/big5freq.py
  18. +42 −0 requests/packages/charade/big5prober.py
  19. +230 −0 requests/packages/charade/chardistribution.py
  20. +106 −0 requests/packages/charade/charsetgroupprober.py
  21. +62 −0 requests/packages/charade/charsetprober.py
  22. +61 −0 requests/packages/charade/codingstatemachine.py
  23. +26 −0 requests/packages/charade/compat.py
  24. +39 −0 requests/packages/charade/constants.py
  25. +86 −0 requests/packages/charade/escprober.py
  26. +242 −0 requests/packages/charade/escsm.py
  27. +90 −0 requests/packages/charade/eucjpprober.py
  28. +596 −0 requests/packages/charade/euckrfreq.py
  29. +42 −0 requests/packages/charade/euckrprober.py
  30. +428 −0 requests/packages/charade/euctwfreq.py
  31. +41 −0 requests/packages/charade/euctwprober.py
  32. +472 −0 requests/packages/charade/gb2312freq.py
  33. +41 −0 requests/packages/charade/gb2312prober.py
  34. +283 −0 requests/packages/charade/hebrewprober.py
  35. +569 −0 requests/packages/charade/jisfreq.py
  36. +219 −0 requests/packages/charade/jpcntx.py
  37. +229 −0 requests/packages/charade/langbulgarianmodel.py
  38. +331 −0 requests/packages/charade/langcyrillicmodel.py
  39. +227 −0 requests/packages/charade/langgreekmodel.py
  40. +203 −0 requests/packages/charade/langhebrewmodel.py
  41. +227 −0 requests/packages/charade/langhungarianmodel.py
  42. +200 −0 requests/packages/charade/langthaimodel.py
  43. +139 −0 requests/packages/charade/latin1prober.py
  44. +86 −0 requests/packages/charade/mbcharsetprober.py
  45. +52 −0 requests/packages/charade/mbcsgroupprober.py
  46. +535 −0 requests/packages/charade/mbcssm.py
  47. +120 −0 requests/packages/charade/sbcharsetprober.py
  48. +69 −0 requests/packages/charade/sbcsgroupprober.py
  49. +91 −0 requests/packages/charade/sjisprober.py
  50. +171 −0 requests/packages/charade/universaldetector.py
  51. +76 −0 requests/packages/charade/utf8prober.py
  52. +58 −0 requests/packages/urllib3/__init__.py
  53. +94 −0 requests/packages/urllib3/_collections.py
  54. +579 −0 requests/packages/urllib3/connectionpool.py
  55. 0 requests/packages/urllib3/contrib/__init__.py
  56. +120 −0 requests/packages/urllib3/contrib/ntlmpool.py
  57. +87 −0 requests/packages/urllib3/exceptions.py
  58. +98 −0 requests/packages/urllib3/filepost.py
  59. +4 −0 requests/packages/urllib3/packages/__init__.py
  60. +260 −0 requests/packages/urllib3/packages/ordered_dict.py
  61. +385 −0 requests/packages/urllib3/packages/six.py
  62. +61 −0 requests/packages/urllib3/packages/ssl_match_hostname/__init__.py
  63. +182 −0 requests/packages/urllib3/poolmanager.py
  64. +142 −0 requests/packages/urllib3/request.py
  65. +214 −0 requests/packages/urllib3/response.py
  66. +338 −0 requests/packages/urllib3/util.py
  67. +472 −0 requests/sessions.py
  68. +86 −0 requests/status_codes.py
  69. +91 −0 requests/structures.py
  70. +591 −0 requests/utils.py
View
@@ -18,7 +18,7 @@
{
"command": "open_file", "args":
{
- "file": "${packages}/Hipster Ipsum/README.mdown"
+ "file": "${packages}/HipsterIpsum/README.mdown"
},
"caption": "README"
},
@@ -28,14 +28,14 @@
{
"command": "open_file", "args":
{
- "file": "${packages}/Hipster Ipsum/Hipster Ipsum.sublime-settings"
+ "file": "${packages}/HipsterIpsum/Hipster Ipsum.sublime-settings"
},
"caption": "Settings – Default"
},
{
"command": "open_file", "args":
{
- "file": "${packages}/User/Hipster Ipsum.sublime-settings"
+ "file": "${packages}/User/HipsterIpsum.sublime-settings"
},
"caption": "Settings – User"
}
View
@@ -1,11 +1,11 @@
-[Hipster Ipsum for Sublime Text 2](http://sublime.daniel.sh/hipstum/)
+Hipster Ipsum for Sublime Text 2 and 3
================================
If you were into _Lorem ipsum_ before it sold out and have been looking for something to fill the void, Hipster Ipsum is your new bicycle. Pull bespoke filler text from [Hipster Ipsum](http://hipsteripsum.me), via the [Hipster Jesus](http://hipsterjesus.com) API, and have it Occupy Sublime.
Installation
------------
-[Package Control](http://wbond.net/sublime_packages/package_control) is the preferred source for direct-trade, farm-to-table Sublime packages, including Hipster Ipsum. DIYers can find small-batch source files at [the GitHub repository](http://github.com/phyllisstein/HipsterIpsum).
+You've probably never heard of [Sublime Package Control](http://wbond.net/sublime_packages/package_control), but it's the preferred method for installing HipsterIpsum. DIYers can find small-batch source files at [the GitHub repository](http://github.com/phyllisstein/HipsterIpsum).
Usage
@@ -22,7 +22,7 @@ Configuration
Cred
----
-Thanks to [Will Bond](http://wbond.net) for his [tutorial on creating a Sublime Text 2 plugin](http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/), which offered some next-level solutions to a few difficulties.
+Thanks to [Will Bond](http://wbond.net) for his [tutorial on creating a Sublime Text 2 plugin](http://net.tutsplus.com/tutorials/python-tutorials/how-to-create-a-sublime-text-2-plugin/), which offered some next-level solutions to a few difficulties. Thanks as well to the [requests](http://docs.python-requests.org/en/latest/) library, the sustainable biodiesel motor behind the farm-to-table HTTP.
Cosby Sweater
View
@@ -2,16 +2,18 @@
import sublime_plugin
import threading
import urllib
-# import urlparse
import json
-import urllib2
+if int(sublime.version()) >= 3000:
+ import HipsterIpsum3.requests as requests
+else:
+ import requests
def err(theError):
- print "[Hipster Ipsum: " + theError + "]"
+ print("[Hipster Ipsum: " + theError + "]")
-class hipsterIpsumCommand(sublime_plugin.TextCommand):
+class HipsterIpsumCommand(sublime_plugin.TextCommand):
def run(self, edit):
s = sublime.load_settings("Hipster Ipsum.sublime-settings")
defaultParas = s.get("paragraphs", 1)
@@ -55,21 +57,20 @@ def run(self, edit):
passedThreads += 1
if passedThreads > 0:
self.view.sel().clear()
- edit = self.view.begin_edit("hipster_ipsum")
- self.manageThreads(edit, threads)
+ self.manageThreads(threads)
else:
sublime.status_message("Hipster Ipsum: No authentic selections.")
err("Skipped %i selections." % skippedThreads)
- def manageThreads(self, theEdit, theThreads, offset=0, i=0, direction=1):
+ def manageThreads(self, theThreads, offset=0, i=0, direction=1):
next_threads = []
for thread in theThreads:
if thread.is_alive():
next_threads.append(thread)
continue
if thread.result == False:
continue
- offset = self.replace(theEdit, thread, offset)
+ offset = self.replace(thread, offset)
theThreads = next_threads
if len(theThreads):
@@ -82,15 +83,14 @@ def manageThreads(self, theEdit, theThreads, offset=0, i=0, direction=1):
i += direction
self.view.set_status("hipster_ipsum", "Gentrifying... [%s=%s]" % (" " * before, " " * after))
- sublime.set_timeout(lambda: self.manageThreads(theEdit, theThreads, offset, i, direction), 100)
+ sublime.set_timeout(lambda: self.manageThreads(theThreads, offset, i, direction), 100)
return
- self.view.end_edit(theEdit)
self.view.erase_status("hipster_ipsum")
selections = len(self.view.sel())
sublime.status_message("%s area%s gentrified." % (selections, '' if selections == 1 else 's'))
- def replace(self, theEdit, theThread, offset):
+ def replace(self, theThread, offset):
selection = theThread.selection
original = theThread.original
result = theThread.result
@@ -99,7 +99,7 @@ def replace(self, theEdit, theThread, offset):
selection = sublime.Region(selection.begin() + offset, selection.end() + offset)
result = self.normalize_line_endings(result)
- self.view.replace(theEdit, selection, result)
+ self.view.run_command("hipster_ipsum_replace", {"begin": selection.begin(), "end": selection.end(), "data": result})
endpoint = selection.begin() + len(result)
self.view.sel().add(sublime.Region(endpoint, endpoint))
@@ -128,18 +128,19 @@ def __init__(self, theSelection, numParagraphs, ipsumType, useHTML, originalStri
def run(self):
params = {"paras": self.paragraphs, "type": self.ipsumType, "html": self.useHTML}
- query = urllib.urlencode(params)
- uriString = "http://hipsterjesus.com/api/?" + query
+
try:
- connection = urllib2.urlopen(uriString)
- data = json.load(connection)
- self.result = data["text"]
- return
- except urllib2.HTTPError as e:
- error = "HTTP error " + str(e.code)
- err(error)
- except urllib2.URLError as e:
- error = "URL error " + str(e.reason)
- err(error)
-
- self.result = False
+ r = requests.get("http://hipsterjesus.com/api/", params=params)
+ except Exception as e:
+ err("Exception: %s" % e)
+ self.result = False
+
+ data = r.json()
+ self.result = data["text"]
+
+class HipsterIpsumReplaceCommand(sublime_plugin.TextCommand):
+ def run(self, edit, begin, end, data):
+ a = long(begin) if int(sublime.version()) < 3000 else begin
+ b = long(end) if int(sublime.version()) < 3000 else end
+ region = sublime.Region(a, b)
+ self.view.replace(edit, region, data)
View
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+
+# __
+# /__) _ _ _ _ _/ _
+# / ( (- (/ (/ (- _) / _)
+# /
+
+"""
+requests HTTP library
+~~~~~~~~~~~~~~~~~~~~~
+
+Requests is an HTTP library, written in Python, for human beings. Basic GET
+usage:
+
+ >>> import requests
+ >>> r = requests.get('http://python.org')
+ >>> r.status_code
+ 200
+ >>> 'Python is a programming language' in r.content
+ True
+
+... or POST:
+
+ >>> payload = dict(key1='value1', key2='value2')
+ >>> r = requests.post("http://httpbin.org/post", data=payload)
+ >>> print r.text
+ {
+ ...
+ "form": {
+ "key2": "value2",
+ "key1": "value1"
+ },
+ ...
+ }
+
+The other HTTP methods are supported - see `requests.api`. Full documentation
+is at <http://python-requests.org>.
+
+:copyright: (c) 2013 by Kenneth Reitz.
+:license: Apache 2.0, see LICENSE for more details.
+
+"""
+
+__title__ = 'requests'
+__version__ = '1.1.0'
+__build__ = 0x010100
+__author__ = 'Kenneth Reitz'
+__license__ = 'Apache 2.0'
+__copyright__ = 'Copyright 2013 Kenneth Reitz'
+
+
+from . import utils
+from .models import Request, Response, PreparedRequest
+from .api import request, get, head, post, patch, put, delete, options
+from .sessions import session, Session
+from .status_codes import codes
+from .exceptions import (
+ RequestException, Timeout, URLRequired,
+ TooManyRedirects, HTTPError, ConnectionError
+)
+
+# Set default logging handler to avoid "No handler found" warnings.
+import logging
+try: # Python 2.7+
+ from logging import NullHandler
+except ImportError:
+ class NullHandler(logging.Handler):
+ def emit(self, record):
+ pass
+
+logging.getLogger(__name__).addHandler(NullHandler())
Oops, something went wrong.

0 comments on commit abb43de

Please sign in to comment.