text:
#
# (re)generate unicode property and type databases
#
# this script converts a unicode 3.2 database file to
# Modules/unicodedata_db.h, Modules/unicodename_db.h,
# and Objects/unicodetype_db.h
#
# history:
# 2000-09-24 fl   created (based on bits and pieces from unidb)
# 2000-09-25 fl   merged tim's splitbin fixes, separate decomposition table
# 2000-09-25 fl   added character type table
# 2000-09-26 fl   added LINEBREAK, DECIMAL, and DIGIT flags/fields (2.0)
# 2000-11-03 fl   expand first/last ranges
# 2001-01-19 fl   added character name tables (2.1)
# 2001-01-21 fl   added decomp compression; dynamic phrasebook threshold
# 2002-09-11 wd   use string methods
# 2002-10-18 mvl  update to Unicode 3.2
# 2002-10-22 mvl  generate NFC tables
# 2002-11-24 mvl  expand all ranges, sort names version-independently
# 2002-11-25 mvl  add UNIDATA_VERSION
# 2004-05-29 perky add east asian width information
# 2006-03-10 mvl  update to Unicode 4.1; add UCD 3.2 delta
#
# written by Fredrik Lundh (fredrik@pythonware.com)
#

import sys

SCRIPT = sys.argv[0]
VERSION = "2.5"

# The Unicode Database
UNIDATA_VERSION = "4.1.0"
UNICODE_DATA = "UnicodeData%s.txt"
COMPOSITION_EXCLUSIONS = "CompositionExclusions%s.txt"
EASTASIAN_WIDTH = "EastAsianWidth%s.txt"

old_versions = ["3.2.0"]

CATEGORY_NAMES = [ "Cn", "Lu", "Ll", "Lt", "Mn", "Mc", "Me", "Nd",
    "Nl", "No", "Zs", "Zl", "Zp", "Cc", "Cf", "Cs", "Co", "Cn", "Lm",
    "Lo", "Pc", "Pd", "Ps", "Pe", "Pi", "Pf", "Po", "Sm", "Sc", "Sk",
    "So" ]

BIDIRECTIONAL_NAMES = [ "", "L", "LRE", "LRO", "R", "AL", "RLE", "RLO",
    "PDF", "EN", "ES", "ET", "AN", "CS", "NSM", "BN", "B", "S", "WS",
    "ON" ]

EASTASIANWIDTH_NAMES = [ "F", "H", "W", "Na", "A", "N" ]

# note: should match definitions in Objects/unicodectype.c
ALPHA_MASK = 0x01
DECIMAL_MASK = 0x02
DIGIT_MASK = 0x04
LOWER_MASK = 0x08
LINEBREAK_MASK = 0x10
SPACE_MASK = 0x20
TITLE_MASK = 0x40
UPPER_MASK = 0x80

def maketables(trace=0):

    print "--- Reading", UNICODE_DATA % "", "..."

    version = ""
    unicode = UnicodeData(UNICODE_DATA % version,
                          COMPOSITION_EXCLUSIONS % version,
                          EASTASIAN_WIDTH % version)

    print len(filter(None, unicode.table)), "characters"

    for version in old_versions:
        print "--- Reading", UNICODE_DATA % ("-"+version), "..."
        old_unicode = UnicodeData(UNICODE_DATA % ("-"+version),
                                  COMPOSITION_EXCLUSIONS % ("-"+version),
                                  EASTASIAN_WIDTH % ("-"+version))
        print len(filter(None, old_unicode.table)), "characters"
        merge_old_version(version, unicode, old_unicode)

    makeunicodename(unicode, trace)
    makeunicodedata(unicode, trace)
    makeunicodetype(unicode, trace)

# --------------------------------------------------------------------
# unicode character properties

def makeunicodedata(unicode, trace):

    dummy = (0, 0, 0, 0, 0)
    table = [dummy]
    cache = {0: dummy}
    index = [0] * len(unicode.chars)

    FILE = "Modules/unicodedata_db.h"

    print "--- Preparing", FILE, "..."

    # 1) database properties

    for char in unicode.chars:
        record = unicode.table[char]
        if record:
            # extract database properties
            category = CATEGORY_NAMES.index(record[2])
            combining = int(record[3])
            bidirectional = BIDIRECTIONAL_NAMES.index(record[4])
            mirrored = record[9] == "Y"
            eastasianwidth = EASTASIANWIDTH_NAMES.index(record[15])
            item = (
                category, combining, bidirectional, mirrored, eastasianwidth
                )
            # add entry to index and item tables
            i = cache.get(item)
            if i is None:
                cache[item] = i = len(table)
                table.append(item)
            index[char] = i

    # 2) decomposition data

    decomp_data = [0]
    decomp_prefix = [""]
    decomp_index = [0] * len(unicode.chars)
    decomp_size = 0

    comp_pairs = []
    comp_first = [None] * len(unicode.chars)
    comp_last = [None] * len(unicode.chars)

    for char in unicode.chars:
        record = unicode.table[char]
        if record:
            if record[5]:
                decomp = record[5].split()
                if len(decomp) > 19:
                    raise Exception, "character %x has a decomposition too large for nfd_nfkd" % char
                # prefix
                if decomp[0][0] == "<":
                    prefix = decomp.pop(0)
                else:
                    prefix = ""
                try:
                    i = decomp_prefix.index(prefix)
                except ValueError:
                    i = len(decomp_prefix)
                    decomp_prefix.append(prefix)
                prefix = i
                assert prefix < 256
                # content
                decomp = [prefix + (len(decomp)<<8)] +\
                         map(lambda s: int(s, 16), decomp)
                # Collect NFC pairs
                if not prefix and len(decomp) == 3 and \
                   char not in unicode.exclusions and \
                   unicode.table[decomp[1]][3] == "0":
                    p, l, r = decomp
                    comp_first[l] = 1
                    comp_last[r] = 1
                    comp_pairs.append((l,r,char))
                try:
                    i = decomp_data.index(decomp)
                except ValueError:
                    i = len(decomp_data)
                    decomp_data.extend(decomp)
                    decomp_size = decomp_size + len(decomp) * 2
            else:
                i = 0
            decomp_index[char] = i

    f = l = 0
    comp_first_ranges = []
    comp_last_ranges = []
    prev_f = prev_l = None
    for i in unicode.chars:
        if comp_first[i] is not None:
            comp_first[i] = f
            f += 1
            if prev_f is None:
                prev_f = (i,i)
            elif prev_f[1]+1 == i:
                prev_f = prev_f[0],i
            else:
                comp_first_ranges.append(prev_f)
                prev_f = (i,i)
        if comp_last[i] is not None:
            comp_last[i] = l
            l += 1
            if prev_l is None:
                prev_l = (i,i)
            elif prev_l[1]+1 == i:
                prev_l = prev_l[0],i
            else:
                comp_last_ranges.append(prev_l)
                prev_l = (i,i)
    comp_first_ranges.append(prev_f)
    comp_last_ranges.append(prev_l)
    total_first = f
    total_last = l

    comp_data = [0]*(total_first*total_last)
    for f,l,char in comp_pairs:
        f = comp_first[f]
        l = comp_last[l]
        comp_data[f*total_last+l] = char

    print len(table), "unique properties"
    print len(decomp_prefix), "unique decomposition prefixes"
    print len(decomp_data), "unique decomposition entries:",
    print decomp_size, "bytes"
    print total_first, "first characters in NFC"
    print total_last, "last characters in NFC"
    print len(comp_pairs), "NFC pairs"

    print "--- Writing", FILE, "..."

    fp = open(FILE, "w")
    print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION)
    print >>fp
    print >>fp, '#define UNIDATA_VERSION "%s"' % UNIDATA_VERSION
    print >>fp, "/* a list of unique database records */"
    print >>fp, \
          "const _PyUnicode_DatabaseRecord _PyUnicode_Database_Records[] = {"
    for item in table:
        print >>fp, "    {%d, %d, %d, %d, %d}," % item
    print >>fp, "};"
    print >>fp

    print >>fp, "/* Reindexing of NFC first characters. */"
    print >>fp, "#define TOTAL_FIRST",total_first
    print >>fp, "#define TOTAL_LAST",total_last
    print >>fp, "struct reindex{int start;short count,index;};"
    print >>fp, "struct reindex nfc_first[] = {"
    for start,end in comp_first_ranges:
        print >>fp,"  { %d, %d, %d}," % (start,end-start,comp_first[start])
    print >>fp,"  {0,0,0}"
    print >>fp,"};\n"
    print >>fp, "struct reindex nfc_last[] = {"
    for start,end in comp_last_ranges:
        print >>fp,"  { %d, %d, %d}," % (start,end-start,comp_last[start])
    print >>fp,"  {0,0,0}"
    print >>fp,"};\n"

    # FIXME: <fl> the following tables could be made static, and
    # the support code moved into unicodedatabase.c

    print >>fp, "/* string literals */"
    print >>fp, "const char *_PyUnicode_CategoryNames[] = {"
    for name in CATEGORY_NAMES:
        print >>fp, "    \"%s\"," % name
    print >>fp, "    NULL"
    print >>fp, "};"

    print >>fp, "const char *_PyUnicode_BidirectionalNames[] = {"
    for name in BIDIRECTIONAL_NAMES:
        print >>fp, "    \"%s\"," % name
    print >>fp, "    NULL"
    print >>fp, "};"

    print >>fp, "const char *_PyUnicode_EastAsianWidthNames[] = {"
    for name in EASTASIANWIDTH_NAMES:
        print >>fp, "    \"%s\"," % name
    print >>fp, "    NULL"
    print >>fp, "};"

    print >>fp, "static const char *decomp_prefix[] = {"
    for name in decomp_prefix:
        print >>fp, "    \"%s\"," % name
    print >>fp, "    NULL"
    print >>fp, "};"

    # split record index table
    index1, index2, shift = splitbins(index, trace)

    print >>fp, "/* index tables for the database records */"
    print >>fp, "#define SHIFT", shift
    Array("index1", index1).dump(fp, trace)
    Array("index2", index2).dump(fp, trace)

    # split decomposition index table
    index1, index2, shift = splitbins(decomp_index, trace)

    print >>fp, "/* decomposition data */"
    Array("decomp_data", decomp_data).dump(fp, trace)

    print >>fp, "/* index tables for the decomposition data */"
    print >>fp, "#define DECOMP_SHIFT", shift
    Array("decomp_index1", index1).dump(fp, trace)
    Array("decomp_index2", index2).dump(fp, trace)

    index, index2, shift = splitbins(comp_data, trace)
    print >>fp, "/* NFC pairs */"
    print >>fp, "#define COMP_SHIFT", shift
    Array("comp_index", index).dump(fp, trace)
    Array("comp_data", index2).dump(fp, trace)

    # Generate delta tables for old versions
    for version, table, normalization in unicode.changed:
        cversion = version.replace(".","_")
        records = [table[0]]
        cache = {table[0]:0}
        index = [0] * len(table)
        for i, record in enumerate(table):
            try:
                index[i] = cache[record]
            except KeyError:
                index[i] = cache[record] = len(records)
                records.append(record)
        index1, index2, shift = splitbins(index, trace)
        print >>fp, "static const change_record change_records_%s[] = {" % cversion
        for record in records:
            print >>fp, "\t{ %s }," % ", ".join(map(str,record))
        print >>fp, "};"
        Array("changes_%s_index" % cversion, index1).dump(fp, trace)
        Array("changes_%s_data" % cversion, index2).dump(fp, trace)
        print >>fp, "static const change_record* get_change_%s(Py_UCS4 n)" % cversion
        print >>fp, "{"
        print >>fp, "\tint index;"
        print >>fp, "\tif (n >= 0x110000) index = 0;"
        print >>fp, "\telse {"
        print >>fp, "\t\tindex = changes_%s_index[n>>%d];" % (cversion, shift)
        print >>fp, "\t\tindex = changes_%s_data[(index<<%d)+(n & %d)];" % \
              (cversion, shift, ((1<<shift)-1))
        print >>fp, "\t}"
        print >>fp, "\treturn change_records_%s+index;" % cversion
        print >>fp, "}\n"
        print >>fp, "static Py_UCS4 normalization_%s(Py_UCS4 n)" % cversion
        print >>fp, "{"
        print >>fp, "\tswitch(n) {"
        for k, v in normalization:
            print >>fp, "\tcase %s: return 0x%s;" % (hex(k), v)
        print >>fp, "\tdefault: return 0;"
        print >>fp, "\t}\n}\n"

    fp.close()

