Exemplo n.º 1
0
 def __getattr__(self, name):
     value = super(API, self).__getattr__(name)
     if (value is None) or (len(value) == 0):  # and (name != '/'):
         _d_ = HashedFuzzySmartLists({})
         _values_ = []
         for k in self.keys():
             if (misc.isDict(super(API, self).__getattr__(k))) and (super(
                     API, self).__getattr__(k).has_key('url')):
                 _k_ = super(API, self).__getattr__(k)['url'].replace(
                     '/' + k.split('@')[0], '')
                 _d_[_k_] = SmartFuzzyObject(
                     super(API, self).__getattr__(k))
         l = ListWrapper(_d_.keys())
         _name_ = name.split(API.make_key('', ''))[-1]
         if (not self.__specific__):
             while (len(_name_) > 0):
                 _list_ = l.findAllContaining(_name_) if (
                     _name_ != '/') else l.findAllMatching(_name_)
                 _items_ = [
                     item for item in _list_ if (item.endswith(_name_))
                 ]
                 x = l.findFirstMatching(_items_[0] if (
                     len(_items_) > 0) else _name_) if (
                         (len(_list_) > 0) or
                         (_name_ == '/')) else l.findFirstContaining(
                             _items_[0] if (len(_items_) > 0) else _name_)
                 if (x > -1):
                     for v in _d_[l[x]]:
                         _values_.append(v)
                     break
                 else:
                     x = l.findFirstContaining(_name_)
                     if (x > -1):
                         for v in _d_[l[x]]:
                             _values_.append(v)
                         break
                     else:
                         _l_ = _name_.split('/')
                         del _l_[-2 if (len(_l_[-1]) == 0) else -1]
                         _name_ = '/'.join(_l_)
     return value if (len(_values_) == 0) else _values_
Exemplo n.º 2
0
 def __getattr__(self, name):
     value = super(API, self).__getattr__(name)
     if (value is None) or (value == []):
         l = ListWrapper(self.keys())
         x = l.findFirstContaining(
             API.make_key(
                 name.split(API.make_key('', ''))[-1], APIVersion1001.
                 __version__) if (
                     name.startswith('/') and name.endswith('/')) else name)
         if (x > -1):
             return super(API, self).__getattr__(l[x])
         else:
             return super(APIVersion1001, self).__getattr__(name)
     return value
Exemplo n.º 3
0
    def parseMessage(self, data):
        from vyperlogix.lists.ListWrapper import ListWrapper

        def fuzzyCompare(_item, s_search):
            f = lambda _item, s_search: _item.lower().find(s_search.lower()
                                                           ) > -1
            does_match = f(_item, s_search)
            return does_match

        def emptyCompare(_item, s_search):
            f = lambda _item, s_search: str(_item).strip() == s_search
            does_match = f(_item, s_search)
            return does_match

        def parse_for_target(_toks, _target, callback=None):
            _val = ''
            i = _toks.findFirstContaining(_target, callback=callback)
            if (i > -1):
                _val = [_toks[i].split(_target)[-1]]
            return _val

        toks = ListWrapper(data.split('\n'))

        d = lists.HashedLists2()

        _f = toks.findFirstContaining('', callback=emptyCompare)
        if (_f > -1):
            _f -= 1

        d[const_headers_symbol] = tuple([t.strip() for t in toks[0:_f]])
        d[const_body_symbol] = tuple([t.strip() for t in toks[_f + 1:]])

        d[const_from_symbol] = parse_for_target(toks,
                                                const_from_symbol,
                                                callback=fuzzyCompare)

        d[const_to_symbol] = parse_for_target(toks,
                                              const_to_symbol,
                                              callback=fuzzyCompare)

        d[const_subject_symbol] = parse_for_target(toks,
                                                   const_subject_symbol,
                                                   callback=fuzzyCompare)

        return d
Exemplo n.º 4
0
Arquivo: g.py Projeto: raychorn/knowu
def send_php_email(url,parms={},is_html=False,data={},error_symbol=None):
    import urllib,urllib2

    content = ''
    try:
	__data__ = data # don't worry this line works...
	data = {}
	logging.warning('send_php_email().1 --> parms=%s' % (parms))
	if (len(parms.keys()) > 0):
	    _expected_keys = ['to','subject','body','altbody']
	    for k,v in parms.iteritems():
		if (k == 'altbody'):
		    data[k] = (v.replace('\n','').replace('\r','').replace("\'",'') if (k in _expected_keys) else '')
		else:
		    data[k] = (v.replace("\'",'') if (k in _expected_keys) else '')
	else:
	    data = {'to':'*****@*****.**', 'subject':'This is a test...', 'body':'<p>This is <b>just</b> a test...</p>', 'altbody':'This is just a test...'}
	logging.warning('send_php_email().2 --> data=%s' % (data))
	data = urllib.urlencode(data)
    
	user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
	headers = {'User-Agent':user_agent}
    
	req = urllib2.Request(url, data, headers)
	response = urllib2.urlopen(req)
	content = response.read()
	logging.warning('send_php_email().3 --> content=%s' % (content))
    except Exception, e:
	toks = ListWrapper(str(e).split())
	f = toks.findFirstContaining(']')
	message = 'send_php_email().ERROR --> "%s".' % (str(e))
	message2 = 'send_php_email().ERROR --> "%s".' % (' '.join(toks[f+1:f+1+5]+'...') if (f > -1) else str(e))
	if (error_symbol):
	    if (misc.isDict(__data__)):
		__data__[error_symbol] = message2
	logging.warning(message)