decode Olympus SpecialMode tag in MakerNote
424412
def special_mode(v):
    """"""
    mode1 = {
        0: 'Normal',
        1: 'Unknown',
        2: 'Fast',
        3: 'Panorama',
    }
    mode2 = {
        0: 'Non-panoramic',
        1: 'Left to right',
        2: 'Right to left',
        3: 'Bottom to top',
        4: 'Top to bottom',
    }
    if not v or (v[0] not in mode1 or v[2] not in mode2):
        return v
    return '%s - sequence %d - %s' % (mode1[v[0]], v[1], mode2[v[2]])
329183
def denormalize_attachment(attachment):
        ''''''
        res = dict()
        ext = ['id', 'url']
        for k in ext:
            if k in attachment['metadata']:
                raise ValueError("metadata section could not contain special key '{}'".format(k))
            res[k] = attachment[k]
        res.update(attachment['metadata'])
        return res
837076
def decode(self, pdu):
        """"""
        while pdu.pduData:
            self.tagList.append( Tag(pdu) )
1213666
def ascii_mode(enabled=True):
    
    global _backups, _chars, _primary_style, _secondary_style, _ascii_mode
    if not (enabled or _backups) or (enabled and _ascii_mode):
        return
    if enabled:
        _backups = _chars.copy(), _primary_style, _secondary_style
        _chars = {
            "primary": {"selected": "*", "block": "#"},
            "secondary": {"arrow": ">", "left-edge": "|", "right-edge": "|"},
            "plain": {"unselected": "."},
        }
        _primary_style = ()
        _secondary_style = ()
    else:
        _chars, _primary_style, _secondary_style = _backups
    _ascii_mode = enabled
330628
function decodeDoc(doc) {
  if (!doc) {
    return doc;
  }
  var idx = doc._doc_id_rev.lastIndexOf(':');
  doc._id = doc._doc_id_rev.substring(0, idx - 1);
  doc._rev = doc._doc_id_rev.substring(idx + 1);
  delete doc._doc_id_rev;
  return doc;
}
872186
def tag(self):
        
        return "{}{}_{}{:02d}".format(self.target.prefix,
                                      self,
                                      self.target.version,
                                      self.target.ccd)
665682
def encodeSpecialChars(self, input):
        
        ret = libxml2mod.xmlEncodeSpecialChars(self._o, input)
        return ret
1242156
def from_stream(cls, stream, marker_code, offset):
        
        # field                 off  type   notes
        # ------------------  ---  -----  ----------------------------
        # segment length       0   short
        # Data precision       2   byte
        # Vertical lines       3   short  px_height
        # Horizontal lines     5   short  px_width
        # ------------------  ---  -----  ----------------------------
        segment_length = stream.read_short(offset)
        px_height = stream.read_short(offset, 3)
        px_width = stream.read_short(offset, 5)
        return cls(marker_code, offset, segment_length, px_width, px_height)
803277
def _handle_tag_defineedittext(self):
        """"""
        obj = _make_object("DefineEditText")
        obj.CharacterID = unpack_ui16(self._src)
        obj.Bounds = self._get_struct_rect()

        bc = BitConsumer(self._src)
        obj.HasText = bc.u_get(1)
        obj.WordWrap = bc.u_get(1)
        obj.Multiline = bc.u_get(1)
        obj.Password = bc.u_get(1)
        obj.ReadOnly = bc.u_get(1)
        obj.HasTextColor = bc.u_get(1)
        obj.HasMaxLength = bc.u_get(1)
        obj.HasFont = bc.u_get(1)
        obj.HasFontClass = bc.u_get(1)
        obj.AutoSize = bc.u_get(1)
        obj.HasLayout = bc.u_get(1)
        obj.NoSelect = bc.u_get(1)
        obj.Border = bc.u_get(1)
        obj.WasStatic = bc.u_get(1)
        obj.HTML = bc.u_get(1)
        obj.UseOutlines = bc.u_get(1)

        if obj.HasFont:
            obj.FontID = unpack_ui16(self._src)
        if obj.HasFontClass:
            obj.FontClass = self._get_struct_string()
        if obj.HasFont:
            obj.FontHeight = unpack_ui16(self._src)
        if obj.HasTextColor:
            obj.TextColor = self._get_struct_rgba()
        if obj.HasMaxLength:
            obj.MaxLength = unpack_ui16(self._src)
        if obj.HasLayout:
            obj.Align = unpack_ui8(self._src)
            obj.LeftMargin = unpack_ui16(self._src)
            obj.RightMargin = unpack_ui16(self._src)
            obj.Indent = unpack_ui16(self._src)
            obj.Leading = unpack_ui16(self._src)

        obj.VariableName = self._get_struct_string()
        if obj.HasText:
            obj.InitialText = self._get_struct_string()
        return obj