# --------------------------------------------------------------------
# unicode character type tables

def makeunicodetype(unicode, trace):

    FILE = "Objects/unicodetype_db.h"

    print "--- Preparing", FILE, "..."

    # extract unicode types
    dummy = (0, 0, 0, 0, 0, 0)
    table = [dummy]
    cache = {0: dummy}
    index = [0] * len(unicode.chars)

    for char in unicode.chars:
        record = unicode.table[char]
        if record:
            # extract database properties
            category = record[2]
            bidirectional = record[4]
            flags = 0
            if category in ["Lm", "Lt", "Lu", "Ll", "Lo"]:
                flags |= ALPHA_MASK
            if category == "Ll":
                flags |= LOWER_MASK
            if category == "Zl" or bidirectional == "B":
                flags |= LINEBREAK_MASK
            if category == "Zs" or bidirectional in ("WS", "B", "S"):
                flags |= SPACE_MASK
            if category == "Lt":
                flags |= TITLE_MASK
            if category == "Lu":
                flags |= UPPER_MASK
            # use delta predictor for upper/lower/title
            if record[12]:
                upper = int(record[12], 16) - char
                assert -32768 <= upper <= 32767
                upper = upper & 0xffff
            else:
                upper = 0
            if record[13]:
                lower = int(record[13], 16) - char
                assert -32768 <= lower <= 32767
                lower = lower & 0xffff
            else:
                lower = 0
            if record[14]:
                title = int(record[14], 16) - char
                assert -32768 <= lower <= 32767
                title = title & 0xffff
            else:
                title = 0
            # decimal digit, integer digit
            decimal = 0
            if record[6]:
                flags |= DECIMAL_MASK
                decimal = int(record[6])
            digit = 0
            if record[7]:
                flags |= DIGIT_MASK
                digit = int(record[7])
            item = (
                upper, lower, title, decimal, digit, flags
                )
            # add entry to index and item tables
            i = cache.get(item)
            if i is None:
                cache[item] = i = len(table)
                table.append(item)
            index[char] = i

    print len(table), "unique character type entries"

    print "--- Writing", FILE, "..."

    fp = open(FILE, "w")
    print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION)
    print >>fp
    print >>fp, "/* a list of unique character type descriptors */"
    print >>fp, "const _PyUnicode_TypeRecord _PyUnicode_TypeRecords[] = {"
    for item in table:
        print >>fp, "    {%d, %d, %d, %d, %d, %d}," % item
    print >>fp, "};"
    print >>fp

    # split decomposition index table
    index1, index2, shift = splitbins(index, trace)

    print >>fp, "/* type indexes */"
    print >>fp, "#define SHIFT", shift
    Array("index1", index1).dump(fp, trace)
    Array("index2", index2).dump(fp, trace)

    fp.close()

# --------------------------------------------------------------------
# unicode name database

def makeunicodename(unicode, trace):

    FILE = "Modules/unicodename_db.h"

    print "--- Preparing", FILE, "..."

    # collect names
    names = [None] * len(unicode.chars)

    for char in unicode.chars:
        record = unicode.table[char]
        if record:
            name = record[1].strip()
            if name and name[0] != "<":
                names[char] = name + chr(0)

    print len(filter(lambda n: n is not None, names)), "distinct names"

    # collect unique words from names (note that we differ between
    # words inside a sentence, and words ending a sentence.  the
    # latter includes the trailing null byte.

    words = {}
    n = b = 0
    for char in unicode.chars:
        name = names[char]
        if name:
            w = name.split()
            b = b + len(name)
            n = n + len(w)
            for w in w:
                l = words.get(w)
                if l:
                    l.append(None)
                else:
                    words[w] = [len(words)]

    print n, "words in text;", b, "bytes"

    wordlist = words.items()

    # sort on falling frequency, then by name
    def cmpwords((aword, alist),(bword, blist)):
        r = -cmp(len(alist),len(blist))
        if r:
            return r
        return cmp(aword, bword)
    wordlist.sort(cmpwords)

    # figure out how many phrasebook escapes we need
    escapes = 0
    while escapes * 256 < len(wordlist):
        escapes = escapes + 1
    print escapes, "escapes"

    short = 256 - escapes

    assert short > 0

    print short, "short indexes in lexicon"

    # statistics
    n = 0
    for i in range(short):
        n = n + len(wordlist[i][1])
    print n, "short indexes in phrasebook"

    # pick the most commonly used words, and sort the rest on falling
    # length (to maximize overlap)

    wordlist, wordtail = wordlist[:short], wordlist[short:]
    wordtail.sort(lambda a, b: len(b[0])-len(a[0]))
    wordlist.extend(wordtail)

    # generate lexicon from words

    lexicon_offset = [0]
    lexicon = ""
    words = {}

    # build a lexicon string
    offset = 0
    for w, x in wordlist:
        # encoding: bit 7 indicates last character in word (chr(128)
        # indicates the last character in an entire string)
        ww = w[:-1] + chr(ord(w[-1])+128)
        # reuse string tails, when possible
        o = lexicon.find(ww)
        if o < 0:
            o = offset
            lexicon = lexicon + ww
            offset = offset + len(w)
        words[w] = len(lexicon_offset)
        lexicon_offset.append(o)

    lexicon = map(ord, lexicon)

    # generate phrasebook from names and lexicon
    phrasebook = [0]
    phrasebook_offset = [0] * len(unicode.chars)
    for char in unicode.chars:
        name = names[char]
        if name:
            w = name.split()
            phrasebook_offset[char] = len(phrasebook)
            for w in w:
                i = words[w]
                if i < short:
                    phrasebook.append(i)
                else:
                    # store as two bytes
                    phrasebook.append((i>>8) + short)
                    phrasebook.append(i&255)

    assert getsize(phrasebook) == 1

    #
    # unicode name hash table

    # extract names
    data = []
    for char in unicode.chars:
        record = unicode.table[char]
        if record:
            name = record[1].strip()
            if name and name[0] != "<":
                data.append((name, char))

    # the magic number 47 was chosen to minimize the number of
    # collisions on the current data set.  if you like, change it
    # and see what happens...

    codehash = Hash("code", data, 47)

    print "--- Writing", FILE, "..."

    fp = open(FILE, "w")
    print >>fp, "/* this file was generated by %s %s */" % (SCRIPT, VERSION)
    print >>fp
    print >>fp, "#define NAME_MAXLEN", 256
    print >>fp
    print >>fp, "/* lexicon */"
    Array("lexicon", lexicon).dump(fp, trace)
    Array("lexicon_offset", lexicon_offset).dump(fp, trace)

    # split decomposition index table
    offset1, offset2, shift = splitbins(phrasebook_offset, trace)

    print >>fp, "/* code->name phrasebook */"
    print >>fp, "#define phrasebook_shift", shift
    print >>fp, "#define phrasebook_short", short

    Array("phrasebook", phrasebook).dump(fp, trace)
    Array("phrasebook_offset1", offset1).dump(fp, trace)
    Array("phrasebook_offset2", offset2).dump(fp, trace)

    print >>fp, "/* name->code dictionary */"
    codehash.dump(fp, trace)

    fp.close()

def merge_old_version(version, new, old):
    # Changes to exclusion file not implemented yet
    if old.exclusions != new.exclusions:
        raise NotImplementedError, "exclusions differ"

    # In these change records, 0xFF means "no change"
    bidir_changes = [0xFF]*0x110000
    category_changes = [0xFF]*0x110000
    decimal_changes = [0xFF]*0x110000
    # In numeric data, 0 means "no change",
    # -1 means "did not have a numeric value
    numeric_changes = [0] * 0x110000
    # normalization_changes is a list of key-value pairs
    normalization_changes = []
    for i in range(0x110000):
        if new.table[i] is None:
            # Characters unassigned in the new version ought to
            # be unassigned in the old one
            assert old.table[i] is None
            continue
        # check characters unassigned in the old version
        if old.table[i] is None:
            # category 0 is "unassigned"
            category_changes[i] = 0
            continue
        # check characters that differ
        if old.table[i] != new.table[i]:
            for k in range(len(old.table[i])):
                if old.table[i][k] != new.table[i][k]:
                    value = old.table[i][k]
                    if k == 2:
                        #print "CATEGORY",hex(i), old.table[i][k], new.table[i][k]
                        category_changes[i] = CATEGORY_NAMES.index(value)
                    elif k == 4:
                        #print "BIDIR",hex(i), old.table[i][k], new.table[i][k]
                        bidir_changes[i] = BIDIRECTIONAL_NAMES.index(value)
                    elif k == 5:
                        #print "DECOMP",hex(i), old.table[i][k], new.table[i][k]
                        # We assume that all normalization changes are in 1:1 mappings
                        assert " " not in value
                        normalization_changes.append((i, value))
                    elif k == 6:
                        #print "DECIMAL",hex(i), old.table[i][k], new.table[i][k]
                        # we only support changes where the old value is a single digit
                        assert value in "0123456789"
                        decimal_changes[i] = int(value)
                    elif k == 8:
                        # print "NUMERIC",hex(i), `old.table[i][k]`, new.table[i][k]
                        # Since 0 encodes "no change", the old value is better not 0
                        assert value != "0" and value != "-1"
                        if not value:
                            numeric_changes[i] = -1
                        else:
                            assert re.match("^[0-9]+$", value)
                            numeric_changes[i] = int(value)
                    elif k == 11:
                        # change to ISO comment, ignore
                        pass
                    elif k == 12:
                        # change to simple uppercase mapping; ignore
                        pass
                    elif k == 13:
                        # change to simple lowercase mapping; ignore
                        pass
                    elif k == 14:
                        # change to simple titlecase mapping; ignore
                        pass
                    else:
                        class Difference(Exception):pass
                        raise Difference, (hex(i), k, old.table[i], new.table[i])
    new.changed.append((version, zip(bidir_changes, category_changes,
                                     decimal_changes, numeric_changes),
                        normalization_changes))

