Converts the limit angle of the PyPot JSON file to the internal format
13234
def _convert_angle_limit(angle, joint, **kwargs):
    """"""
    angle_pypot = angle

    # No need to take care of orientation
    if joint["orientation"] == "indirect":
        angle_pypot = 1 * angle_pypot

    # angle_pypot = angle_pypot + offset

    return angle_pypot * np.pi / 180
713097
def _convert_2_0_0_alpha(topo, topo_path):
    
    topo["revision"] = 6
    for node in topo.get("topology", {}).get("nodes", []):
        if node.get("console_type") == "serial":
            node["console_type"] = "telnet"
        if node["node_type"] in ("vmware", "virtualbox"):
            prop = node.get("properties")
            if "enable_remote_console" in prop:
                del prop["enable_remote_console"]
    return topo
775148
def toString(self):
        
        slist = self.toList()
        string = angle.slistStr(slist)
        return string if slist[0] == '-' else string[1:]
811183
def dumpJSON(self):
        
        numexp = self.number.get()
        expTime, _, _, _, _ = self.timing()
        if numexp == 0:
            numexp = -1

        data = dict(
            numexp=self.number.value(),
            app=self.app.value(),
            led_flsh=self.led(),
            dummy_out=self.dummy(),
            fast_clks=self.fastClk(),
            readout=self.readSpeed(),
            dwell=self.expose.value(),
            exptime=expTime,
            oscan=self.oscan(),
            oscany=self.oscany(),
            xbin=self.wframe.xbin.value(),
            ybin=self.wframe.ybin.value(),
            multipliers=self.nmult.getall(),
            clear=self.clear()
        )

        # only allow nodding in clear mode, even if GUI has got confused
        if data['clear'] and self.nodPattern:
            data['nodpattern'] = self.nodPattern

        # no mixing clear and multipliers, no matter what GUI says
        if data['clear']:
            data['multipliers'] = [1 for i in self.nmult.getall()]

        # add window mode
        if not self.isFF():
            if self.isDrift():
                # no clear, multipliers or oscan in drift
                for setting in ('clear', 'oscan', 'oscany'):
                    data[setting] = 0
                data['multipliers'] = [1 for i in self.nmult.getall()]

                for iw, (xsl, xsr, ys, nx, ny) in enumerate(self.wframe):
                    data['x{}start_left'.format(iw+1)] = xsl
                    data['x{}start_right'.format(iw+1)] = xsr
                    data['y{}start'.format(iw+1)] = ys
                    data['y{}size'.format(iw+1)] = ny
                    data['x{}size'.format(iw+1)] = nx
            else:
                # no oscany in window mode
                data['oscany'] = 0

                for iw, (xsll, xsul, xslr, xsur, ys, nx, ny) in enumerate(self.wframe):
                    data['x{}start_upperleft'.format(iw+1)] = xsul
                    data['x{}start_lowerleft'.format(iw+1)] = xsll
                    data['x{}start_upperright'.format(iw+1)] = xsur
                    data['x{}start_lowerright'.format(iw+1)] = xslr
                    data['y{}start'.format(iw+1)] = ys
                    data['x{}size'.format(iw+1)] = nx
                    data['y{}size'.format(iw+1)] = ny
        return data
943521
def load_json(filename, gzip_mode=False):
    ''''''

    open_file = open
    if gzip_mode:
        open_file = gzip.open

    try:
        with open_file(filename, 'rt') as fh:
            data = json.load(fh)
            data = convert_unicode_2_utf8(data)
            return data
    except AttributeError:
        # Python-2.6
        fh = open_file(filename, 'rt')
        data = json.load(fh)
        fh.close()
        data = convert_unicode_2_utf8(data)
        return data
924799
def jsonify(o, max_depth=-1, parse_enums=PARSE_KEEP):
    
    if max_depth == 0:
        return o
    max_depth -= 1
    if isinstance(o, dict):
        keyattrs = getattr(o.__class__, '_altnames', {})

        def _getter(key, value):
            key = keyattrs.get(key, key)
            other = getattr(o, key, value)
            if callable(other):
                other = value
            if isinstance(key, Enum):  # Make sure we use a name as the key... if we don't it might mess some things up.
                key = key.name
            return key, jsonify(other, max_depth=max_depth, parse_enums=parse_enums)

        return dict(_getter(key, value) for key, value in six.iteritems(o))
    elif isinstance(o, list):
        return [jsonify(x, max_depth=max_depth, parse_enums=parse_enums) for x in o]
    elif isinstance(o, tuple):
        return (jsonify(x, max_depth=max_depth, parse_enums=parse_enums) for x in o)
    elif isinstance(o, Enum):
        o = _parse_enum(o, parse_enums=parse_enums)
    return o
