Daniel Graña avatar Daniel Graña committed 9e70e69

minimize data dicts returned by handlers and reuse **opts expansion

Comments (0)

Files changed (1)

 #!/usr/bin/env python
-
-'''send diffs from Mercurial to various pastebin websites
-'''
+'''Send diffs from Mercurial to various pastebin websites'''
 
 import sys
 import urllib2
 from mercurial import cmdutil, commands, help, util
 from urllib import urlencode
 
-def _paste_dpaste(content, **parameters):
-    data = {'content': content, 'language': parameters['syntax'] or 'Diff'}
-    if parameters['title']:
-        data['title'] = parameters['title']
-    if parameters['user']:
-        data['poster'] = parameters['user']
 
-    if len(data['poster']) > 30:
-        data['poster'] = data['poster'][:30]
+def _paste_dpaste(content, syntax, title, user, keep, **kw):
+    return {
+            'content': content, 
+            'language': syntax or 'Diff',
+            'title': title,
+            'poster': user[:30],
+            'hold': 'on' if keep else 'off',
+            }
 
-    if parameters['keep']:
-        data['hold'] = 'on'
-    return data
+def _paste_dpaste_org(content, syntax, title, user, keep, **kw):
+    return {
+            'content': content,
+            'lexer': syntax or 'diff',
+            'title': title,
+            'poster': user[:30],
+            'expire_options': '3110400000' if keep else '2592000',
+            }
 
-def _paste_dpaste_org(content, **parameters):
-    data = {'content': content, 'lexer': parameters['syntax'] or 'diff'}
-    if parameters['title']:
-        data['title'] = parameters['title']
-    if parameters['user']:
-        data['author'] = parameters['user']
-
-    if len(data['author']) > 30:
-        data['author'] = data['author'][:30]
-
-    # Same values used in dpaste.org form for default (a month) and forever expires.
-    data['expire_options'] = '3110400000' if parameters['keep'] else '2592000'
-    return data
-
-def _paste_pastebin_dixo_net(content, **parameters):
+def _paste_pastebin_dixo_net(content, syntax, user, keep, **kw):
     return {
             'paste': 'Send',
             'code2': content,
-            'format': parameters['syntax'] or 'diff',
-            'expiry': 'f' if parameters['keep'] else 'm',
-            'poster': parameters.get('user', ''),
+            'format': syntax or 'diff',
+            'poster': user,
+            'expiry': 'f' if keep else 'm',
             }
 
 
             b64cred = urlsafe_b64encode('%s:%s' % (cred[0], cred[2]))
             request.add_header('Authorization', 'Basic %s' % b64cred)
 
-def _do_paste(pastebin, content, parameters):
-    url = parameters.get('url') or pastebin['url']
-    data = pastebin['handler'](content, **parameters)
+def _do_paste(pastebin, content, opts):
+    url = opts['url'] or pastebin['url']
+    data = pastebin['handler'](content, **opts)
     request = urllib2.Request(url, urlencode(data))
-    _authorize_request(request, **parameters)
+    _authorize_request(request, **opts)
     response = urllib2.urlopen(request)
     geturl = pastebin.get('geturl')
     return geturl(response) if geturl else response.geturl()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.