# --------------------------------------------------------------------
# the following support code is taken from the unidb utilities
# Copyright (c) 1999-2000 by Secret Labs AB

# load a unicode-data file from disk

import sys

class UnicodeData:

    def __init__(self, filename, exclusions, eastasianwidth, expand=1):
        self.changed = []
        file = open(filename)
        table = [None] * 0x110000
        while 1:
            s = file.readline()
            if not s:
                break
            s = s.strip().split(";")
            char = int(s[0], 16)
            table[char] = s

        # expand first-last ranges
        if expand:
            field = None
            for i in range(0, 0x110000):
                s = table[i]
                if s:
                    if s[1][-6:] == "First>":
                        s[1] = ""
                        field = s
                    elif s[1][-5:] == "Last>":
                        s[1] = ""
                        field = None
                elif field:
                    f2 = field[:]
                    f2[0] = "%X" % i
                    table[i] = f2

        # public attributes
        self.filename = filename
        self.table = table
        self.chars = range(0x110000) # unicode 3.2

        file = open(exclusions)
        self.exclusions = {}
        for s in file:
            s = s.strip()
            if not s:
                continue
            if s[0] == '#':
                continue
            char = int(s.split()[0],16)
            self.exclusions[char] = 1

        widths = [None] * 0x110000
        for s in open(eastasianwidth):
            s = s.strip()
            if not s:
                continue
            if s[0] == '#':
                continue
            s = s.split()[0].split(';')
            if '..' in s[0]:
                first, last = [int(c, 16) for c in s[0].split('..')]
                chars = range(first, last+1)
            else:
                chars = [int(s[0], 16)]
            for char in chars:
                widths[char] = s[1]
        for i in range(0, 0x110000):
            if table[i] is not None:
                table[i].append(widths[i])

    def uselatin1(self):
        # restrict character range to ISO Latin 1
        self.chars = range(256)

# hash table tools

# this is a straight-forward reimplementation of Python's built-in
# dictionary type, using a static data structure, and a custom string
# hash algorithm.

def myhash(s, magic):
    h = 0
    for c in map(ord, s.upper()):
        h = (h * magic) + c
        ix = h & 0xff000000L
        if ix:
            h = (h ^ ((ix>>24) & 0xff)) & 0x00ffffff
    return h

SIZES = [
    (4,3), (8,3), (16,3), (32,5), (64,3), (128,3), (256,29), (512,17),
    (1024,9), (2048,5), (4096,83), (8192,27), (16384,43), (32768,3),
    (65536,45), (131072,9), (262144,39), (524288,39), (1048576,9),
    (2097152,5), (4194304,3), (8388608,33), (16777216,27)
]

class Hash:
    def __init__(self, name, data, magic):
        # turn a (key, value) list into a static hash table structure

        # determine table size
        for size, poly in SIZES:
            if size > len(data):
                poly = size + poly
                break
        else:
            raise AssertionError, "ran out of polynominals"

        print size, "slots in hash table"

        table = [None] * size

        mask = size-1

        n = 0

        hash = myhash

        # initialize hash table
        for key, value in data:
            h = hash(key, magic)
            i = (~h) & mask
            v = table[i]
            if v is None:
                table[i] = value
                continue
            incr = (h ^ (h >> 3)) & mask;
            if not incr:
                incr = mask
            while 1:
                n = n + 1
                i = (i + incr) & mask
                v = table[i]
                if v is None:
                    table[i] = value
                    break
                incr = incr << 1
                if incr > mask:
                    incr = incr ^ poly

        print n, "collisions"
        self.collisions = n

        for i in range(len(table)):
            if table[i] is None:
                table[i] = 0

        self.data = Array(name + "_hash", table)
        self.magic = magic
        self.name = name
        self.size = size
        self.poly = poly

    def dump(self, file, trace):
        # write data to file, as a C array
        self.data.dump(file, trace)
        file.write("#define %s_magic %d\n" % (self.name, self.magic))
        file.write("#define %s_size %d\n" % (self.name, self.size))
        file.write("#define %s_poly %d\n" % (self.name, self.poly))

# stuff to deal with arrays of unsigned integers

class Array:

    def __init__(self, name, data):
        self.name = name
        self.data = data

    def dump(self, file, trace=0):
        # write data to file, as a C array
        size = getsize(self.data)
        if trace:
            print >>sys.stderr, self.name+":", size*len(self.data), "bytes"
        file.write("static ")
        if size == 1:
            file.write("unsigned char")
        elif size == 2:
            file.write("unsigned short")
        else:
            file.write("unsigned int")
        file.write(" " + self.name + "[] = {\n")
        if self.data:
            s = "    "
            for item in self.data:
                i = str(item) + ", "
                if len(s) + len(i) > 78:
                    file.write(s + "\n")
                    s = "    " + i
                else:
                    s = s + i
            if s.strip():
                file.write(s + "\n")
        file.write("};\n\n")

def getsize(data):
    # return smallest possible integer size for the given array
    maxdata = max(data)
    if maxdata < 256:
        return 1
    elif maxdata < 65536:
        return 2
    else:
        return 4

def splitbins(t, trace=0):
    """t, trace=0 -> (t1, t2, shift).  Split a table to save space.

    t is a sequence of ints.  This function can be useful to save space if
    many of the ints are the same.  t1 and t2 are lists of ints, and shift
    is an int, chosen to minimize the combined size of t1 and t2 (in C
    code), and where for each i in range(len(t)),
        t[i] == t2[(t1[i >> shift] << shift) + (i & mask)]
    where mask is a bitmask isolating the last "shift" bits.

    If optional arg trace is non-zero (default zero), progress info
    is printed to sys.stderr.  The higher the value, the more info
    you'll get.
    """

    import sys
    if trace:
        def dump(t1, t2, shift, bytes):
            print >>sys.stderr, "%d+%d bins at shift %d; %d bytes" % (
                len(t1), len(t2), shift, bytes)
        print >>sys.stderr, "Size of original table:", len(t)*getsize(t), \
                            "bytes"
    n = len(t)-1    # last valid index
    maxshift = 0    # the most we can shift n and still have something left
    if n > 0:
        while n >> 1:
            n >>= 1
            maxshift += 1
    del n
    bytes = sys.maxint  # smallest total size so far
    t = tuple(t)    # so slices can be dict keys
    for shift in range(maxshift + 1):
        t1 = []
        t2 = []
        size = 2**shift
        bincache = {}
        for i in range(0, len(t), size):
            bin = t[i:i+size]
            index = bincache.get(bin)
            if index is None:
                index = len(t2)
                bincache[bin] = index
                t2.extend(bin)
            t1.append(index >> shift)
        # determine memory size
        b = len(t1)*getsize(t1) + len(t2)*getsize(t2)
        if trace > 1:
            dump(t1, t2, shift, b)
        if b < bytes:
            best = t1, t2, shift
            bytes = b
    t1, t2, shift = best
    if trace:
        print >>sys.stderr, "Best:",
        dump(t1, t2, shift, bytes)
    if __debug__:
        # exhaustively verify that the decomposition is correct
        mask = ~((~0) << shift) # i.e., low-bit mask of shift bits
        for i in xrange(len(t)):
            assert t[i] == t2[(t1[i >> shift] << shift) + (i & mask)]
    return best

if __name__ == "__main__":
    maketables(1)


text:
public class LinkedList3<T>
{
    private class Node<T>
    {
        private T data;
        private Node<T> link;

        public Node( )
        {
             data = null;
             link = null;
        }

        public Node(T newData, Node<T> linkValue)
        {
            data = newData;
            link = linkValue;
        }
     }//End of Node<T> inner class

    private Node<T> head;

    public LinkedList3( )
    {
        head = null;
    }

    /**
     Adds a node at the start of the list with the specified data.
     The added node will be the first node in the list.
    */
    public void addToStart(T itemData)
    {
        head = new Node<T>(itemData, head);
    }

    /**
     Removes the head node and returns true if the list contains at least
     one node. Returns false if the list is empty.
    */
    public boolean deleteHeadNode( )
    {
        if (head != null)
        {
            head = head.link;
            return true;
        }
        else
            return false;
    }

    /**
     Returns the number of nodes in the list.
    */
    public int size( )
    {
        int count = 0;
        Node<T> position = head;
        while (position != null)
        {
            count++;
            position = position.link;
        }
        return count;
    }

    public boolean contains(T item)
    {
        return (find(item) != null);
    }

    /**
     Finds the first node containing the target item, and returns a
     reference to that node. If target is not in the list, null is returned.
    */
    private Node<T> find(T target)
    {
        Node<T> position = head;
        T itemAtPosition;
        while (position != null)
        {
            itemAtPosition = position.data;
            if (itemAtPosition.equals(target))
                return position;
            position = position.link;
        }
        return null; //target was not found
    }

    /**
     Finds the first node containing the target and returns a reference
      to the data in that node. If target is not in the list, null is returned.
    */
    public T findData(T target)
    {
        return find(target).data;
    }

    public void outputList( )
    {
        Node<T> position = head;
        while (position != null)
        {
            System.out.println(position.data);
            position = position.link;
        }
    }

    public boolean isEmpty( )
    {
        return (head == null);
    }

    public void clear( )
    {
        head = null;
    }

   /*
    For two lists to be equal they must contain the same data items in
    the same order. The equals method of T is used to compare data items.
   */
   public boolean equals(Object otherObject)
    {
        if (otherObject == null)
            return false;
        else if (getClass( ) != otherObject.getClass( ))
            return false;
        else
        {
            LinkedList3<T> otherList = (LinkedList3<T>)otherObject;
            if (size( ) != otherList.size( ))
                return false;
            Node<T> position = head;
            Node<T> otherPosition = otherList.head;
            while (position != null)
            {
                if (!(position.data.equals(otherPosition.data)))
                    return false;
                position = position.link;
                otherPosition = otherPosition.link;
            }
            return true; //no mismatch was not found
        }
    }

}

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UnityThreading
{
    public static class EnumerableExtension
    {
        /// <summary>
        /// Performs the given Action parallel for each element in the enumerable.
        /// </summary>
        /// <param name="action">The action to perform for each element.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task> ParallelForEach<T>(this IEnumerable<T> that, Action<T> action)
        {
            return that.ParallelForEach(action, null);
        }

        /// <summary>
        /// Performs the given Action parallel for each element in the enumerable.
        /// </summary>
        /// <param name="action">The action to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task> ParallelForEach<T>(this IEnumerable<T> that, Action<T> action, TaskDistributor target)
        {
            return (IEnumerable<Task>)that.ParallelForEach(element => { action(element); return default(UnityThreading.Task.Unit); }, target);
        }

        /// <summary>
        /// Performs the given Func parallel for each element in the enumerable.
        /// </summary>
        /// <param name="action">The Func to perform for each element.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task<TResult>> ParallelForEach<TResult, T>(this IEnumerable<T> that, Func<T, TResult> action)
        {
            return that.ParallelForEach(action);
        }

        /// <summary>
        /// Performs the given Func parallel for each element in the enumerable.
        /// </summary>
        /// <param name="action">The Func to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task<TResult>> ParallelForEach<TResult, T>(this IEnumerable<T> that, Func<T, TResult> action, TaskDistributor target)
        {
            var result = new List<Task<TResult>>();
            foreach (var element in that)
            {
                var tmp = element;
                var task = Task.Create(() => action(tmp)).Run(target);
                result.Add(task);
            }
            return result;
        }

        /// <summary>
        /// Performs the given Action sequential for each element in the enumerable.
        /// </summary>
        /// <param name="action">The Action to perform for each element.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task> SequentialForEach<T>(this IEnumerable<T> that, Action<T> action)
        {
            return that.SequentialForEach(action, null);
        }

        /// <summary>
        /// Performs the given Action sequential for each element in the enumerable.
        /// </summary>
        /// <param name="action">The Action to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task> SequentialForEach<T>(this IEnumerable<T> that, Action<T> action, TaskDistributor target)
        {
            return (IEnumerable<Task>)that.SequentialForEach(element => { action(element); return default(UnityThreading.Task.Unit); }, target);
        }

        /// <summary>
        /// Performs the given Func sequential for each element in the enumerable.
        /// </summary>
        /// <param name="action">The Func to perform for each element.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task<TResult>> SequentialForEach<TResult, T>(this IEnumerable<T> that, Func<T, TResult> action)
        {
            return that.SequentialForEach(action);
        }

        /// <summary>
        /// Performs the given Func sequential for each element in the enumerable.
        /// </summary>
        /// <param name="action">The Func to perform for each element.</param>
        /// <param name="target">The TaskDistributor instance on which the operation should perform.</param>
        /// <returns>IEnumerable of created tasks.</returns>
        public static IEnumerable<Task<TResult>> SequentialForEach<TResult, T>(this IEnumerable<T> that, Func<T, TResult> action, TaskDistributor target)
        {
            var result = new List<Task<TResult>>();
            Task lastTask = null;
            foreach (var element in that)
            {
                var tmp = element;
                var task = Task.Create(() => action(tmp));
                if (lastTask == null)
                    task.Run(target);
                else
                    lastTask.WhenEnded(() => task.Run(target));
                lastTask = task;
                result.Add(task);
            }
            return result;
        }
    }
}


