(Lazy)load list of all supported symbols (sorted)

    Look into `_data()` for all currency symbols, then sort by length and
    unicode-ord (A-Z is not as relevant as ֏).

    Returns:
        List[unicode]: Sorted list of possible currency symbols.
1938
def _symbols():
    
    global _SYMBOLS
    if _SYMBOLS is None:
        tmp = [(s, 'symbol') for s in _data()['symbol'].keys()]
        tmp += [(s, 'alpha3') for s in _data()['alpha3'].keys()]
        tmp += [(s.name, 'name') for s in _data()['alpha3'].values()]
        _SYMBOLS = sorted(
            tmp,
            key=lambda s: (len(s[0]), ord(s[0][0])),
            reverse=True)

    return _SYMBOLS
443558
def convert(data):
    
    if isinstance(data, unicode):
        return data.encode('utf-8')
    elif isinstance(data, str):
        return data
    elif isinstance(data, collections.Mapping):
        return dict(map(convert, data.iteritems()))
    elif isinstance(data, collections.Iterable):
        return type(data)(map(convert, data))
    else:
        return data
1290747
def symbols_to_prob(symbols):
    '''
    
    '''
    myCounter = Counter(symbols)

    N = float(len(list(symbols)))   # symbols might be a zip object in python 3

    for k in myCounter:
        myCounter[k] /= N

    return myCounter
191747
def _symbol_trades(self, symbols):
        '''
        
        '''

        @skip_http_error((404, 504))
        def fetch(symbol):
            return self._api.polygon.last_trade(symbol)

        return parallelize(fetch)(symbols)
1082345
def supported_currencies(self, project='moneywagon', level="full"):
        
        ret = []
        if project == 'multiexplorer-wallet':
            for currency, data in self.sorted_crypto_data:
                if not data.get("bip44_coin_type"):
                    continue
                if len(data.get('services', {}).get("push_tx", [])) < 1:
                    continue
                if len(data.get('services', {}).get("historical_transactions", [])) < 1:
                    continue
                if len(data.get('services', {}).get("single_transaction", [])) < 1:
                    continue
                if len(data.get('services', {}).get("unspent_outputs", [])) < 1:
                    continue
                ret.append(currency)

            altcore_tx = self.supported_currencies('altcore', level="transaction")
            return [x for x in ret if x in altcore_tx]

        for symbol, data in self.sorted_crypto_data:
            if symbol == '': # template
                continue
            if self.is_all_supported(data, project, level):
                ret.append(symbol)
        return ret
730401
private function getCurrencies()
    {
        if (null === self::$currencies) {
            self::$currencies = $this->loadCurrencies();
        }

        return self::$currencies;
    }
1106743
def get_currency_symbol(self):
        
        currency = self.context.bika_setup.getCurrency()
        locale = locales.getLocale("en")
        locale_currency = locale.numbers.currencies.get(currency)
        if locale_currency is None:
            return "$"
        return locale_currency.symbol
276362
def to_utf8(self, data):
        
        # if this is a unicode string, return its string representation
        if isinstance(data, unicode):
            return data.encode('utf-8')

        # if this is a list of values, return list of string values
        if isinstance(data, list):
            return [self.to_utf8(item) for item in data]

        # if this is a dictionary, return dictionary of string keys and values
        if isinstance(data, dict):
            return {
                self.to_utf8(key): self.to_utf8(value)
                for key, value in data.iteritems()
            }

        # if it's anything else, return it in its original form
        return data
909702
def get_symbol_map(self):
        
        # todo: make sure we return a list of strings!
        sm = _libxdo.xdo_get_symbol_map()

        # Return value is like:
        # ['alt', 'Alt_L', ..., None, None, None, ...]
        # We want to return only values up to the first None.
        # todo: any better solution than this?
        i = 0
        ret = []
        while True:
            c = sm[i]
            if c is None:
                return ret
            ret.append(c)
            i += 1
