def __str__(self): info = [] for k, v in self.__dict__.iteritems(): if (k != '_sa_instance_state'): info.append('%s --> %s' % (_utils.ascii_only(k), _utils.ascii_only(v))) ch = '\n' if (len(info) > 10) else ', ' return '(%s) %s' % (ObjectTypeName__typeName(self), ch.join(info))
def links(self, address): file_request = urllib2.Request(address) file_opener = urllib2.build_opener() file_feed = file_opener.open(file_request).read() items = [] file_feed = _utils.ascii_only(file_feed) try: file_xml = minidom.parseString(file_feed) item_nodes = file_xml.getElementsByTagName("url") for item in item_nodes: nodes = [] for node in [ n for n in item.childNodes if (n.nodeName == 'loc') ]: try: nodes.append(node.firstChild.data) except: pass for n in nodes: items.append(n) except Exception as e: info_string = _utils.formattedException(details=e) items.append(info_string) items.append(str(file_feed)) return items
def __get_top_trending_hashtags(api): data = api.trends_place(1) hashtags = dict([ tuple([trend['name'], trend['tweet_volume']]) for trend in data[0]['trends'] if (trend['name'].startswith('#')) and ( len(_utils.ascii_only(trend['name'])) == len(trend['name'])) ]) return _utils.sorted_dict(hashtags, reversed=True, default=-1)
def weave_into(target, phrase): from vyperlogix.iterators import iterutils normalize = lambda foo, m: foo + ('00' * (m - (len(foo) / 2)) if ((len(foo) / 2) < m) else '') results = [] target = _utils.ascii_only(target) phrase = _utils.ascii_only(phrase) m = max(len(target) / 2, len(phrase) / 2) m += m % 2 target = normalize(target, m) phrase = normalize(phrase, m) assert len(target) == len( phrase), 'ERROR: Something went wrong with the normalization in %s' % ( misc.funcName()) pGen = (pCh for pCh in iterutils.itergroup([p for p in phrase], 2)) for t in iterutils.itergroup([i for i in target], 2): results.append(''.join(t)) results.append(''.join(pGen.next())) return ''.join(results)
def _process(self, xml=None): d = lists.HashedLists() def recurse_into(aTag): _d_ = lists.HashedLists() is_tag = lambda t: (misc.ObjectTypeName.typeClassName(t) == 'xml.dom.minidom.Element') if (is_tag(aTag)): _d_[aTag.nodeName] = lists.HashedLists( dict(aTag.attributes.items())) for aKid in aTag.childNodes: if (is_tag(aKid)): if (self.verbose): print misc.ObjectTypeName.typeClassName( aKid), aKid.nodeName node = recurse_into(aKid) for k, v in node.iteritems(): misc._unpack_( _d_[aTag.nodeName])[k] = misc._unpack_(v) if (callable(self.callback)): self.callback( k, misc._unpack_( misc._unpack_(_d_[aTag.nodeName])[k])) if (callable(self.callbackNodeName)): _k_ = self.callbackNodeName(k) if (k != _k_): _x_ = misc._unpack_(_d_[aTag.nodeName]) del _x_[k] _x_[_k_] = misc._unpack_(v) pass pass else: try: misc._unpack_( _d_[aTag.nodeName])['data'] = aKid.data except: pass return _d_ if (xml is not None): self.xml = _utils.ascii_only(xml) dom = parseString(self.xml) for aChild in dom.childNodes: d[aChild.nodeName] = recurse_into(aChild) try: __d = misc._unpack_(d[aChild.nodeName]) if (__d.has_key(aChild.nodeName)) and (len( list(set(__d.keys()) - set([aChild.nodeName]))) == 0): d = __d except Exception as e: print 'ERROR', _utils.formattedException(details=e) if (self.verbose): print '=' * 40 return d
def __get_aws_credentials__(contents, method=Methods.default): from vyperlogix.iterators import iterutils _contents_, passphrase = (contents, None) if (method is Methods.improved): _contents_, passphrase = unweave_from(contents) passphrase = oodb.hexToStr(passphrase) if ( misc.isString(passphrase)) else __passphrase__ assert passphrase == __passphrase__, 'WARNING: Something has gone wrong with the passPhrase.' contents = blowfish.decryptData(oodb.hexToStr(_contents_), passphrase) contents = contents.split(chr(0x00))[0] d = HashedLists2(fromDict=dict([ tt.split('=') for tt in [t.strip() for t in contents.split('\n')] if (len(tt) > 0) ])) if (method is not Methods.improved): for k, v in d.iteritems(): _k_ = _utils.ascii_only( blowfish.decryptData(oodb.hexToStr(k), __passphrase__)) d[_k_] = _utils.ascii_only( blowfish.decryptData(oodb.hexToStr(v), __passphrase__)) del d[k] return SmartObject.SmartFuzzyObject(args=d.asDict(isCopy=True))
def process(self, html=None): l = lists.HashedLists() n = 1 def recurse_into(aTag, _list=lists.HashedLists(), n=1): is_tag = lambda t: (misc.ObjectTypeName.typeClassName(t) == 'BeautifulSoup.Tag') is_valid_tag = lambda t: (t.name in ['table', 'tr', 'th', 'td']) if (is_tag(aTag)) and (is_valid_tag(aTag)): for aKid in aTag.childGenerator() if ( is_valid_tag(aTag)) else []: if (is_tag(aKid)): print misc.ObjectTypeName.typeClassName( aKid), aKid.name, if (aKid.name == 'table'): recurse_into(aKid, _list=_list, n=n) elif (aKid.name == 'tr'): n += 1 print recurse_into(aKid, _list=_list, n=n) elif (aKid.name in ['th', 'td']): data = aKid.contents if (misc.isList( aKid.contents)) and (len( aKid.contents) == 1) else [ misc.unpack([ t for t in aKid.contents if (not is_tag(t)) ]) ] print data _list['%s' % (n)] = data return if (html is not None): self.html = _utils.ascii_only(html) soup = BeautifulSoup.BeautifulSoup(self.html) tables = soup.findAll('table') for aTable in tables: recurse_into(aTable, _list=l, n=n) print '=' * 40 keys = misc.sortCopy([int(k) for k in l.keys()]) items = ListWrapper() for k in keys: _items = l['%s' % (k)] items.append([_items]) return items
def walk_nodes(self, url, callback=None): self.referer = 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 = BeautifulStoneSoup(c) try: item_nodes = self.soup.findAll("item") for item in item_nodes: so = SmartObject.SmartObject() for node in item.recursiveChildGenerator(): if (ObjectTypeName.typeClassName(node) == 'BeautifulSoup.Tag') and (node.string): so[node.name] = _utils.ascii_only( node.string.extract()) if (callable(callback)): callback(so) except Exception as e: info_string = _utils.formattedException(details=e) so = SmartObject.SmartObject() s.info_string = info_string items.append(so)
USE AT YOUR OWN RISK. """ from vyperlogix.misc import _utils from vyperlogix.enum.Enum import Enum class DictWalkOptions(Enum): keys_and_values = 1 keys_only = 2 values_only = 4 keys_and_values_and_top = 8 encode = lambda value: ''.join( [c if (c != '_') else chr(ord(c) + 128) for c in _utils.ascii_only(value)]) def flatten(d, parent_key='', delim='_'): ''' Care must be taken to ensure keys do not have "_" or bad evil things can happen. ''' items = [] for k, v in d.items(): try: items.extend(flatten(v, '%s%s%s' % (parent_key, k, delim)).items()) except AttributeError: items.append(('%s%s' % (parent_key, k), v)) return dict(items)
def fset(self, html): self.__html__ = _utils.ascii_only(html)
__passphrase__ = 'V~scHqj]V$HdCe/)34"3dN:gAcT`uJrk&-Kt1}mqb"_y;0W=5$jnVi|_' #__url__ = 'http://cdn-python.s3-website-us-east-1.amazonaws.com/credentials_secure.txt' #x = oodb.strToHex(blowfish.encryptData(__url__, __passphrase__)) __url__ = '2E7BC64BCDCBED1751A179A330C9BB772091684720523EAE3567C79B9272F129763242FC370DB7E3183CECCC6A4878D6E301ED66B2EFF878B078325025A27B20169FECC6FF4456755B43E0812B060B8C' class Methods(Enum.Enum): none = 0 default = 2 ^ 0 improved = 2 ^ 2 decrypt = lambda encrypted: _utils.ascii_only( blowfish.decryptData(oodb.hexToStr(encrypted), __passphrase__)) def _url_(): return decrypt(__url__) def unweave_from(contents): from vyperlogix.iterators import iterutils target = [] phrase = [] for t in iterutils.itergroup([i for i in contents.strip()], 4): _t_ = list(t) n = len(_t_) / 2 target.append(''.join(_t_[0:n])) phrase.append(''.join(_t_[n:]))
def fset(self, xml): self.__xml__ = _utils.ascii_only(xml)