726170
def to_json(self, indent=None, sort_keys=True):
        
        return json.dumps(self.to_dict(), indent=indent, sort_keys=sort_keys)
983101
def to_json(self, indent=2):
        
        return json.dumps(self, default=json_encode_for_printing, indent=indent)
1293513
def _jsonify(x):
    """"""
    if isinstance(x, dict_class):
        return json.dumps(x._d, separators=(',', ':'))
    return json.dumps(x, separators=(',', ':'))
927576
def pp_obj(obj, out_path=None, indent=4, sort_keys=False, ensure_ascii=False, default=None):
    
    rt = anyjson.dumps(obj, sort_keys=sort_keys, indent=indent, ensure_ascii=ensure_ascii,
                       separators=(',', ': '), default=default, namedtuple_as_object=False)
    # unicode_available
    if out_path is None:
        return rt
    else:
        with open(out_path, 'w') as out:
            out.write(rt)
1229641
def eval_from_json(json):
        
        close  = json[-1]['close'] # Latest closing price
        low    = min(poloniex.get_attribute(json, 'low')) # Lowest low
        high   = max(poloniex.get_attribute(json, 'high')) # Highest high
        return SO.eval_algorithm(close, low, high)
727798
def _format_json(self, ans, q):
        
        params = {}
        try: params['indent'] = int(q.get('indent')[0])
        except: pass

        return json.dumps(ans, **params)+'\n'
699050
def _format_ret(self, full_ret):
        '''
        
        '''
        ret = {}
        out = ''
        retcode = 0
        for key, data in six.iteritems(full_ret):
            ret[key] = data['ret']
            if 'out' in data:
                out = data['out']
            ret_retcode = self._get_retcode(data)
            if ret_retcode > retcode:
                retcode = ret_retcode
        return ret, out, retcode
486824
def tojson(val, indent=None):
    '''
    
    '''
    options = {'ensure_ascii': True}
    if indent is not None:
        options['indent'] = indent
    return (
        salt.utils.json.dumps(
            val, **options
        ).replace('<', '\\u003c')
         .replace('>', '\\u003e')
         .replace('&', '\\u0026')
         .replace("'", '\\u0027')
    )
520927
def pformat(
    object,
    indent=_UNSET_SENTINEL,
    width=_UNSET_SENTINEL,
    depth=_UNSET_SENTINEL,
    *,
    ribbon_width=_UNSET_SENTINEL,
    max_seq_len=_UNSET_SENTINEL,
    compact=_UNSET_SENTINEL,
    sort_dict_keys=_UNSET_SENTINEL
):
    
    sdocs = python_to_sdocs(
        object,
        **_merge_defaults(
            indent=indent,
            width=width,
            depth=depth,
            ribbon_width=ribbon_width,
            max_seq_len=max_seq_len,
            sort_dict_keys=sort_dict_keys,
        )
    )
    stream = StringIO()
    default_render_to_stream(stream, sdocs)
    return stream.getvalue()
1076738
def _write_json(filepath, data, kwargs):
    """"""
    with io_stl.open(filepath, 'w', encoding='utf8') as outfile:
        if 'indent' not in kwargs:
            kwargs['indent'] = 4
        if 'sort_keys' not in kwargs:
            kwargs['sort_keys'] = True
        if 'separators' not in kwargs:
            kwargs['separators'] = (',', ': ')
        if 'ensure_ascii' not in kwargs:
            kwargs['ensure_ascii'] = False
        str_ = json.dumps(data, **kwargs)
        outfile.write(to_unicode(str_))
    return data
1053716
def load_json_path(path):
    """"""
    with open(path) as handle:
        try: return json.load(handle, object_pairs_hook=collections.OrderedDict)
        except ValueError as error:
            message = "Could not decode JSON file '%s'." % path
            message = "-"*20 + "\n" + message + "\n" + str(error) + "\n" + "-"*20 + "\n"
            sys.stderr.write(message)
            raise error