587494
def get_symbols_with_positive_balances(self) -> List[str]:
        
        from gnucash_portfolio import BookAggregate

        holdings = []

        with BookAggregate() as book:
            # query = book.securities.query.filter(Commodity.)
            holding_entities = book.securities.get_all()
            for item in holding_entities:
                # Check holding balance
                agg = book.securities.get_aggregate(item)
                balance = agg.get_num_shares()
                if balance > Decimal(0):
                    holdings.append(f"{item.namespace}:{item.mnemonic}")
                else:
                    self.logger.debug(f"0 balance for {item}")
            # holdings = map(lambda x: , holding_entities)

        return holdings
4213
def to_unicode(data, encoding='UTF-8'):
    """"""
    if isinstance(data, unicode_type):
        return data

    if isinstance(data, bytes):
        return unicode_type(data, encoding=encoding)

    if hasattr(data, '__iter__'):
        try:
            dict(data)
        except TypeError:
            pass
        except ValueError:
            # Assume it's a one dimensional data structure
            return (to_unicode(i, encoding) for i in data)
        else:
            # We support 2.6 which lacks dict comprehensions
            if hasattr(data, 'items'):
                data = data.items()
            return dict(((to_unicode(k, encoding), to_unicode(v, encoding)) for k, v in data))

    return data
1367875
def get_currencysymbol(self, code):
        """"""
        if not self._symbols:
            symbolpath = os.path.join(self._dir, 'currencies.json')
            with open(symbolpath, encoding='utf8') as df:
                self._symbols = json.load(df)
        return self._symbols.get(code)
70332
def _extract_symbols(self, symbols, default=None):
        """"""
        to_ret = {}
        for symbol in symbols:
            symbolInfo = self.elf.symbol_decoder.get_symbol_for_name(symbol)
            if symbolInfo is None:
                if default is not None:
                    to_ret[symbol] = default
                    continue
                raise FlashAlgoException("Missing symbol %s" % symbol)
            to_ret[symbol] = symbolInfo.address
        return to_ret
1230641
def load_doge(self):
        

        if self.ns.no_shibe:
            return ['']

        with open(self.doge_path) as f:
            if sys.version_info < (3, 0):
                if locale.getpreferredencoding() == 'UTF-8':
                    doge_lines = [l.decode('utf-8') for l in f.xreadlines()]
                else:
                    # encode to printable characters, leaving a space in place
                    # of untranslatable characters, resulting in a slightly
                    # blockier doge on non-UTF8 terminals
                    doge_lines = [
                        l.decode('utf-8')
                        .encode(locale.getpreferredencoding(), 'replace')
                        .replace('?', ' ')
                        for l in f.xreadlines()
                    ]
            else:
                doge_lines = [l for l in f.readlines()]
            return doge_lines
707606
def symbol(currency, *, native=True):
	
	currency = validate_currency(currency)
	if native:
		return _currencies[currency]['symbol_native']
	return _currencies[currency]['symbol']
7622
def _to_unicode(self, data, encoding, errors='strict'):
    ''''''

    # strip Byte Order Mark (if present)
    if (len(data) >= 4) and (data[:2] == '\xfe\xff') and (data[2:4] != '\x00\x00'):
        encoding = 'utf-16be'
        data = data[2:]
    elif (len(data) >= 4) and (data[:2] == '\xff\xfe') and (data[2:4] != '\x00\x00'):
        encoding = 'utf-16le'
        data = data[2:]
    elif data[:3] == '\xef\xbb\xbf':
        encoding = 'utf-8'
        data = data[3:]
    elif data[:4] == '\x00\x00\xfe\xff':
        encoding = 'utf-32be'
        data = data[4:]
    elif data[:4] == '\xff\xfe\x00\x00':
        encoding = 'utf-32le'
        data = data[4:]
    newdata = unicode(data, encoding, errors)
    return newdata
554800
def get_stocks(self, symbols: List[str]) -> List[Commodity]:
        
        query = (
            self.query
            .filter(Commodity.mnemonic.in_(symbols))
        ).order_by(Commodity.namespace, Commodity.mnemonic)
        return query.all()