text:
lea-to-sqf
==========

Converter of [Loadout Editor for Arma 3](http://www.armaholic.com/page.php?id=23852) profiles to SQF code.
Always select "Use default uniform" because of http://feedback.arma...ew.php?id=15298
Copy to LEA installation folder (C:\Program Files (x86)\LEA) and run as administrator. Check C:\Program Files (x86)\LEA\profiles\converted for new directories with results.

Конвертер профайлов [Loadout Editor for Arma 3](http://www.armaholic.com/page.php?id=23852) в SQF код. Поддерживает платформу Зеалота и BG-3. Также генерирует SQF для теста в редакторе.
Всегда отмечайте галку "Use default uniform" пока не исправят баг http://feedback.arma...ew.php?id=15298
Скопируйте в папку с LEA (C:\Program Files (x86)\LEA) и запустите от имени администратора. Проверьте C:\Program Files (x86)\LEA\profiles\converted на наличие новых папок с результатом.


text:
package org.wso2.carbon.apimgt.rest.api.store.v1;

import org.wso2.carbon.apimgt.rest.api.store.v1.dto.ErrorDTO;
import org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyDTO;
import org.wso2.carbon.apimgt.rest.api.store.v1.dto.ThrottlingPolicyListDTO;
import org.wso2.carbon.apimgt.rest.api.store.v1.ThrottlingPoliciesApiService;
import org.wso2.carbon.apimgt.rest.api.store.v1.impl.ThrottlingPoliciesApiServiceImpl;
import org.wso2.carbon.apimgt.api.APIManagementException;

import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.inject.Inject;

import io.swagger.annotations.*;
import java.io.InputStream;

import org.apache.cxf.jaxrs.ext.MessageContext;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;

import java.util.Map;
import java.util.List;
import javax.validation.constraints.*;
@Path("/throttling-policies")

@Api(description = "the throttling-policies API")

public class ThrottlingPoliciesApi  {

  @Context MessageContext securityContext;

ThrottlingPoliciesApiService delegate = new ThrottlingPoliciesApiServiceImpl();

    @GET
    @Path("/{policyLevel}")

    @Produces({ "application/json" })
    @ApiOperation(value = "Get All Available Throttling Policies", notes = "Get available Throttling Policies ", response = ThrottlingPolicyListDTO.class, authorizations = {
        @Authorization(value = "OAuth2Security", scopes = {

        })
    }, tags={ "Throttling Policies",  })
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK. List of throttling policies returned. ", response = ThrottlingPolicyListDTO.class),
        @ApiResponse(code = 304, message = "Not Modified. Empty body because the client has already the latest version of the requested resource. ", response = Void.class),
        @ApiResponse(code = 406, message = "Not Acceptable. The requested media type is not supported.", response = ErrorDTO.class) })
    public Response throttlingPoliciesPolicyLevelGet(@ApiParam(value = "List Application or Subscription type thro. ",required=true, allowableValues="application, subscription") @PathParam("policyLevel") String policyLevel,  @ApiParam(value = "Maximum size of resource array to return. ", defaultValue="25") @DefaultValue("25") @QueryParam("limit") Integer limit,  @ApiParam(value = "Starting point within the complete list of items qualified. ", defaultValue="0") @DefaultValue("0") @QueryParam("offset") Integer offset,  @ApiParam(value = "Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resourec. " )@HeaderParam("If-None-Match") String ifNoneMatch,  @ApiParam(value = "For cross-tenant invocations, this is used to specify the tenant domain, where the resource need to be   retrieved from. " )@HeaderParam("X-WSO2-Tenant") String xWSO2Tenant) throws APIManagementException{
        return delegate.throttlingPoliciesPolicyLevelGet(policyLevel, limit, offset, ifNoneMatch, xWSO2Tenant, securityContext);
    }

    @GET
    @Path("/{policyLevel}/{policyId}")

    @Produces({ "application/json" })
    @ApiOperation(value = "Get Details of a Throttling Policy ", notes = "This operation can be used to retrieve details of a single throttling policy by specifying the policy level and policy name.  `X-WSO2-Tenant` header can be used to retrive throttling policy that belongs to a different tenant domain. If not specified super tenant will be used. If Authorization header is present in the request, the user's tenant associated with the access token will be used. ", response = ThrottlingPolicyDTO.class, authorizations = {
        @Authorization(value = "OAuth2Security", scopes = {

        })
    }, tags={ "Throttling Policies" })
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK. Throttling Policy returned ", response = ThrottlingPolicyDTO.class),
        @ApiResponse(code = 304, message = "Not Modified. Empty body because the client has already the latest version of the requested resource. ", response = Void.class),
        @ApiResponse(code = 404, message = "Not Found. The specified resource does not exist.", response = ErrorDTO.class),
        @ApiResponse(code = 406, message = "Not Acceptable. The requested media type is not supported.", response = ErrorDTO.class) })
    public Response throttlingPoliciesPolicyLevelPolicyIdGet(@ApiParam(value = "The name of the policy ",required=true) @PathParam("policyId") String policyId, @ApiParam(value = "List Application or Subscription type thro. ",required=true, allowableValues="application, subscription") @PathParam("policyLevel") String policyLevel,  @ApiParam(value = "For cross-tenant invocations, this is used to specify the tenant domain, where the resource need to be   retrieved from. " )@HeaderParam("X-WSO2-Tenant") String xWSO2Tenant,  @ApiParam(value = "Validator for conditional requests; based on the ETag of the formerly retrieved variant of the resourec. " )@HeaderParam("If-None-Match") String ifNoneMatch) throws APIManagementException{
        return delegate.throttlingPoliciesPolicyLevelPolicyIdGet(policyId, policyLevel, xWSO2Tenant, ifNoneMatch, securityContext);
    }
}


text:
<?php

namespace Bolt\Translation;

use Bolt\Application;
use Bolt\Configuration\ResourceManager;
use Symfony\Component\Translation\Exception\InvalidResourceException;

/**
 * Handles translation.
 */
class Translator
{
    /**
     * Encode array values as html special chars.
     *
     * @param array  $params    Parameter to encode
     * @param string $removeKey If not empty the key is removed from result
     *
     * @return array
     */
    private static function htmlencodeParams(array $params, $removeKey = '')
    {
        if ($removeKey) {
            unset($params[$removeKey]);
        }

        return array_map(
            function ($val) {
                return htmlspecialchars($val, ENT_QUOTES);
            },
            $params
        );
    }