69510
def get_fwhm_tag(expnum, ccd, prefix=None, version='p'):
    
    uri = get_uri(expnum, ccd, version, ext='fwhm', prefix=prefix)
    if uri not in fwhm:
        key = "fwhm_{:1s}{:02d}".format(version, int(ccd))
        fwhm[uri] = get_tag(expnum, key)
    return fwhm[uri]
295142
function getMaskTemplate(mask) {
                if (opts.numericInput) {
                    mask = mask.split('').reverse().join('');
                }
                var escaped = false, outCount = 0, greedy = opts.greedy, repeat = opts.repeat;
                if (repeat == "*") greedy = false;
                //if (greedy == true && opts.placeholder == "") opts.placeholder = " ";
                if (mask.length == 1 && greedy == false && repeat != 0) { opts.placeholder = ""; } //hide placeholder with single non-greedy mask
                var singleMask = $.map(mask.split(""), function (element, index) {
                    var outElem = [];
                    if (element == opts.escapeChar) {
                        escaped = true;
                    }
                    else if ((element != opts.optionalmarker.start && element != opts.optionalmarker.end) || escaped) {
                        var maskdef = opts.definitions[element];
                        if (maskdef && !escaped) {
                            for (var i = 0; i < maskdef.cardinality; i++) {
                                outElem.push(opts.placeholder.charAt((outCount + i) % opts.placeholder.length));
                            }
                        } else {
                            outElem.push(element);
                            escaped = false;
                        }
                        outCount += outElem.length;
                        return outElem;
                    }
                });

                //allocate repetitions
                var repeatedMask = singleMask.slice();
                for (var i = 1; i < repeat && greedy; i++) {
                    repeatedMask = repeatedMask.concat(singleMask.slice());
                }

                return { "mask": repeatedMask, "repeat": repeat, "greedy": greedy };
            }
43414
def tagversion(repo, level='patch', special=''):
    
    prepend = 'v'
    with lcd(repo):
        oldversion = local(
            'git describe --abbrev=0 --tags', capture=True).strip()
        if oldversion.startswith('v'):
            oldversion = oldversion[1:]
        else:
            prepend = ''
    major, minor, patch = [int(x) for x in re.split('\D', oldversion, 3)[:3]]
    if special:
        if not re.match('^[a-z]', special):
            raise ValueError('Special must start with a-z')
        if not re.match('[_a-zA-Z0-9]+', special):
            raise ValueError('Must contain start with lowercase letter')
    if level == 'major':
        major, minor, patch = major + 1, 0, 0
    elif level == 'minor':
        major, minor, patch = major, minor + 1, 0
    elif level == 'patch':
        major, minor, patch = major, minor, patch + 1
    version_string = '{}.{}.{}'.format(major, minor, patch) + special
    with lcd(repo):
        local('git tag -s --force {}{}'.format(prepend, version_string))
    return version_string
