<commit_before># -*- coding: utf-8 -*-
from osv import fields, osv
import random
import re
import string
import urllib2
from tools.translate import _

class pad_common(osv.osv_memory):
    _name = 'pad.common'

    def pad_generate_url(self, cr, uid, context=None):
        pad_server = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.pad_server
        # make sure pad server in the form of http://hostname
        if not pad_server.startswith('http'):
            pad_server = 'http://' + pad_server
        pad_server = pad_server.rstrip('/')
        # generate a salt
        s = string.ascii_uppercase + string.digits
        salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(10)])
        # contruct the url
        url = '%s/p/%s-%s-%s' % (pad_server, cr.dbname, self._name, salt)
        return url

    def pad_get_content(self, cr, uid, url, context=None):
        content = ''
        if url:
            page = urllib2.urlopen('%s/export/html'%url).read()
            mo = re.search('<body>(.*)</body>',page)
            if mo:
                content = mo.group(1)
        return content

    # TODO
    # reverse engineer protocol to be setHtml without using the api key
    # override read and copy to generate url and store the content if empty

    def default_get(self, cr, uid, fields, context=None):
        data = super(pad_common, self).default_get(cr, uid, fields, context)<commit_msg>[FIX] pad: fix case of missing pad server<commit_after># -*- coding: utf-8 -*-
from osv import fields, osv
import random
import re
import string
import urllib2
from tools.translate import _

class pad_common(osv.osv_memory):
    _name = 'pad.common'

    def pad_generate_url(self, cr, uid, context=None):
        pad_server = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.pad_server
        # make sure pad server in the form of http://hostname
        if not pad_server:
            return ''
        if not pad_server.startswith('http'):
            pad_server = 'http://' + pad_server
        pad_server = pad_server.rstrip('/')
        # generate a salt
        s = string.ascii_uppercase + string.digits
        salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(10)])
        # contruct the url
        url = '%s/p/%s-%s-%s' % (pad_server, cr.dbname, self._name, salt)
        return url

    def pad_get_content(self, cr, uid, url, context=None):
        content = ''
        if url:
            page = urllib2.urlopen('%s/export/html'%url).read()
            mo = re.search('<body>(.*)</body>',page)
            if mo:
                content = mo.group(1)
        return content

    # TODO
    # reverse engineer protocol to be setHtml without using the api key
    # override read and copy to generate url and store the content if empty

    def default_get(self, cr, uid, fields, context=None):
        data = super(pad_common, self).default_get(cr, uid, fields, context)
{'fraction_non_alphanumeric': 0.12360688956433637, 'fraction_numerical': 0.005403579871664978, 'mean_word_length': 2.5053254437869823, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5140871', 'n_tokens_mistral': 933, 'n_tokens_neox': 916, 'n_words': 272}