    /**
     * Low level translation.
     *
     * @param string $key
     * @param array  $params
     * @param string $domain
     * @param mixed  $locale
     * @param mixed  $default
     *
     * @return string
     */
    private static function trans($key, array $params = [], $domain = 'messages', $locale = null, $default = null)
    {
        $app = ResourceManager::getApp();

        // Handle default parameter
        if (isset($params['DEFAULT'])) {
            if ($default === null) {
                $default = $params['DEFAULT'];
            }
            unset($params['DEFAULT']);
        }

        // Handle number parameter
        if (isset($params['NUMBER'])) {
            $number = $params['NUMBER'];
            unset($params['NUMBER']);
        } else {
            $number = null;
        }

        // Translate
        try {
            if ($number === null) {
                $trans = $app['translator']->trans($key, $params, $domain, $locale);
            } else {
                $trans = $app['translator']->transChoice($key, $number, $params, $domain, $locale);
            }

            return ($trans === $key && $default !== null) ? $default : $trans;
        } catch (InvalidResourceException $e) {
            if (!isset($app['translationyamlerror']) && $app['request']->isXmlHttpRequest() === false) {
                $app['logger.flash']->warning('Error: You should fix this now, before continuing!
' . $e->getMessage());
                $app['translationyamlerror'] = true;
            }

            return strtr($key, $params);
        }
    }

    /**
     * Returns translated contenttype name with fallback to name/slug from 'contenttypes.yml'.
     *
     * @param string $contenttype The contentype
     * @param bool   $singular    Singular or plural requested?
     * @param string $locale      Translate to this locale
     *
     * @return string
     */
    private static function transContenttypeName($contenttype, $singular, $locale)
    {
        $key = 'contenttypes.' . $contenttype . '.name.' . ($singular ? 'singular' : 'plural');

        $name = self::trans($key, [], 'contenttypes', $locale);
        if ($name === $key) {
            $app = ResourceManager::getApp();

            $name = $app['config']->get('contenttypes/' . $contenttype . ($singular ? '/singular_name' : '/name'));
            if (empty($name)) {
                $name = ucfirst(
                    $app['config']->get(
                        'contenttypes/' . $contenttype . ($singular ? '/singular_slug' : '/slug'),
                        $contenttype
                    )
                );
            }
            // Escape names coming from 'contenttypes.yml'
            $name = htmlspecialchars($name, ENT_QUOTES);
        }

        return $name;
    }

    /**
     * Translates contentype specific messages and falls back to building generic message or fallback locale.
     *
     * @param string  $genericKey
     * @param array   $params
     * @param string  $id
     * @param boolean $singular
     * @param mixed   $locale
     *
     * @return boolean
     */
    private static function transContenttype($genericKey, array $params, $id, $singular, $locale)
    {
        $contenttype = $params[$id];
        $encParams = self::htmlencodeParams($params, $id);
        $key = 'contenttypes.' . $contenttype . '.text.' . substr($genericKey, 21);

        // Try to get a real translation from contenttypes.xx_XX.yml
        $trans = self::trans($key, $encParams, 'contenttypes', $locale, false);
        $transFallback = self::trans($key, $encParams, 'contenttypes', Application::DEFAULT_LOCALE, false);

        // We don't want fallback translation here
        if ($trans === $transFallback) {
            $trans = false;
        }

        // No translation found, build string from generic translation pattern
        if ($trans === false) {
            // Get generic translation with name replaced
            $encParams[$id] = self::transContenttypeName($contenttype, $singular, $locale);
            $transGeneric = self::trans($genericKey, $encParams, 'messages', $locale, false);
        } else {
            $transGeneric = false;
        }

        // Return: translation => generic translation => fallback translation => key
        if ($trans !== false) {
            return $trans;
        } elseif ($transGeneric !== false) {
            return $transGeneric;
        } elseif ($transFallback !== false) {
            return $transFallback;
        } else {
            return $genericKey;
        }
    }

    /**
     * i18n made right, third attempt….
     *
     * Instead of calling directly $app['translator']->trans(), we check for the presence of a placeholder named
     * '%contenttype%'.
     *
     * If one is found, we replace it with the contenttype.name parameter, and try to get a translated string. If
     * there is not, we revert to the generic (%contenttype%) string, which must have a translation.
     *
     * Special parameter keys:
     * 'DEFAULT': the value is returns instead of the key of no translation is found
     * 'NUMBER': transCjoice is triggered with the value as countvalue
     *
     * @param mixed  $key    The messsage id. If an array is passed, an sanitized key is build
     * @param array  $params Parameter for string replacement and commands ('DEFAULT', 'NUMBER')
     * @param string $domain
     * @param mixed  $locale
     *
     * @return string
     */
    public static function /*@codingStandardsIgnoreStart*/__/*@codingStandardsIgnoreEnd*/($key, array $params = [], $domain = 'messages', $locale = null)
    {
        // If $key is an array, convert it to a sanizized string
        if (is_array($key)) {
            array_walk(
                $key,
                function (&$value) {
                    $value = preg_replace('/[^a-z-]/', '', strtolower($value));
                }
            );
            $key = join('.', $key);
        }

        // Handle contenttypes
        if (substr($key, 0, 13) == 'contenttypes.') {
            // Generic contenttypes
            if (substr($key, 13, 8) == 'generic.') {
                if (isset($params['%contenttype%'])) {
                    return self::transContenttype($key, $params, '%contenttype%', true, $locale);
                } elseif (isset($params['%contenttypes%'])) {
                    return self::transContenttype($key, $params, '%contenttypes%', false, $locale);
                }
            // Switch domain
            } elseif ($domain === 'messages') {
                $domain = 'contenttypes';
            }
        }

        return self::trans($key, self::htmlencodeParams($params), $domain, $locale);
    }
}


text:
<!-- Ride Issue -->

### Did you connect to an already running interpreter or start the interpreter from RIDE?
<!-- Connect to already running/Start an interpreter -->

### How do you reproduce the issue?
<!-- instructions to reproduce -->

### Paste the contents of Help → About (Shift+F1)
```
(Paste here)
```


text:
# uberfetch
A thin layer over [fetch](https://github.com/github/fetch) which makes JSON the default, and turns HTTP errors into Promise rejections.

```js
import uberfetch from 'uberfetch';
```

### get JSON
```js
uberfetch('/cats/10')
  .then(res => /* do stuff */);
```

which is equivalent to:

```js
function rejectOnRequestError(res) {
  if (res.ok) return res;
  return Promise.reject(new RequestError(res));
}

fetch('/cats/10', {
  credentials: 'same-origin',
  headers: {
    'accept': 'application/json'
  }
})
  .then(rejectOnRequestError)
  .then(res => /* do stuff */);
```

### post JSON
```js
let updatedCat = {id: 10, name: 'Keith'};

uberfetch.post('/cats/10', {body: updatedCat});
```

which is equivalent to:

```js
let updatedCat = {id: 10, name: 'Keith'};

fetch('/cats/10', {
  method: 'post',
  body: JSON.stringify(updatedCat),
  credentials: 'same-origin',
  headers: {
    'content-type': 'application/json'
    'accept': 'application/json'
  }
})
  .then(rejectOnRequestError);
```

### get HTML
```js
// get some html
uberfetch('/cats/10', {accept: 'html'})
  .then(res => /* do stuff */);
```

which is equivalent to:

```js
fetch('/cats/10', {
  credentials: 'same-origin',
  headers: {
    'accept': 'text/html'
  }
})
  .then(rejectOnRequestError)
  .then(res => /* do stuff */);
```

### catch typed errors

```js
let cat = {id: 10, name: 'Keith'};

uberfetch.post('/cats/10', {body: cat})
  .then(res => res.json())
  .then(body => FlashMessage.show(`${body.name} saved`))
  .catch(err => {
    if (err instanceof uberfetch.RequestError) {
      if (err.status == 422) {
        return err.response.json()
          .then(body =>
            AlertModal.show(`Validation failed: ${body.validationErrors}`)
          );
      }
    }
    return Promise.reject(err);
  });
```

Or with ES7 `async/await`

```js
async function() {
  let cat = {id: 10, name: 'Keith'};

  try {
    let response = await uberfetch.post('/cats/10', {body: cat})
    let body = await response.json();
    FlashMessage.show(`${body.name} saved`);
  } catch (err) {
    if (err instanceof uberfetch.RequestError) {
      if (err.status == 422) {
        let body = err.response.json()
        AlertModal.show(`Validation failed: ${body.validationErrors}`);
        return;
      }
    }
    return Promise.reject(err);
  }
}
```

## API

Use `uberfetch(url, opts)` exactly as you would `fetch(url, opts)`, with the
following additional opts which can be provided in the opts object:

- `accept: string` shorthand for setting an accept header, which takes
  either a mime type, or a convenient short name like `form`, `html`, `text` etc.
- `contentType: string` shorthand for setting an content-type header,
  which takes either a mime type, or a convenient short name like `form`,
  `html`, `text` etc.
- `body: any` works like the normal `fetch` body field, except that known
  content-types will be automatically serialized. When `body` is present, the
  default http method becomes POST.

In addition to the `uberfetch()` function, the following convenience helpers are
available:

- `uberfetch.get()` automatically sets `method: 'get'`
- `uberfetch.post()` automatically sets `method: 'post'`
- `uberfetch.put()` automatically sets `method: 'put'`
- `uberfetch.patch()` automatically sets `method: 'patch'`
- `uberfetch.delete()` automatically sets `method: 'delete'`


text:
<?xml version="1.0"?>
<Document>

	<Sentence>
		<value>Right after the surgery, you may have burning, itching, or a feeling that something is in the eye.</value>
		<pattern_crowdsource> Right after the surgery, you may have burning, [[itching|C0033774]], or a feeling that something is in the [[eye|C0015392]].		</pattern_crowdsource>
		<annotations>
			<annotation>
				<surface-form>Right</surface-form>
				<RDF-ID>C0205090</RDF-ID>
			</annotation>
			<annotation>
				<surface-form>surgery</surface-form>
				<RDF-ID>C0543467</RDF-ID>
			</annotation>
			<annotation>
				<surface-form>burning</surface-form>
				<RDF-ID>C0175627</RDF-ID>
			</annotation>
			<annotation>
				<surface-form>itching</surface-form>
				<RDF-ID>C0033774</RDF-ID>
			</annotation>
			<annotation>
				<surface-form>feeling</surface-form>
				<RDF-ID>C1527305</RDF-ID>
			</annotation>
			<annotation>
				<surface-form>eye</surface-form>
				<RDF-ID>C0015392</RDF-ID>
			</annotation>
		</annotations>
		<triples>
			<triple>C0015392 LOCATION_OF C0033774</triple>
		</triples>
	</Sentence>

</Document>


text:
package ibur.ticktimecounter.test;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.JFileChooser;

public class Rotater {
	public static void main(String[] args) {
		JFileChooser jfc = new JFileChooser(new File("/Users/Sean/Documents/tick-time-counter"));
		jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int val = jfc.showOpenDialog(null);
		if(val != JFileChooser.APPROVE_OPTION) {
			System.exit(1);
		}
		System.out.println(jfc.getSelectedFile().getAbsolutePath());
		List<BufferedImage> images = getImages(jfc.getSelectedFile());
		List<BufferedImage> rotated = new ArrayList<BufferedImage>(images.size());
		for(BufferedImage b : images) {
			rotated.add(rotateImage180(b));
		}
		File outFolder = new File(jfc.getSelectedFile().getAbsoluteFile() + "_rotated");
		if(!outFolder.exists()) {
			outFolder.mkdir();
		}
		for(int i = 0; i < rotated.size(); i++) {
			try{
				ImageIO.write(rotated.get(i), "png", new File(outFolder.getAbsolutePath() + "/tape_1_" + i + ".png"));
			}
			catch(IOException e) {
				e.printStackTrace();
			}
		}
	}

	private static List<BufferedImage> getImages(File d) {
		if(!d.isDirectory()) {
			throw new IllegalArgumentException("Argument must be directory");
		}
		List<BufferedImage> l = new ArrayList<BufferedImage>();
		for(File f : d.listFiles()) {
			if(f.isFile() && f.canRead()) {
				try{
					BufferedImage b = ImageIO.read(f);
					if(b != null) {
						System.out.println(f.getAbsolutePath() + " is an image");
						l.add(b);
					} else {
						System.out.println(f.getAbsolutePath() + " is not an image");
					}

				}
				catch(IOException e) {
					System.out.println(f.getAbsolutePath() + " is not an image");
				}
			}
		}
		return l;
	}

	private static BufferedImage rotateImage180(BufferedImage b) {
		BufferedImage n = new BufferedImage(b.getWidth(), b.getHeight(), BufferedImage.TYPE_INT_RGB);
		for(int x = 0; x < b.getWidth(); x++) {
			for(int y = 0; y < b.getHeight(); y++) {
				n.setRGB(b.getWidth() - x - 1, b.getHeight() - y - 1, b.getRGB(x, y));
			}
		}
		return n;
	}
}


text:
/* Tell glibc's <stdio.h> to provide a prototype for getline().
   This must come before <config.h> because <config.h> may include
   <features.h>, and once <features.h> has been included, it's too late.  */
#ifndef _GNU_SOURCE
# define _GNU_SOURCE 1
#endif

#define _GL_USE_STDLIB_ALLOC 1
#include <config.h>

/* Specification.  */
#include "relocatable.h"

#if ENABLE_RELOCATABLE

#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef NO_XMALLOC
# define xmalloc malloc
#else
# include "xalloc.h"
#endif

#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif

#ifdef __EMX__
# define INCL_DOS
# include <os2.h>

# define strcmp  stricmp
# define strncmp strnicmp
#endif

#if DEPENDS_ON_LIBCHARSET
# include <libcharset.h>
#endif
#if DEPENDS_ON_LIBICONV && HAVE_ICONV
# include <iconv.h>
#endif
#if DEPENDS_ON_LIBINTL && ENABLE_NLS
# include <libintl.h>
#endif

/* Faked cheap 'bool'.  */
#undef bool
#undef false
#undef true
#define bool int
#define false 0
#define true 1

/* Pathname support.
   ISSLASH(C)           tests whether C is a directory separator character.
   IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
 */
#if ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __EMX__ || defined __DJGPP__
  /* Native Windows, OS/2, DOS */
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
# define HAS_DEVICE(P) \
    ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
     && (P)[1] == ':')
# define IS_PATH_WITH_DIR(P) \
    (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
# define FILE_SYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
#else
  /* Unix */
# define ISSLASH(C) ((C) == '/')
# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
# define FILE_SYSTEM_PREFIX_LEN(P) 0
#endif

/* Whether to enable the more costly support for relocatable libraries.
   It allows libraries to be have been installed with a different original
   prefix than the program.  But it is quite costly, especially on Cygwin
   platforms, see below.  Therefore we enable it by default only on native
   Windows platforms.  */
#ifndef ENABLE_COSTLY_RELOCATABLE
# if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
#  define ENABLE_COSTLY_RELOCATABLE 1
# else
#  define ENABLE_COSTLY_RELOCATABLE 0
# endif
#endif

/* Original installation prefix.  */
static char *orig_prefix;
static size_t orig_prefix_len;
/* Current installation prefix.  */
static char *curr_prefix;
static size_t curr_prefix_len;
/* These prefixes do not end in a slash.  Anything that will be concatenated
   to them must start with a slash.  */

/* Sets the original and the current installation prefix of this module.
   Relocation simply replaces a pathname starting with the original prefix
   by the corresponding pathname with the current prefix instead.  Both
   prefixes should be directory names without trailing slash (i.e. use ""
   instead of "/").  */
static void
set_this_relocation_prefix (const char *orig_prefix_arg,
                            const char *curr_prefix_arg)
{
  if (orig_prefix_arg != NULL && curr_prefix_arg != NULL
      /* Optimization: if orig_prefix and curr_prefix are equal, the
         relocation is a nop.  */
      && strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
    {
      /* Duplicate the argument strings.  */
      char *memory;

      orig_prefix_len = strlen (orig_prefix_arg);
      curr_prefix_len = strlen (curr_prefix_arg);
      memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
#ifdef NO_XMALLOC
      if (memory != NULL)
#endif
        {
          memcpy (memory, orig_prefix_arg, orig_prefix_len + 1);
          orig_prefix = memory;
          memory += orig_prefix_len + 1;
          memcpy (memory, curr_prefix_arg, curr_prefix_len + 1);
          curr_prefix = memory;
          return;
        }
    }
  orig_prefix = NULL;
  curr_prefix = NULL;
  /* Don't worry about wasted memory here - this function is usually only
     called once.  */
}

/* Sets the original and the current installation prefix of the package.
   Relocation simply replaces a pathname starting with the original prefix
   by the corresponding pathname with the current prefix instead.  Both
   prefixes should be directory names without trailing slash (i.e. use ""
   instead of "/").  */
void
set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
{
  set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg);

  /* Now notify all dependent libraries.  */
#if DEPENDS_ON_LIBCHARSET
  libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
#if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109
  libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
#if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix
  libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
}

#if !defined IN_LIBRARY || (defined PIC && defined INSTALLDIR && ENABLE_COSTLY_RELOCATABLE)

/* Convenience function:
   Computes the current installation prefix, based on the original
   installation prefix, the original installation directory of a particular
   file, and the current pathname of this file.
   Returns it, freshly allocated.  Returns NULL upon failure.  */
#ifdef IN_LIBRARY
#define compute_curr_prefix local_compute_curr_prefix
static
#endif
char *
compute_curr_prefix (const char *orig_installprefix,
                     const char *orig_installdir,
                     const char *curr_pathname)
{
  char *curr_installdir;
  const char *rel_installdir;

  if (curr_pathname == NULL)
    return NULL;

  /* Determine the relative installation directory, relative to the prefix.
     This is simply the difference between orig_installprefix and
     orig_installdir.  */
  if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix))
      != 0)
    /* Shouldn't happen - nothing should be installed outside $(prefix).  */
    return NULL;
  rel_installdir = orig_installdir + strlen (orig_installprefix);

  /* Determine the current installation directory.  */
  {
    const char *p_base = curr_pathname + FILE_SYSTEM_PREFIX_LEN (curr_pathname);
    const char *p = curr_pathname + strlen (curr_pathname);
    char *q;

    while (p > p_base)
      {
        p--;
        if (ISSLASH (*p))
          break;
      }

    q = (char *) xmalloc (p - curr_pathname + 1);
#ifdef NO_XMALLOC
    if (q == NULL)
      return NULL;
#endif
    memcpy (q, curr_pathname, p - curr_pathname);
    q[p - curr_pathname] = '\0';
    curr_installdir = q;
  }

  /* Compute the current installation prefix by removing the trailing
     rel_installdir from it.  */
  {
    const char *rp = rel_installdir + strlen (rel_installdir);
    const char *cp = curr_installdir + strlen (curr_installdir);
    const char *cp_base =
      curr_installdir + FILE_SYSTEM_PREFIX_LEN (curr_installdir);

    while (rp > rel_installdir && cp > cp_base)
      {
        bool same = false;
        const char *rpi = rp;
        const char *cpi = cp;

        while (rpi > rel_installdir && cpi > cp_base)
          {
            rpi--;
            cpi--;
            if (ISSLASH (*rpi) || ISSLASH (*cpi))
              {
                if (ISSLASH (*rpi) && ISSLASH (*cpi))
                  same = true;
                break;
              }
            /* Do case-insensitive comparison if the file system is always or
               often case-insensitive.  It's better to accept the comparison
               if the difference is only in case, rather than to fail.  */
#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__
            /* Native Windows, Cygwin, OS/2, DOS - case insignificant file system */
            if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi)
                != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi))
              break;
