Exemplo n.º 1
0
 def _drill_into_Zone_Facet(self, url):
     self.request = urllib2.Request(url)
     self.request.add_header("Referer", self.referer)
     self.browser.open(self.request)
     c = self.browser.response().read()
     self.soup = BeautifulSoup.BeautifulSoup(c)
     self.forms = self.soup.findAll('form')
     self.d_newForm_actions = lists.HashedLists2()
     for f in self.forms:
         self.d_newForm = lists.HashedLists2()
         self.d_form = lists.HashedFuzzyLists2(dict(f.attrs))
         if (self.d_form['name'] == 'add'):
             children = f.findChildren('input')
             for aChild in children:
                 self.d_child = lists.HashedFuzzyLists2(dict(aChild.attrs))
                 self.d_newForm[
                     self.d_child['name']] = self.d_child['value']
             action = self.d_form['action']
             self.d_newForm_actions[self.d_form['name']] = action
             if (callable(self.callback_addForm)):
                 try:
                     self.callback_addForm(self, action=action)
                 except:
                     pass
         elif (self.d_form['name'] == 'edit'):
             children = f.findChildren('input')
             self.tuples = []
             self.d_tuples = lists.HashedFuzzyLists2()
             elements = []
             pattern = ['id', 'oldfrom', 'oldto', 'del']
             p = []
             for aChild in children:
                 d_form = lists.HashedLists2(dict(aChild.attrs))
                 name = str(d_form['name'])
                 if (pattern[len(p)] == name):
                     elements.append(d_form)
                     p.append(name)
                     if (p == pattern):
                         self.tuples.append(elements)
                         oldfrom = [
                             e for e in elements if (e['name'] == 'oldfrom')
                         ]
                         oldto = [
                             e for e in elements if (e['name'] == 'oldto')
                         ]
                         if (len(oldfrom) == 1) and (len(oldto) == 1):
                             self.d_tuples[oldfrom[0]['value']] = oldto[0][
                                 'value'], elements
                         elements = []
                         p = []
             action = self.d_form['action']
             self.d_newForm_actions[self.d_form['name']] = action
             if (callable(self.callback_editForm)):
                 try:
                     self.callback_editForm(self, action=action)
                 except:
                     pass
Exemplo n.º 2
0
    def __init__(self, username=None, password=None, token=None):
        self.__sfQuery__ = None
        self.__lastError__ = ''
        self.__factory = None
        self.__save_result = []
        self.__save_result_isValid = False
        self.__description__ = None
        self.__descriptions__ = SmartFuzzyObject({})
        self.__names__ = None
        self.object_name = None

        self.__username__ = username
        self.__password__ = password
        self.__token__ = token
        self.__endPoint__ = None
        self.__sfLoginModel__ = None
        self.__api_version__ = 14
        self.__types__ = lists.HashedFuzzyLists2()
        self.__objectStack__ = []
        self.__fieldsStack__ = []
        self.__filterStack__ = []
        self.__orderByStack__ = []
        self.__quoted__ = lambda val: "'" if (not str(val).isdigit()) else ''

        self.__reset_magic__()
Exemplo n.º 3
0
def get_packages(browser, url, username, password, logging=None):
    '''Returns a list of items as follows:
    (u'/pypi?%3Aaction=logout', {u'/pypi': {u'%3Aaction': u'logout'}}, u'Logout')
    '''
    import urllib2
    from vyperlogix.url import _urllib2

    browser.add_password(url, username, password)

    packages = []

    try:
        req = urllib2.Request(url)
        req.add_header("Referer", url.split('?')[0])
        browser.open(req)
        for aLink in browser.links():
            d_attrs = lists.HashedFuzzyLists2(dict(aLink.attrs))
            _href = d_attrs['href']
            toks = _urllib2.parse_href_into_parms(_href)[-1]
            if (all([isinstance(t, list) for t in toks])):
                try:
                    d_parms = lists.HashedFuzzyLists2(
                        dict([tuple(t) for t in toks]))
                except:
                    d_parms = lists.HashedFuzzyLists2()
                if ((d_parms[':action']) or
                    (d_parms['%3Aaction'])) and (d_parms['name']):
                    href = aLink.url
                    text = aLink.text
                    toks = [[x.split('=') for x in tt]
                            for tt in [t.split('&') for t in href.split('?')]]
                    d = lists.HashedLists2()
                    d[toks[0][0][0]] = lists.HashedLists2(
                        dict([tuple(t) for t in toks[-1]]))
                    _datum = tuple([href, d, text])
                    dd = d[d.keys()[0]]
                    if (dd is not None) and (misc.isString(
                            str(dd['name']) if (
                                dd['name'] is not None) else dd['name'])):
                        packages.append(_datum)
    except Exception as e:
        info_string = _utils.formattedException(details=e)
        if (logging is not None):
            logging.warning(info_string)
        print >> sys.stderr, info_string
    return packages
Exemplo n.º 4
0
 def fget(self):
     if (self.__metadata_by_names__ is None):
         d = lists.HashedFuzzyLists2()
         for k, aField in self.description.metadata['fields'].iteritems(
         ):
             d[k] = aField
         self.__metadata_by_names__ = d
     return self.__metadata_by_names__
