Commits

Rolando Espinoza committed 34def0e

added support for custom url and http authorization
e.g. hg paste -d dpaste.org --url https://paste.mysite.com --httpauth 'myuser:mypass'

Sign-Off: Rolando Espinoza La fuente

Comments (0)

Files changed (1)

 '''send diffs from Mercurial to various pastebin websites
 '''
 
+import base64
 import urllib2
 from mercurial import cmdutil, commands, help, util
 from urllib import urlencode
         data['title'] = parameters['title']
     if parameters['user']:
         data['poster'] = parameters['user']
+
+    if len(data['poster']) > 30:
+        data['poster'] = data['poster'][:30]
+
     if parameters['keep']:
         data['hold'] = 'on'
     data = urlencode(data)
     
-    request = urllib2.Request(pastebins['dpaste']['url'], data)
+    if parameters['url']:
+        url = parameters['url']
+    else:
+        url = pastebins['dpaste']['url']
+ 
+    request = urllib2.Request(url, data)
+    if parameters['httpauth']:
+        request.add_header('Authorization', 'Basic %s' \
+                    % base64.encodestring(parameters['httpauth'])[:-1])
     response = urllib2.urlopen(request)
-    
-    location = response.geturl()
-    return location
+    return response.geturl()
 
 def _paste_dpaste_org(content, **parameters):
     data = {'content': content, 'lexer': 'diff'}
         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'
     data = urlencode(data)
+
+    if parameters['url']:
+        url = parameters['url']
+    else:
+        url = pastebins['dpaste.org']['url']
     
-    request = urllib2.Request(pastebins['dpaste.org']['url'], data)
+    request = urllib2.Request(url, data)
+    if parameters['httpauth']:
+        request.add_header('Authorization', 'Basic %s' \
+                    % base64.encodestring(parameters['httpauth'])[:-1])
     response = urllib2.urlopen(request)
     return response.geturl()
 
         ('k', 'keep', False, 'specify that the pastebin should keep the paste '
                              'for as long as possible (optional)'),
         ('',  'dry-run', False, 'do not paste to the pastebin'),
+        ('',  'url', '', 'perform request against this url'),
+        ('',  'httpauth', '', 'http authorization (user:pass)'),
     ] + commands.diffopts + commands.walkopts,
     'hg paste [OPTION] [-r REV] [FILE...]')
 }