#else
            if (*rpi != *cpi)
              break;
#endif
          }
        if (!same)
          break;
        /* The last pathname component was the same.  opi and cpi now point
           to the slash before it.  */
        rp = rpi;
        cp = cpi;
      }

    if (rp > rel_installdir)
      {
        /* Unexpected: The curr_installdir does not end with rel_installdir.  */
        free (curr_installdir);
        return NULL;
      }

    {
      size_t curr_prefix_len = cp - curr_installdir;
      char *curr_prefix;

      curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
#ifdef NO_XMALLOC
      if (curr_prefix == NULL)
        {
          free (curr_installdir);
          return NULL;
        }
#endif
      memcpy (curr_prefix, curr_installdir, curr_prefix_len);
      curr_prefix[curr_prefix_len] = '\0';

      free (curr_installdir);

      return curr_prefix;
    }
  }
}

#endif /* !IN_LIBRARY || PIC */

#if defined PIC && defined INSTALLDIR && ENABLE_COSTLY_RELOCATABLE

/* Full pathname of shared library, or NULL.  */
static char *shared_library_fullname;

#if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
/* Native Windows only.
   On Cygwin, it is better to use the Cygwin provided /proc interface, than
   to use native Windows API and cygwin_conv_to_posix_path, because it
   supports longer file names
   (see <http://cygwin.com/ml/cygwin/2011-01/msg00410.html>).  */

/* Determine the full pathname of the shared library when it is loaded.  */

BOOL WINAPI
DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
{
  (void) reserved;

  if (event == DLL_PROCESS_ATTACH)
    {
      /* The DLL is being loaded into an application's address range.  */
      static char location[MAX_PATH];

      if (!GetModuleFileName (module_handle, location, sizeof (location)))
        /* Shouldn't happen.  */
        return FALSE;

      if (!IS_PATH_WITH_DIR (location))
        /* Shouldn't happen.  */
        return FALSE;

      shared_library_fullname = strdup (location);
    }

  return TRUE;
}

#elif defined __EMX__

extern int  _CRT_init (void);
extern void _CRT_term (void);
extern void __ctordtorInit (void);
extern void __ctordtorTerm (void);

unsigned long _System
_DLL_InitTerm (unsigned long hModule, unsigned long ulFlag)
{
  static char location[CCHMAXPATH];

  switch (ulFlag)
    {
      case 0:
        if (_CRT_init () == -1)
          return 0;

        __ctordtorInit();

        /* See http://cyberkinetica.homeunix.net/os2tk45/cp1/1247_L2H_DosQueryModuleNameSy.html
           for specification of DosQueryModuleName(). */
        if (DosQueryModuleName (hModule, sizeof (location), location))
          return 0;

        _fnslashify (location);
        shared_library_fullname = strdup (location);
        break;

      case 1:
        __ctordtorTerm();

        _CRT_term ();
        break;
    }

  return 1;
}

#else /* Unix */

static void
find_shared_library_fullname ()
{
#if (defined __linux__ && (__GLIBC__ >= 2 || defined __UCLIBC__)) || defined __CYGWIN__
  /* Linux has /proc/self/maps. glibc 2 and uClibc have the getline()
     function.
     Cygwin >= 1.5 has /proc/self/maps and the getline() function too.
     But it is costly: ca. 0.3 ms on Linux, 3 ms on Cygwin 1.5, and 5 ms on
     Cygwin 1.7.  */
  FILE *fp;

  /* Open the current process' maps file.  It describes one VMA per line.  */
  fp = fopen ("/proc/self/maps", "r");
  if (fp)
    {
      unsigned long address = (unsigned long) &find_shared_library_fullname;
      for (;;)
        {
          unsigned long start, end;
          int c;

          if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
            break;
          if (address >= start && address <= end - 1)
            {
              /* Found it.  Now see if this line contains a filename.  */
              while (c = getc (fp), c != EOF && c != '\n' && c != '/')
                continue;
              if (c == '/')
                {
                  size_t size;
                  int len;

                  ungetc (c, fp);
                  shared_library_fullname = NULL; size = 0;
                  len = getline (&shared_library_fullname, &size, fp);
                  if (len >= 0)
                    {
                      /* Success: filled shared_library_fullname.  */
                      if (len > 0 && shared_library_fullname[len - 1] == '\n')
                        shared_library_fullname[len - 1] = '\0';
                    }
                }
              break;
            }
          while (c = getc (fp), c != EOF && c != '\n')
            continue;
        }
      fclose (fp);
    }
#endif
}

#endif /* Native Windows / EMX / Unix */

/* Return the full pathname of the current shared library.
   Return NULL if unknown.
   Guaranteed to work only on Linux, EMX, Cygwin, and native Windows.  */
static char *
get_shared_library_fullname ()
{
#if (!((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) \
     && !defined __EMX__)
  static bool tried_find_shared_library_fullname;
  if (!tried_find_shared_library_fullname)
    {
      find_shared_library_fullname ();
      tried_find_shared_library_fullname = true;
    }
#endif
  return shared_library_fullname;
}

#endif /* PIC */

/* Returns the pathname, relocated according to the current installation
   directory.
   The returned string is either PATHNAME unmodified or a freshly allocated
   string that you can free with free() after casting it to 'char *'.  */