Exemplo n.º 5
0
 def __processForm__(self, d_form, action):
     url = '%s%s%s' % (self.url, '/' if
                       (not self.url.endswith('/')) else '', action)
     request = urllib2.Request(url)
     request.add_header("Referer", self.referer)
     data = urllib.urlencode([(k, v) for k, v in d_form.iteritems()])
     self.browser.open(request, data)
     c = ''.join([
         l.strip() for l in self.browser.response().readlines()
         if (len(l.strip()) > 0)
     ])
     soup = BeautifulSoup.BeautifulSoup(c)
     forms = soup.findAll('form')
     for f in forms:
         d_newForm = lists.HashedLists2()
         d_form = lists.HashedFuzzyLists2(dict(f.attrs))
         if (d_form['name'] == 'edit'):
             submits = []
             children = f.findChildren('input')
             for aChild in children:
                 d_child = lists.HashedFuzzyLists2(dict(aChild.attrs))
                 if (d_child['type'] == 'submit'):
                     submits.append(d_child)
                 else:
                     d_newForm[d_child['name']] = d_child['value']
             url = '%s%s%s' % (self.url, '/' if
                               (not self.url.endswith('/')) else '',
                               d_form['action'])
             request = urllib2.Request(url)
             request.add_header("Referer", self.referer)
             try:
                 aSubmit = [
                     aSubmit for aSubmit in submits
                     if (aSubmit['value'].lower() == 'yes')
                 ][0]
                 d_newForm[aSubmit['name']] = aSubmit['value']
             except:
                 pass
             data = urllib.urlencode([(k, v)
                                      for k, v in d_newForm.iteritems()])
             self.browser.open(self.request, data)
Exemplo n.º 6
0
 def fget(self):
     if (self.__fields_by_metadata__ is None):
         d = lists.HashedFuzzyLists2()
         for k, aField in self.description.metadata['fields'].iteritems(
         ):
             for name, value in aField.iteritems():
                 if (d[name] is None):
                     d[name] = lists.HashedFuzzyLists()
                 _d = d[name][0] if (isinstance(d[name],
                                                list)) else d[name]
                 _d[value] = aField
         self.__fields_by_metadata__ = d
     return self.__fields_by_metadata__
Exemplo n.º 7
0
    def __init__(self,username=None,password=None,token=None):
	# Note: SalesForceAbstract.__init__() appears below where it should... never mind about doing anything about it here.
        self.__username__ = username
        self.__password__ = password
        self.__token__ = token
        self.__endPoint__ = None
        self.__sfLoginModel__ = None
        self.__api_version__ = 14
        self.__types__ = lists.HashedFuzzyLists2()
        self.__objectStack__ = []
        self.__fieldsStack__ = []
        self.__filterStack__ = []
        self.__orderByStack__ = []
        self.__quoted__ = lambda val:"'" if (not str(val).isdigit()) else ''
	
        self.__reset_magic__() # This is basically the init method for MagicObject2...
Exemplo n.º 8
0
def read_from_url(host,url):
    toks = host.split(':')
    host = toks[0]
    port = 80 if (len(toks) != 2) else toks[-1]
    conn = httplib.HTTPConnection(host,port=port)
    conn.request("GET", url)
    isError = False
    try:
        resp = conn.getresponse()
    except:
        isError = True
    data = ''
    if ( (isError == False) and (resp.status == 200) and (resp.reason == 'OK') ):
        data = resp.read()
    else:
        d = lists.HashedFuzzyLists2(resp.msg.dict)
        location = d['location']
        if (resp.status == 302):
            foo = urlparse.urlparse(location)
            return read_from_url(foo[1],foo[2])
    return data
Exemplo n.º 9
0
 def __init__(self, request, name, model, action, target='_top'):
     self.__model_choice_fields = lambda self: [
         field for field in [self.fields[k] for k in self.fields.keyOrder]
         if self.is_ModelChoiceField(field)
     ]
     self.__model__ = model
     self.__form_name__ = name
     self.__target__ = target
     self.__action__ = action
     self.__request__ = request
     self.__datasources__ = lists.HashedLists2(
     )  # datasource specifies the source of data for any given field name.
     self.__fields__ = fields.fields_for_model(model)
     self.__model_choice_fields__ = self.__model_choice_fields(self)
     self.__d_model_choice_fields__ = lists.HashedFuzzyLists2()
     for field in self.__model_choice_fields__:
         self.__d_model_choice_fields__[field.label] = field
     self.__choice_models__ = lists.HashedLists2()
     self.__choice_model_defaults__ = lists.HashedLists2()
     self.__last_error__ = ''
     self.__use_captcha__ = False
     self.__captcha_form_name__ = None
     self.__captcha_font_name__ = None
     self.__captcha_font_size__ = 18
     self.__captcha_choices__ = ''.join(
         chr(ch) for ch in xrange(ord('A'),
                                  ord('Z') + 1))
     self.__captcha_fill__ = (255, 255, 255)
     self.__captcha_bgImage__ = 'bg.jpg'
     self.__get_freehost_by_name__ = None
     self.__datetime_field_content__ = ''
     self.__submit_button_title__ = 'Submit Button Title'
     self.__submit_button_value__ = 'Submit Button Value'
     self.__field_validations__ = [
     ]  # list of tuples where first element is a lambda and the second element is a dict that connects context elements to error messages when validation fails.
     self.__hidden_fields__ = lists.HashedLists2()
     self.__field_ordering__ = [
     ]  # list of field names to be used to render the fields as HTML.
     self.__extra_fields__ = lists.HashedLists2()