105815
function toGemoji(node) {
  var value = toString(node)
  var info = (unicodes[value] || emoticons[value] || {}).shortcode

  if (info) {
    node.value = info
  }
}
769664
def recompute_mag(mpc_in, skip_centroids=False):
    
    # TODO this really shouldn't need to build a 'reading' to get the cutout...

    from ossos.downloads.cutouts import downloader
    dlm = downloader.ImageCutoutDownloader()

    mpc_obs = deepcopy(mpc_in)
    assert isinstance(mpc_obs, mp_ephem.ephem.Observation)
    assert isinstance(mpc_obs.comment, mp_ephem.ephem.OSSOSComment)

    if mpc_obs.null_observation:
        return mpc_obs

    parts = re.search('(?P<expnum>\d{7})(?P<type>\S)(?P<ccd>\d\d)', mpc_obs.comment.frame)
    if parts is None:
        return mpc_obs
    expnum = parts.group('expnum')
    ccd = parts.group('ccd')
    file_type = parts.group('type')

    observation = astrom.Observation(expnum, file_type, ccd)
    assert isinstance(observation, astrom.Observation)

    ast_header = _connection_error_wrapper(storage._get_sghead, int(expnum))[int(ccd)+1]

    filter_value = None
    for keyword in ['FILTER', 'FILT1 NAME']:
       filter_value = ast_header.get(keyword, None)
       if filter_value is not None:
         if filter_value.startswith('gri'):
             filter_value = 'w'
         else:
             filter_value = filter_value[0]
         break
    # The ZP for the current astrometric lines is the pipeline one.  The new ZP is in the astheader file.
    new_zp = ast_header.get('PHOTZP')

    # The .zeropoint.used value is likely the one used for the original photometry.
    old_zp = _connection_error_wrapper(storage.get_zeropoint, int(expnum), int(ccd))

    reading = astrom.SourceReading(float(mpc_obs.comment.x), float(mpc_obs.comment.y), float(mpc_obs.comment.x),
                                   float(mpc_obs.comment.y), mpc_obs.coordinate.ra.degree,
                                   mpc_obs.coordinate.dec.degree, float(mpc_obs.comment.x), float(mpc_obs.comment.y),
                                   observation, ssos=True, from_input_file=True, null_observation=False,
                                   discovery=mpc_obs.discovery)

    cutout = _connection_error_wrapper(dlm.download_cutout, reading, needs_apcor=True)
    cutout._zmag = new_zp

    if math.fabs(cutout.zmag - old_zp) > 0.3:
        logging.warn("Large change in zeropoint detected: {}  -> {}".format(old_zp, cutout.zmag))

    try:
        PHOT = cutout.get_observed_magnitude(centroid=not skip_centroids and mpc_obs.note1 != "H")
        x = PHOT['XCENTER']
        y = PHOT['YCENTER']
        mag = PHOT['MAG']
        merr = PHOT['MERR']
        cutout.update_pixel_location((x, y), hdu_index=cutout.extno)
        x, y = cutout.observed_source_point
    except Exception as ex:
        logging.error("ERROR: {}".format(str(ex)))
        return mpc_obs

    try:
        if mpc_obs.comment.mag_uncertainty is not None and mpc_obs.comment.mag is not None and math.fabs(mpc_obs.comment.mag - mag) > 3.5 * mpc_obs.comment.mag_uncertainty:
           logging.warn("recomputed magnitude shift large: {} --> {}".format(mpc_obs.mag, mag[0]))
        if math.sqrt((x.value - mpc_obs.comment.x) ** 2 + (y.value - mpc_obs.comment.y) ** 2) > 1.9:
            logging.warn("Centroid shifted ({},{}) -> ({},{})".format(mpc_obs.comment.x,
                                                                      mpc_obs.comment.y,
                                                                      x.value,
                                                                      y.value))
    except Exception as ex:
        logging.error(str(ex))

    # Don't use the new X/Y for Hand measured entries.  (although call to get_observed_magnitude should have changed)
    if str(mpc_obs.note1) != "H" and not skip_centroids:
        mpc_obs.comment.x = x.value
        mpc_obs.comment.y = y.value

    try:
        mag = float(mag)
    except:
        return mpc_obs

    if math.isnan(mag):
        return mpc_obs

    if mag > 10:
        mpc_obs._band = filter_value
        mpc_obs.comment.mag = mag
        mpc_obs.comment.mag_uncertainty = merr

    # Update the mpc record magnitude if previous value existed here.
    if (mpc_obs.mag is not None or (mpc_obs.mag is None and mpc_in.comment.photometry_note[0] == "Z")) and mag > 10:
        mpc_obs.mag = mag

    return mpc_obs
198034
private void encodeThis() throws IOException {
        if (require == -1 && inhibit == -1) {
            this.extensionValue = null;
            return;
        }
        DerOutputStream tagged = new DerOutputStream();
        DerOutputStream seq = new DerOutputStream();

        if (require != -1) {
            DerOutputStream tmp = new DerOutputStream();
            tmp.putInteger(require);
            tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                         false, TAG_REQUIRE), tmp);
        }
        if (inhibit != -1) {
            DerOutputStream tmp = new DerOutputStream();
            tmp.putInteger(inhibit);
            tagged.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT,
                         false, TAG_INHIBIT), tmp);
        }
        seq.write(DerValue.tag_Sequence, tagged);
        this.extensionValue = seq.toByteArray();
    }
20149
private static String decode(ShapeStyle style) {
		String css = "";
		if (style.getFillColor() != null && !"".equals(style.getFillColor())) {
			css += "fill:" + style.getFillColor() + ";";
		}
		css += "fill-opacity:" + style.getFillOpacity() + ";";
		if (style.getStrokeColor() != null && !"".equals(style.getStrokeColor())) {
			css += "stroke:" + style.getStrokeColor() + ";";
		}
		css += "stroke-opacity:" + style.getStrokeOpacity() + ";";
		if (style.getStrokeWidth() >= 0) {
			css += "stroke-width:" + style.getStrokeWidth() + ";";
		}
		return css;
	}
77085
def _handle_tag_defineshape4(self):
        """"""
        obj = _make_object("DefineShape4")
        obj.ShapeId = unpack_ui16(self._src)
        obj.ShapeBounds = self._get_struct_rect()
        obj.EdgeBounds = self._get_struct_rect()

        bc = BitConsumer(self._src)
        bc.u_get(5)  # reserved
        obj.UsesFillWindingRule = bc.u_get(1)
        obj.UsesNonScalingStrokes = bc.u_get(1)
        obj.UsesScalingStrokes = bc.u_get(1)
        obj.Shapes = self._get_struct_shapewithstyle(4)
        return obj