def resolve_snippets(ctx): cl = set() types = [''] if ctx.get('local') else ctx.get('types') vars = {} for k, v in ctx.iteritems(): if gs.is_a_string(v): vars[k] = v try: snips = [] snips.extend(gs.setting('default_snippets', [])) snips.extend(gs.setting('snippets', [])) for m in snips: try: if snippet_match(ctx, m): for ent in m.get('snippets', []): text = ent.get('text', '') title = ent.get('title', '') value = ent.get('value', '') if text and value: for typename in types: vars['typename'] = typename vars['typename_abbr'] = typename[0].lower( ) if typename else '' txt, ttl, val = expand_snippet_vars( vars, text, title, value) s = u'%s\t%s \u0282' % (txt, ttl) cl.add((s, val)) except: gs.notice(DOMAIN, gs.traceback()) except: gs.notice(DOMAIN, gs.traceback()) return list(cl)
def resolve_snippets(ctx): cl = set() types = [''] if ctx.get('local') else ctx.get('types') vars = {} for k,v in ctx.iteritems(): if gs.is_a_string(v): vars[k] = v try: snips = [] snips.extend(gs.setting('default_snippets', [])) snips.extend(gs.setting('snippets', [])) for m in snips: try: if snippet_match(ctx, m): for ent in m.get('snippets', []): text = ent.get('text', '') title = ent.get('title', '') value = ent.get('value', '') if text and value: for typename in types: vars['typename'] = typename vars['typename_abbr'] = typename[0].lower() if typename else '' txt, ttl, val = expand_snippet_vars(vars, text, title, value) s = u'%s\t%s \u0282' % (txt, ttl) cl.add((s, val)) except: gs.notice(DOMAIN, gs.traceback()) except: gs.notice(DOMAIN, gs.traceback()) return list(cl)
def expand_jdata(v): if gs.is_a(v, {}): for k in v: v[k] = expand_jdata(v[k]) elif gs.is_a_string(v) and v.startswith('base64:'): try: v = base64.b64decode(v[7:]) except Exception: v = '' gs.error_traceback(DOMAIN) return v
def snippet_match(ctx, m): try: for k,p in m.get('match', {}).iteritems(): q = ctx.get(k, '') if p and gs.is_a_string(p): if not re.search(p, str(q)): return False elif p != q: return False except: gs.notice(DOMAIN, gs.traceback()) return True
def snippet_match(ctx, m): try: for k, p in m.get('match', {}).iteritems(): q = ctx.get(k, '') if p and gs.is_a_string(p): if not re.search(p, str(q)): return False elif p != q: return False except: gs.notice(DOMAIN, gs.traceback()) return True
def resolve_snippets(ctx): cl = set() types = [""] if ctx.get("local") else ctx.get("types") vars = {} for k, v in ctx.iteritems(): if gs.is_a_string(v): vars[k] = v try: snips = [] snips.extend(gs.setting("default_snippets", [])) snips.extend(gs.setting("snippets", [])) for m in snips: try: if snippet_match(ctx, m): for ent in m.get("snippets", []): text = ent.get("text", "") title = ent.get("title", "") value = ent.get("value", "") if text and value: for typename in types: vars["typename"] = typename if typename: if len(typename) > 1 and typename[0].islower() and typename[1].isupper(): vars["typename_abbr"] = typename[1].lower() else: vars["typename_abbr"] = typename[0].lower() else: vars["typename_abbr"] = "" txt, ttl, val = expand_snippet_vars(vars, text, title, value) s = u"%s\t%s \u0282" % (txt, ttl) cl.add((s, val)) except: gs.notice(DOMAIN, gs.traceback()) except: gs.notice(DOMAIN, gs.traceback()) return list(cl)