const char *
relocate (const char *pathname)
{
#if defined PIC && defined INSTALLDIR && ENABLE_COSTLY_RELOCATABLE
  static int initialized;

  /* Initialization code for a shared library.  */
  if (!initialized)
    {
      /* At this point, orig_prefix and curr_prefix likely have already been
         set through the main program's set_program_name_and_installdir
         function.  This is sufficient in the case that the library has
         initially been installed in the same orig_prefix.  But we can do
         better, to also cover the cases that 1. it has been installed
         in a different prefix before being moved to orig_prefix and (later)
         to curr_prefix, 2. unlike the program, it has not moved away from
         orig_prefix.  */
      const char *orig_installprefix = INSTALLPREFIX;
      const char *orig_installdir = INSTALLDIR;
      char *curr_prefix_better;

      curr_prefix_better =
        compute_curr_prefix (orig_installprefix, orig_installdir,
                             get_shared_library_fullname ());

      set_relocation_prefix (orig_installprefix,
                             curr_prefix_better != NULL
                             ? curr_prefix_better
                             : curr_prefix);

      if (curr_prefix_better != NULL)
        free (curr_prefix_better);

      initialized = 1;
    }
#endif

  /* Note: It is not necessary to perform case insensitive comparison here,
     even for DOS-like file systems, because the pathname argument was
     typically created from the same Makefile variable as orig_prefix came
     from.  */
  if (orig_prefix != NULL && curr_prefix != NULL
      && strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
    {
      if (pathname[orig_prefix_len] == '\0')
        {
          /* pathname equals orig_prefix.  */
          char *result = (char *) xmalloc (strlen (curr_prefix) + 1);

#ifdef NO_XMALLOC
          if (result != NULL)
#endif
            {
              strcpy (result, curr_prefix);
              return result;
            }
        }
      else if (ISSLASH (pathname[orig_prefix_len]))
        {
          /* pathname starts with orig_prefix.  */
          const char *pathname_tail = &pathname[orig_prefix_len];
          char *result =
            (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);

#ifdef NO_XMALLOC
          if (result != NULL)
#endif
            {
              memcpy (result, curr_prefix, curr_prefix_len);
              strcpy (result + curr_prefix_len, pathname_tail);
              return result;
            }
        }
    }

#ifdef __EMX__
# ifdef __KLIBC__
#  undef strncmp

  if (pathname && strncmp (pathname, "/@unixroot", 10) == 0
      && (pathname[10] == '\0' || pathname[10] == '/' || pathname[10] == '\\'))
    {
      /* kLIBC itself processes /@unixroot prefix */

      return pathname;
    }
  else
# endif
  if (pathname && ISSLASH (pathname[0]))
    {
      const char *unixroot = getenv ("UNIXROOT");

      if (unixroot && HAS_DEVICE (unixroot) && !unixroot[2])
        {
          char *result = (char *) xmalloc (2 + strlen (pathname) + 1);
#ifdef NO_XMALLOC
          if (result != NULL)
#endif
            {
              strcpy (result, unixroot);
              strcpy (result + 2, pathname);
              return result;
            }
        }
    }
#endif

  /* Nothing to relocate.  */
  return pathname;
}

#endif


text:
"""
Written by nickcooper-zhangtonghao
Github: https://github.com/nickcooper-zhangtonghao
Email: nickcooper-zhangtonghao@opencloud.tech
Note: Example code For testing purposes only
This code has been released under the terms of the Apache-2.0 license
http://opensource.org/licenses/Apache-2.0
"""
from __future__ import print_function
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import atexit
import sys
import argparse

def get_args():
    parser = argparse.ArgumentParser(
        description='Arguments for talking to vCenter')

    parser.add_argument('-s', '--host',
                        required=True,
                        action='store',
                        help='vSpehre service to connect to')

    parser.add_argument('-o', '--port',
                        type=int,
                        default=443,
                        action='store',
                        help='Port to connect on')

    parser.add_argument('-u', '--user',
                        required=True,
                        action='store',
                        help='User name to use')

    parser.add_argument('-p', '--password',
                        required=True,
                        action='store',
                        help='Password to use')

    parser.add_argument('-v', '--vswitch',
                        required=True,
                        action='store',
                        help='vSwitch to create')

    args = parser.parse_args()
    return args

def GetVMHosts(content):
    host_view = content.viewManager.CreateContainerView(content.rootFolder,
                                                        [vim.HostSystem],
                                                        True)
    obj = [host for host in host_view.view]
    host_view.Destroy()
    return obj

def AddHostsSwitch(hosts, vswitchName):
    for host in hosts:
        AddHostSwitch(host, vswitchName)

def AddHostSwitch(host, vswitchName):
    vswitch_spec = vim.host.VirtualSwitch.Specification()
    vswitch_spec.numPorts = 1024
    vswitch_spec.mtu = 1450
    host.configManager.networkSystem.AddVirtualSwitch(vswitchName,
                                                      vswitch_spec)

def main():
    args = get_args()
    serviceInstance = SmartConnect(host=args.host,
                                   user=args.user,
                                   pwd=args.password,
                                   port=443)
    atexit.register(Disconnect, serviceInstance)
    content = serviceInstance.RetrieveContent()

    hosts = GetVMHosts(content)
    AddHostsSwitch(hosts, args.vswitch)

# Main section
if __name__ == "__main__":
    sys.exit(main())


text:
Rails.application.routes.draw do
  root 'questions#index'

  devise_for :users, skip: %i[sessions registrations]
  devise_scope :user do
    get     'login'  => 'devise/sessions#new',     as: :new_user_session
    post    'login'  => 'devise/sessions#create',  as: :user_session
    delete  'logout' => 'devise/sessions#destroy', as: :destroy_user_session
    get   'register' => 'devise/registrations#new',    as: :new_user_registration
    post  'register' => 'devise/registrations#create', as: :user_registration
  end

  concern :votable do
    member do
      post :upvote
      post :downvote
    end
  end

  concern :subscribable do
    member do
      post :subscribe
      post :unsubscribe
    end
  end

  get '/ask', to: redirect('/questions/new')
  get '/q/:id', to: redirect('/questions/%{id}'), as: :question_short
  get '/settings', to: redirect('/settings/profile')
  get '/search', to: 'search#index', as: :search

  namespace :admin do
    root 'dashboard#show', as: :dashboard
  end

  namespace :settings do
    resource :account, only: %i[show update]
    resource :profile, only: %i[show update]
    resource :password, only: %i[show update]
  end

  resources :tags, only: [:show], param: :name
  resources :categories, only: %i[index show], param: :permalink, concerns: :subscribable
  resources :users, only: [:show], param: :username do
    member do
      get :answers
      get :questions
    end
  end
  resources :questions, only: %i[index new create], concerns: :votable do
    post :star, on: :member
    resources :answers, only: %i[new create]
  end
  resources :answers, only: [], concerns: :votable

  get '/questions/*id(/:permalink)', to: 'questions#show', as: :question
end


text:
FROM node:14

# Install dependencies
RUN apt-get update && \
    apt-get install -y curl git jq

# Install npm at latest.
RUN npm install --global npm@latest

# Install hub
RUN curl -fsSL --output hub.tgz https://github.com/github/hub/releases/download/v2.13.0/hub-linux-amd64-2.13.0.tgz
RUN tar --strip-components=2 -C /usr/bin -xf hub.tgz hub-linux-amd64-2.13.0/bin/hub


text:
<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/include/autoprepend.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/include/cms-inc/include_cms.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/include/cms-inc/include_class.php');

if (is_get('source')){
	$scoord = $_GET['source'];
}
else{
	$scoord = '';
}

//source
if (is_get('idField')){
	$ssource = $_GET['idField'];
}
else{
	$ssource = '';
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>Couleur Citron - Objets</title>

<?php
if ($scoord != ''){

}
?>

<input id="fformat" name="fformat" type="text" value="aa" style="width:690px" disabled="disabled" />

<input id="fcoords" name="fcoords" type="text" value="<?php echo $scoord; ?>" style="width:690px"/>
<input id="fok" name="fok" type="submit" value="OK" style="width:100px" onclick="returnCoords();"/>


text:
using System.Collections.Generic;
using System.Threading.Tasks;

namespace NTierApplications.Domain.ServiceInterfaces
{
	public interface ICommonServiceAsync<TEntity>
	{
		Task CreateAsync(TEntity entity);
		Task UpdateAsync(TEntity entity);
		Task DeleteAsync(int id);
		Task<TEntity> FindByIdAsync(int id);
		Task<IEnumerable<TEntity>> GetAllAsync();
		void Dispose();
	}
}


text:
module NotifierHelpers
  def reconfigure_notifier
    Rollbar.clear_notifier!

    Rollbar.reconfigure do |config|
      # special test access token
      config.access_token = test_access_token
      config.logger = ::Rails.logger
      config.root = ::Rails.root
      config.framework = "Rails: #{::Rails::VERSION::STRING}"
      config.open_timeout = 60
      config.request_timeout = 60
    end
  end

  def preconfigure_rails_notifier
    rails_logger = if defined?(::Rails.logger)
                     ::Rails.logger
                   elsif defined?(RAILS_DEFAULT_LOGGER)
                     RAILS_DEFAULT_LOGGER
                   end

    Rollbar.preconfigure do |config|
      config.logger = rails_logger
      config.environment = defined?(::Rails.env) && ::Rails.env ||
                           defined?(RAILS_ENV) && RAILS_ENV
      config.root = defined?(::Rails.root) && ::Rails.root ||
                    defined?(RAILS_ROOT) && RAILS_ROOT
      version = defined?(::Rails.version) && ::Rails.version ||
                defined?(::Rails::VERSION::STRING) && ::Rails::VERSION::STRING
      config.framework = "Rails: #{version}"
    end
  end

  def test_access_token
    'bfec94a1ede64984b862880224edd0ed'
  end

  def reset_configuration
    Rollbar.reconfigure do |config|
    end
  end

  def clear_proxy_env_vars
    env_vars = {}
    proxy_env_vars.each do |var|
      env_vars[var] = ENV.delete(var)
    end
    env_vars
  end

  def restore_proxy_env_vars(env_vars)
    proxy_env_vars.each do |var|
      ENV[var] = env_vars[var]
    end
  end

  def proxy_env_vars
    %w[http_proxy HTTP_PROXY https_proxy HTTPS_PROXY]
  end
end


text:
namespace Pixator.Api.Areas.HelpPage.ModelDescriptions
{
    public class SimpleTypeModelDescription : ModelDescription
    {
    }
}


text:
#pragma once

#include <memory>
#include <optional>

#include <thrift/lib/cpp2/async/AsyncProcessor.h>

namespace folly {
class EventBase;
}

namespace apache {
namespace thrift {

class AsyncProcessor;
class Cpp2Worker;
class RequestSetupMetadata;
class ThriftServer;
class RequestsRegistry;

namespace concurrency {
class ThreadManager;
} // namespace concurrency

namespace server {
class ServerConfigs;
} // namespace server

namespace rocket {

struct ProcessorInfo {
  ProcessorInfo(
      apache::thrift::AsyncProcessorFactory& processorFactory,
      std::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager,
      server::ServerConfigs& serverConfigs,
      RequestsRegistry* requestsRegistry,
      bool useResourcePool = false)
      : processorFactory_(processorFactory),
        threadManager_(std::move(threadManager)),
        serverConfigs_(serverConfigs),
        requestsRegistry_(std::move(requestsRegistry)),
        useResourcePool_(useResourcePool) {}

  apache::thrift::AsyncProcessorFactory& processorFactory_;
  std::shared_ptr<apache::thrift::concurrency::ThreadManager> threadManager_;
  server::ServerConfigs& serverConfigs_;
  RequestsRegistry* FOLLY_NULLABLE requestsRegistry_;
  bool useResourcePool_;
};

/*
 * An interface used by ThriftServer to allow overriding
 * default processor and thread pool based on connection setup frame.
 */
class SetupFrameHandler {
 public:
  SetupFrameHandler() = default;
  virtual ~SetupFrameHandler() = default;
  SetupFrameHandler(const SetupFrameHandler&) = delete;

  virtual std::optional<ProcessorInfo> tryHandle(
      const RequestSetupMetadata& meta) = 0;
};

} // namespace rocket
} // namespace thrift
} // namespace apache


text: export { default } from './CardList';


text:
package extruder.metrics.syntax

import extruder.metrics.data.CounterValue
import extruder.metrics.syntax.counter._
import org.scalatest.funsuite.AnyFunSuite
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks

class CounterSyntaxSpec extends AnyFunSuite with ScalaCheckDrivenPropertyChecks {
  test("Can convert a numeric into a gauge")(forAll { i: Int =>
    i.toCounter === CounterValue(i)
  })
}


text:
package org.keycloak.subsystem.adapter.extension;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest;
import org.jboss.dmr.ModelNode;
import org.junit.Test;

import java.io.IOException;

/**
 * Tests all management expects for subsystem, parsing, marshaling, model definition and other
 * Here is an example that allows you a fine grained controller over what is tested and how. So it can give you ideas what can be done and tested.
 * If you have no need for advanced testing of subsystem you look at {@link SubsystemBaseParsingTestCase} that testes same stuff but most of the code
 * is hidden inside of test harness
 *
 * @author Kabir Khan
 * @author Tomaz Cerar
 * @author Marko Strukelj
 */
public class SubsystemParsingTestCase extends AbstractSubsystemBaseTest {

    public SubsystemParsingTestCase() {
        super(KeycloakExtension.SUBSYSTEM_NAME, new KeycloakExtension());
    }

    @Test
    public void testJson() throws Exception {
        ModelNode node = new ModelNode();
        node.get("realm").set("demo");
        node.get("resource").set("customer-portal");
        node.get("realm-public-key").set("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB");
        node.get("auth-url").set("http://localhost:8080/auth-server/rest/realms/demo/protocol/openid-connect/login");
        node.get("code-url").set("http://localhost:8080/auth-server/rest/realms/demo/protocol/openid-connect/access/codes");
        node.get("ssl-required").set("external");
        node.get("confidential-port").set(443);
        node.get("expose-token").set(true);

        ModelNode jwtCredential = new ModelNode();
        jwtCredential.get("client-keystore-file").set("/tmp/keystore.jks");
        jwtCredential.get("client-keystore-password").set("changeit");
        ModelNode credential = new ModelNode();
        credential.get("jwt").set(jwtCredential);
        node.get("credentials").set(credential);

        System.out.println("json=" + node.toJSONString(false));
    }

    @Test
    public void testJsonFromSignedJWTCredentials() {
        KeycloakAdapterConfigService service = KeycloakAdapterConfigService.getInstance();

        PathAddress addr = PathAddress.pathAddress(PathElement.pathElement("subsystem", "keycloak"), PathElement.pathElement("secure-deployment", "foo"));
        ModelNode deploymentOp = new ModelNode();
        deploymentOp.get(ModelDescriptionConstants.OP_ADDR).set(addr.toModelNode());
        ModelNode deployment = new ModelNode();
        deployment.get("realm").set("demo");
        deployment.get("resource").set("customer-portal");
        service.addSecureDeployment(deploymentOp, deployment, false);

        addCredential(addr, service, "secret", "secret1");
        addCredential(addr, service, "jwt.client-keystore-file", "/tmp/foo.jks");
        addCredential(addr, service, "jwt.token-timeout", "10");
    }

    private void addCredential(PathAddress parent, KeycloakAdapterConfigService service, String key, String value) {
        PathAddress credAddr = PathAddress.pathAddress(parent, PathElement.pathElement("credential", key));
        ModelNode credOp = new ModelNode();
        credOp.get(ModelDescriptionConstants.OP_ADDR).set(credAddr.toModelNode());
        ModelNode credential = new ModelNode();
        credential.get("value").set(value);
        service.addCredential(credOp, credential);
    }

    @Override
    protected String getSubsystemXml() throws IOException {
        return readResource("keycloak-1.1.xml");
    }

    @Override
    protected String getSubsystemXsdPath() throws Exception {
        return "schema/wildfly-keycloak_1_1.xsd";
    }

    @Override
    protected String[] getSubsystemTemplatePaths() throws IOException {
        return new String[]{
                "/subsystem-templates/keycloak-adapter.xml"
        };
    }
}


text:
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                */
/*                                                                            */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
/* not use this file except in compliance with the License. You may obtain    */
/* a copy of the License at                                                   */
/*                                                                            */
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
/*                                                                            */
/* Unless required by applicable law or agreed to in writing, software        */
/* distributed under the License is distributed on an "AS IS" BASIS,          */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
/* See the License for the specific language governing permissions and        */
/* limitations under the License.                                             */
/* -------------------------------------------------------------------------- */

#include "Hook.h"
#include "Nebula.h"

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void AllocateRemoveHook::do_hook(void *arg)
{
    PoolObjectSQL * obj = static_cast<PoolObjectSQL *>(arg);
    string          parsed_args = args;

    if ( obj == 0 )
    {
        return;
    }

    parse_hook_arguments(obj, parsed_args);

    Nebula& ne                    = Nebula::instance();
    HookManager * hm              = ne.get_hm();
    const HookManagerDriver * hmd = hm->get();

    if ( hmd != 0 )
    {
        if ( remote == true )
        {
            string hostname;

            hmd->execute(obj->get_oid(),
                         name,
                         remote_host(obj, hostname),
                         cmd,
                         parsed_args);
        }
        else
        {
            hmd->execute(obj->get_oid(), name, cmd, parsed_args);
        }
    }
}

/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

void Hook::parse_hook_arguments(PoolObjectSQL *obj,
                                string&       parsed)
{
    size_t  found;

    found = parsed.find("$ID");

    if ( found !=string::npos )
    {
        ostringstream oss;
        oss << obj->get_oid();

        parsed.replace(found, 3, oss.str());
    }

    found = parsed.find("$TEMPLATE");

    if ( found != string::npos )
    {
        string templ;
        parsed.replace(found, 9, obj->to_xml64(templ));
    }
}


text:
class Profile;

namespace extensions {

class SettingsOverridesAPI : public BrowserContextKeyedAPI,
                             public ExtensionRegistryObserver {
 public:
  explicit SettingsOverridesAPI(content::BrowserContext* context);

  SettingsOverridesAPI(const SettingsOverridesAPI&) = delete;
  SettingsOverridesAPI& operator=(const SettingsOverridesAPI&) = delete;

  ~SettingsOverridesAPI() override;

  // BrowserContextKeyedAPI implementation.
  static BrowserContextKeyedAPIFactory<SettingsOverridesAPI>*
      GetFactoryInstance();

 private:
  friend class BrowserContextKeyedAPIFactory<SettingsOverridesAPI>;

  // Wrappers around PreferenceAPI.
  void SetPref(const std::string& extension_id,
               const std::string& pref_key,
               std::unique_ptr<base::Value> value) const;
  void UnsetPref(const std::string& extension_id,
                 const std::string& pref_key) const;

  // ExtensionRegistryObserver implementation.
  void OnExtensionLoaded(content::BrowserContext* browser_context,
                         const Extension* extension) override;
  void OnExtensionUnloaded(content::BrowserContext* browser_context,
                           const Extension* extension,
                           UnloadedExtensionReason reason) override;

  void RegisterSearchProvider(const Extension* extension) const;
  // BrowserContextKeyedAPI implementation.
  static const char* service_name() { return "SettingsOverridesAPI"; }

  raw_ptr<Profile> profile_;
  raw_ptr<TemplateURLService> url_service_;

  // Listen to extension load, unloaded notifications.
  base::ScopedObservation<ExtensionRegistry, ExtensionRegistryObserver>
      extension_registry_observation_{this};
};

template <>
void BrowserContextKeyedAPIFactory<
    SettingsOverridesAPI>::DeclareFactoryDependencies();

}  // namespace extensions

#endif  // CHROME_BROWSER_EXTENSIONS_API_SETTINGS_OVERRIDES_SETTINGS_OVERRIDES_API_H_


text:
**Table Of Contents**
- [Description](#description)
    * [Structure](#structure)
- [Parameters](#parameters)
- [Additional resources](#additional-resources)
- [License](#license)
- [Changelog](#changelog)
- [Known issues](#known-issues)

## Description

Adds a residual tensor, applies layer normalization, i.e., transforms the mean and standard deviation to beta and gamma respectively.
Optionally can adds a bias vector before layer-normalization.

### Structure

The `skipLayerNormPlugin` takes two inputs; `input` and `skip`.

`input`
input is a tensor with shape `[S, B, E]` where `B` is the batch size and `E` is the hidden size.

`skip`
skip is a tensor with shape `[S, B, E]` where `B` is the batch size and `E` is the hidden size.
The purpose of this input is to introduce skip (aka. residual) connections to previously computed tensors.

The `skipLayerNormPlugin` generates the following output:

`output`
output is a tensor with shape `[S, B, E]` where `B` is the batch size.

## Parameters

`skipLayerNormPlugin` has plugin creator class `SkipLayerNormPluginDynamicCreator` and plugin class `CustomSkipLayerNormPluginDynamic`.

The parameters are defined below and consists of the following attributes:

| Type     | Parameter                               |  Version   | Description
|----------|-----------------------------------------|------------|-------------------------------------------------------------------
|`int`     |`type_id`                                |  1, 2      |Integer encoding the DataType (0: FP32, 1: FP16, 2: INT8)
|`int`     |`ld`                                     |  1         |The leading dimension of the input tensor, corresponding to the hidden size, denoted by `E` above.
|`Weights` |`beta`                                   |  1, 2, 3   |The mean to normalize to. Shape: `[1, 1, E]`
|`Weights` |`gamma`                                  |  1, 2, 3   |The standard deviation to normalize to. Shape: `[1, 1, E]`
|`Weights` |`bias`                                   |  1, 2      |An optional bias vector to add before normalization. Shape: `[1, 1, E]`

## Additional resources

-   [LayerNorm](https://arxiv.org/abs/1607.06450)

## License

For terms and conditions for use, reproduction, and distribution, see the [TensorRT Software License Agreement](https://docs.nvidia.com/deeplearning/sdk/tensorrt-sla/index.html)
documentation.

## Changelog

October  2020
Add V2 plugin that supports variable sequence length.
Add v3 plugin that supports int8 interleaved variable sequence length.

November 2019
This is the first release of this `README.md` file.

## Known issues

This plugin only supports GPUs with compute capability >= 7.0. For more information see the [CUDA GPU Compute Capability Support Matrix](https://developer.nvidia.com/cuda-gpus#compute)