Author

Topic: new coin for everyone coming !! Join community now (Read 174 times)

hero member
Activity: 2856
Merit: 644
https://duelbits.com/
I am developing the website and writing the code right now.

I am overwhelmed by the community response and thus would speed up my work so I can show so better results to you all.


Thank you for your time and patience.

Warm Regards,
CyberPunk

You should first develop the website and other social media links so we can clearly see the information.
Don't write threads first and that code is not understood by everyone.
I hope you do it well.
newbie
Activity: 4
Merit: 0
I am developing the website and writing the code right now.

I am overwhelmed by the community response and thus would speed up my work so I can show so better results to you all.


Thank you for your time and patience.

Warm Regards,
CyberPunk
hero member
Activity: 2744
Merit: 541
Campaign Management?"Hhampuz" is the Man
just like everyone's asking,can you please explain further?can you create ANN thread for formality and cleaner format?

this is not the right way to post if you really want your project to be known,this is very cheap and wont attract rightful investors in future.
i am afraid that with your formatting only bad image will bring to your team and currency.

looking forward for more and much better approach.
sr. member
Activity: 1022
Merit: 252
I think you shouldn't share the code of a coin directly like this because someone can copy it and make the similiar one. I don't know those lines of code are important or no but you better do it on pastebin and just copy the link to here for better thread
sr. member
Activity: 756
Merit: 251
More than the code, could you please tell us about the coin and the project itself. Codes are very important in cryptocurrency projects. They are particularly what other people are looking for when buying a new coin. But there are many people here who do not have enough knowledge on codes. They will have to be presented with the project whitepaper, roadmap, coin economy and other details, and so on. They need to know the people that build the coin as well.
full member
Activity: 1176
Merit: 104
No further details about the project, maybe at least tell us if there is any telegram channel for this or maybe, any social channel to give us more information about it! I don't understand what you are talking about OP but if you can at least edit this post maybe, community will get more insights about this!
hero member
Activity: 2660
Merit: 551
What the hell is this one? You should tell us what's this new privacy coin is all about.

Not everyone here is a coder to understand what's going on from behind. I know your excitement about it, but please you also need the understand where the community here, give us the details and not lines of codes.
full member
Activity: 1232
Merit: 143
Very vague this topic of yours. What is the purpose of this? What is it about? Coins for everyone, who? When will they release more information?
hero member
Activity: 3150
Merit: 636
DGbet.fun - Crypto Sportsbook
Dude, I didn't read your whole post after seeing that there's a bunch of code in it.

try to use "Insert code" function.
@OP use the forum code function since you have posted a code..

It's like this..

Quote
[code ]
~your code here~
[/code ]

remove space

hero member
Activity: 2128
Merit: 530
PredX - AI-Powered Prediction Market
I think the developer is putting out the code for verification, which I think is good and could help in building transparencies and fairness in the project, but it is not started how to join the community, there is no name, no social media link or anything about the team, there still need for more information on some of the things highlighted here
copper member
Activity: 490
Merit: 2
I thought that anonymous crypto currencies will not have a bright future, because such coins would be never adopted and are very likely to be restricted by governments. But it seems like anonymous currencies are in trend, so wish you the best of luck.
legendary
Activity: 2282
Merit: 1041
I think you should say the idea of the project instead of putting a long piece of code on your post, because I'm not a coder and can't understand the language. But I have a question why are you posting the code here? You know that private coins can easily be hacked by hackers if they are aware of your security system. Monero, Dash have been hacked in many cases and stolen millions of dollars. So to secure the future of your private coin, you should delete the code and tell us more about this coin's information.

Codes of the project are usually available for critical examination of anyone interested which is why developers are asked to share the github links. Project has to be opensource that anyone can edit and own it for themselves.

I am however curious why he share it here while saying nothing how to acquire the said coins, if it has potentials which I believe he is confident in showing his code, I think I'd give it a try.

Is it CENTECHAIN?  No website yet?
sr. member
Activity: 854
Merit: 253
l0tt0.com
I think you should say the idea of the project instead of putting a long piece of code on your post, because I'm not a coder and can't understand the language. But I have a question why are you posting the code here? You know that private coins can easily be hacked by hackers if they are aware of your security system. Monero, Dash have been hacked in many cases and stolen millions of dollars. So to secure the future of your private coin, you should delete the code and tell us more about this coin's information.
sr. member
Activity: 1274
Merit: 263
It took so many spaces copy-pasting it directly, try to use "Insert code" function.
and it will become like this;
Code:
enerate_class_string(typename, props, description, namespace):
    """Dynamically generate class strings to have nicely formatted docstrings,
    keyword arguments, and repr.
  
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    string
    """
    # TODO _prop_names, _type, _namespace, and available_properties
    # can be modified by a Dash JS developer via setattr
    # TODO - Tab out the repr for the repr of these components to make it
    # look more like a hierarchical tree
    # TODO - Include "description" "defaultValue" in the repr and docstring
    #
    # TODO - Handle "required"
    #
    # TODO - How to handle user-given `null` values? I want to include
    # an expanded docstring like Dropdown(value=None, id=None)
    # but by templating in those None values, I have no way of knowing
    # whether a property is None because the user explicitly wanted
    # it to be `null` or whether that was just the default value.
    # The solution might be to deal with default values better although
    # not all component authors will supply those.
    c = '''class {typename}(Component):
    """{docstring}"""
    @_explicitize_args
    def __init__(self, {default_argtext}):
        self._prop_names = {list_of_valid_keys}
        self._type = '{typename}'
        self._namespace = '{namespace}'
        self._valid_wildcard_attributes =\
            {list_of_valid_wildcard_attr_prefixes}
        self.available_properties = {list_of_valid_keys}
        self.available_wildcard_properties =\
            {list_of_valid_wildcard_attr_prefixes}
        _explicit_args = kwargs.pop('_explicit_args')
        _locals = locals()
        _locals.update(kwargs)  # For wildcard attrs
        args = {{k: _locals[k] for k in _explicit_args if k != 'children'}}
        for k in {required_props}:
            if k not in args:
                raise TypeError(
                    'Required argument `' + k + '` was not specified.')
        super({typename}, self).__init__({argtext})
'''

    filtered_props = reorder_props(filter_props(props))
    wildcard_prefixes = repr(parse_wildcards(props))
    list_of_valid_keys = repr(list(map(str, filtered_props.keys())))
    docstring = create_docstring(
        component_name=typename,
        props=filtered_props,
        description=description).replace('\r\n', '\n')

    prohibit_events(props)

    # pylint: disable=unused-variable
    prop_keys = list(props.keys())
    if 'children' in props:
        prop_keys.remove('children')
        default_argtext = "children=None, "
        argtext = 'children=children, **args'
    else:
        default_argtext = ""
        argtext = '**args'
    default_argtext += ", ".join(
        [('{:s}=Component.REQUIRED'.format(p)
          if props[p]['required'] else
          '{:s}=Component.UNDEFINED'.format(p))
         for p in prop_keys
         if not p.endswith("-*") and
         p not in python_keywords and
         p != 'setProps'] + ["**kwargs"]
    )
    required_args = required_props(props)
    return c.format(
        typename=typename,
        namespace=namespace,
        filtered_props=filtered_props,
        list_of_valid_wildcard_attr_prefixes=wildcard_prefixes,
        list_of_valid_keys=list_of_valid_keys,
        docstring=docstring,
        default_argtext=default_argtext,
        argtext=argtext,
        required_props=required_args
    )


def generate_class_file(typename, props, description, namespace):
    """Generate a python class file (.py) given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    """
    import_string =\
        "# AUTO GENERATED FILE - DO NOT EDIT\n\n" + \
        "from dash.development.base_component import " + \
        "Component, _explicitize_args\n\n\n"
    class_string = generate_class_string(
        typename,
        props,
        description,
        namespace
    )
    file_name = "{:s}.py".format(typename)

    file_path = os.path.join(namespace, file_name)
    with open(file_path, 'w') as f:
        f.write(import_string)
        f.write(class_string)

    print('Generated {}'.format(file_name))


def generate_imports(project_shortname, components):
    with open(os.path.join(project_shortname, '_imports_.py'), 'w') as f:
        imports_string = '{}\n\n{}'.format(
            '\n'.join(
                'from .{0} import {0}'.format(x) for x in components),
            '__all__ = [\n{}\n]'.format(
                ',\n'.join('    "{}"'.format(x) for x in components))
        )

        f.write(imports_string)


def generate_classes_files(project_shortname, metadata, *component_generators):
    components = []
    for component_path, component_data in metadata.items():
        component_name = component_path.split('/')[-1].split('.')[0]
        components.append(component_name)

        for generator in component_generators:
            generator(
                component_name,
                component_data['props'],
                component_data['description'],
                project_shortname
            )

    return components


def generate_class(typename, props, description, namespace):
    """Generate a python class object given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    """
    string = generate_class_string(typename, props, description, namespace)
    scope = {'Component': Component, '_explicitize_args': _explicitize_args}
    # pylint: disable=exec-used
    exec(string, scope)
    result = scope[typename]
    return result


def required_props(props):
    """Pull names of required props from the props object.
    Parameters
    ----------
    props: dict
    Returns
    -------
    list
        List of prop names (str) that are required for the Component
    """
    return [prop_name for prop_name, prop in list(props.items())
            if prop['required']]


def create_docstring(component_name, props, description):
    """Create the Dash component docstring.
    Parameters
    ----------
    component_name: str
        Component name
    props: dict
        Dictionary with {propName: propMetadata} structure
    description: str
        Component description
    Returns
    -------
    str
        Dash component docstring
    """
    # Ensure props are ordered with children first
    props = reorder_props(props=props)

    return (
        """A{n} {name} component.\n{description}
Keyword arguments:\n{args}"""
    ).format(
        n='n' if component_name[0].lower() in ['a', 'e', 'i', 'o', 'u']
        else '',
        name=component_name,
        description=description,
        args='\n'.join(
            create_prop_docstring(
                prop_name=p,
                type_object=prop['type'] if 'type' in prop
                else prop['flowType'],
                required=prop['required'],
                description=prop['description'],
                default=prop.get('defaultValue'),
                indent_num=0,
                is_flow_type='flowType' in prop and 'type' not in prop)
            for p, prop in list(filter_props(props).items())))


def prohibit_events(props):
    """Events have been removed. Raise an error if we see dashEvents or
    fireEvents.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Raises
    -------
    ?
    """
    if 'dashEvents' in props or 'fireEvents' in props:
        raise NonExistentEventException(
            'Events are no longer supported by dash. Use properties instead, '
            'eg `n_clicks` instead of a `click` event.')


def parse_wildcards(props):
    """Pull out the wildcard attributes from the Component props.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    list
        List of Dash valid wildcard prefixes
    """
    list_of_valid_wildcard_attr_prefixes = []
    for wildcard_attr in ["data-*", "aria-*"]:
        if wildcard_attr in props:
            list_of_valid_wildcard_attr_prefixes.append(wildcard_attr[:-1])
    return list_of_valid_wildcard_attr_prefixes


def reorder_props(props):
    """If "children" is in props, then move it to the front to respect dash
    convention.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Dictionary with {propName: propMetadata} structure
    """
    if 'children' in props:
        # Constructing an OrderedDict with duplicate keys, you get the order
        # from the first one but the value from the last.
        # Doing this to avoid mutating props, which can cause confusion.
        props = OrderedDict([('children', '')] + list(props.items()))

    return props


def filter_props(props):
    """Filter props from the Component arguments to exclude:
        - Those without a "type" or a "flowType" field
        - Those with arg.type.name in {'func', 'symbol', 'instanceOf'}
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Filtered dictionary with {propName: propMetadata} structure
    Examples
    --------
    ```python
    prop_args = {
        'prop1': {
            'type': {'name': 'bool'},
            'required': False,
            'description': 'A description',
            'flowType': {},
            'defaultValue': {'value': 'false', 'computed': False},
        },
        'prop2': {'description': 'A prop without a type'},
        'prop3': {
            'type': {'name': 'func'},
            'description': 'A function prop',
        },
    }
    # filtered_prop_args is now
    # {
    #    'prop1': {
    #        'type': {'name': 'bool'},
    #        'required': False,
    #        'description': 'A description',
    #        'flowType': {},
    #        'defaultValue': {'value': 'false', 'computed': False},
    #    },
    # }
    filtered_prop_args = filter_props(prop_args)
    ```
    """
    filtered_props = copy.deepcopy(props)

    for arg_name, arg in list(filtered_props.items()):
        if 'type' not in arg and 'flowType' not in arg:
            filtered_props.pop(arg_name)
            continue

        # Filter out functions and instances --
        # these cannot be passed from Python
        if 'type' in arg:  # These come from PropTypes
            arg_type = arg['type']['name']
            if arg_type in {'func', 'symbol', 'instanceOf'}:
                filtered_props.pop(arg_name)
        elif 'flowType' in arg:  # These come from Flow & handled differently
            arg_type_name = arg['flowType']['name']
            if arg_type_name == 'signature':
                # This does the same as the PropTypes filter above, but "func"
                # is under "type" if "name" is "signature" vs just in "name"
                if 'type' not in arg['flowType'] \
                        or arg['flowType']['type'] != 'object':
                    filtered_props.pop(arg_name)
        else:
            raise ValueError

    return filtered_props


# pylint: disable=too-many-arguments
def create_prop_docstring(prop_name, type_object, required, description,
                          default, indent_num, is_flow_type=False):
    """Create the Dash component prop docstring.
    Parameters
    ----------
    prop_name: str
        Name of the Dash component prop
    type_object: dict
        react-docgen-generated prop type dictionary
    required: bool
        Component is required?
    description: str
        Dash component description
    default: dict
        Either None if a default value is not defined, or
        dict containing the key 'value' that defines a
        default value for the prop
    indent_num: int
        Number of indents to use for the context block
        (creates 2 spaces for every indent)
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    Returns
    -------
    str
        Dash component prop docstring
    """
    py_type_name = js_to_py_type(
        type_object=type_object,
        is_flow_type=is_flow_type,
        indent_num=indent_num + 1)
    indent_spacing = '  ' * indent_num

    if default is None:
        default = ''
    else:
        default = default['value']

    if default in ['true', 'false']:
        default = default.title()

    is_required = 'optional'
    if required:
        is_required = 'required'
    elif default and default not in ['null', '{}', '[]']:
        is_required = 'default {}'.format(
            default.replace('\n', '\n' + indent_spacing)
        )

    if '\n' in py_type_name:
        return '{indent_spacing}- {name} (dict; {is_required}): ' \
            '{description}{period}' \
            '{name} has the following type: {type}'.format(
                indent_spacing=indent_spacing,
                name=prop_name,
                type=py_type_name,
                description=description.strip().strip('.'),
                period='. ' if description else '',
                is_required=is_required)
    return '{indent_spacing}- {name} ({type}' \
        '{is_required}){description}'.format(
            indent_spacing=indent_spacing,
            name=prop_name,
            type='{}; '.format(py_type_name) if py_type_name else '',
            description=(
                ': {}'.format(description) if description != '' else ''
            ),
            is_required=is_required)


def map_js_to_py_types_prop_types(type_object):
    """Mapping from the PropTypes js type object to the Python type."""

    def shape_or_exact():
        return 'dict containing keys {}.\n{}'.format(
            ', '.join(
                "'{}'".format(t) for t in list(type_object['value'].keys())
            ),
            'Those keys have the following types:\n{}'.format(
                '\n'.join(
                    create_prop_docstring(
                        prop_name=prop_name,
                        type_object=prop,
                        required=prop['required'],
                        description=prop.get('description', ''),
                        default=prop.get('defaultValue'),
                        indent_num=1
                    ) for prop_name, prop in
                    list(type_object['value'].items())))
            )

    return dict(
        array=lambda: 'list',
        bool=lambda: 'boolean',
        number=lambda: 'number',
        string=lambda: 'string',
        object=lambda: 'dict',
        any=lambda: 'boolean | number | string | dict | list',
        element=lambda: 'dash component',
        node=lambda: 'a list of or a singular dash '
                     'component, string or number',

        # React's PropTypes.oneOf
        enum=lambda: 'a value equal to: {}'.format(
            ', '.join(
                '{}'.format(str(t['value']))
                for t in type_object['value'])),

        # React's PropTypes.oneOfType
        union=lambda: '{}'.format(
            ' | '.join(
                '{}'.format(js_to_py_type(subType))
                for subType in type_object['value']
                if js_to_py_type(subType) != '')),

        # React's PropTypes.arrayOf
        arrayOf=lambda: (
            "list" + (" of {}".format(
                js_to_py_type(type_object["value"]) + 's'
                if js_to_py_type(type_object["value"]).split(' ')[0] != 'dict'
                else js_to_py_type(type_object["value"]).replace(
                        'dict', 'dicts', 1
                )
            )
                      if js_to_py_type(type_object["value"]) != ""
                      else "")
        ),

        # React's PropTypes.objectOf
        objectOf=lambda: (
            'dict with strings as keys and values of type {}'
            ).format(
                js_to_py_type(type_object['value'])),

        # React's PropTypes.shape
        shape=shape_or_exact,
        # React's PropTypes.exact
        exact=shape_or_exact
    )


def map_js_to_py_types_flow_types(type_object):
    """Mapping from the Flow js types to the Python type."""

    return dict(
        array=lambda: 'list',
        boolean=lambda: 'boolean',
        number=lambda: 'number',
        string=lambda: 'string',
        Object=lambda: 'dict',
        any=lambda: 'bool | number | str | dict | list',
        Element=lambda: 'dash component',
        Node=lambda: 'a list of or a singular dash '
                     'component, string or number',

        # React's PropTypes.oneOfType
        union=lambda: '{}'.format(
            ' | '.join(
                '{}'.format(js_to_py_type(subType))
                for subType in type_object['elements']
                if js_to_py_type(subType) != '')),

        # Flow's Array type
        Array=lambda: 'list{}'.format(
            ' of {}s'.format(
                js_to_py_type(type_object['elements'][0]))
            if js_to_py_type(type_object['elements'][0]) != ''
            else ''),

        # React's PropTypes.shape
        signature=lambda indent_num: 'dict containing keys {}.\n{}'.format(
            ', '.join("'{}'".format(d['key'])
                      for d in type_object['signature']['properties']),
            '{}Those keys have the following types:\n{}'.format(
                '  ' * indent_num,
                '\n'.join(
                    create_prop_docstring(
                        prop_name=prop['key'],
                        type_object=prop['value'],
                        required=prop['value']['required'],
                        description=prop['value'].get('description', ''),
                        default=prop.get('defaultValue'),
                        indent_num=indent_num,
                        is_flow_type=True)
                    for prop in type_object['signature']['properties']))),
    )


def js_to_py_type(type_object, is_flow_type=False, indent_num=0):
    """Convert JS types to Python types for the component definition.
    Parameters
    ----------
    type_object: dict
        react-docgen-generated prop type dictionary
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    indent_num: int
        Number of indents to use for the docstring for the prop

how to join the community if you do not tell us how to do it?
hero member
Activity: 1302
Merit: 577
avatar and signature space for rent !!!
Sorry i dont understand coe  Grin . How member can really claim the free coins can you explain and also add details .
Private crypto currency not a token ? So it means we need to download the wallet where is the wallet link?
newbie
Activity: 4
Merit: 0
Hello everyone

A new private cryptocurrency is coming for everyone. It is time to participate in the coin distribution and development system then the coin would be distributed to everyone.

enerate_class_string(typename, props, description, namespace):
    """Dynamically generate class strings to have nicely formatted docstrings,
    keyword arguments, and repr.
   
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    string
    """
    # TODO _prop_names, _type, _namespace, and available_properties
    # can be modified by a Dash JS developer via setattr
    # TODO - Tab out the repr for the repr of these components to make it
    # look more like a hierarchical tree
    # TODO - Include "description" "defaultValue" in the repr and docstring
    #
    # TODO - Handle "required"
    #
    # TODO - How to handle user-given `null` values? I want to include
    # an expanded docstring like Dropdown(value=None, id=None)
    # but by templating in those None values, I have no way of knowing
    # whether a property is None because the user explicitly wanted
    # it to be `null` or whether that was just the default value.
    # The solution might be to deal with default values better although
    # not all component authors will supply those.
    c = '''class {typename}(Component):
    """{docstring}"""
    @_explicitize_args
    def __init__(self, {default_argtext}):
        self._prop_names = {list_of_valid_keys}
        self._type = '{typename}'
        self._namespace = '{namespace}'
        self._valid_wildcard_attributes =\
            {list_of_valid_wildcard_attr_prefixes}
        self.available_properties = {list_of_valid_keys}
        self.available_wildcard_properties =\
            {list_of_valid_wildcard_attr_prefixes}
        _explicit_args = kwargs.pop('_explicit_args')
        _locals = locals()
        _locals.update(kwargs)  # For wildcard attrs
        args = {{k: _locals[k] for k in _explicit_args if k != 'children'}}
        for k in {required_props}:
            if k not in args:
                raise TypeError(
                    'Required argument `' + k + '` was not specified.')
        super({typename}, self).__init__({argtext})
'''

    filtered_props = reorder_props(filter_props(props))
    wildcard_prefixes = repr(parse_wildcards(props))
    list_of_valid_keys = repr(list(map(str, filtered_props.keys())))
    docstring = create_docstring(
        component_name=typename,
        props=filtered_props,
        description=description).replace('\r\n', '\n')

    prohibit_events(props)

    # pylint: disable=unused-variable
    prop_keys = list(props.keys())
    if 'children' in props:
        prop_keys.remove('children')
        default_argtext = "children=None, "
        argtext = 'children=children, **args'
    else:
        default_argtext = ""
        argtext = '**args'
    default_argtext += ", ".join(
        [('{:s}=Component.REQUIRED'.format(p)
          if props[p]['required'] else
          '{:s}=Component.UNDEFINED'.format(p))
         for p in prop_keys
         if not p.endswith("-*") and
         p not in python_keywords and
         p != 'setProps'] + ["**kwargs"]
    )
    required_args = required_props(props)
    return c.format(
        typename=typename,
        namespace=namespace,
        filtered_props=filtered_props,
        list_of_valid_wildcard_attr_prefixes=wildcard_prefixes,
        list_of_valid_keys=list_of_valid_keys,
        docstring=docstring,
        default_argtext=default_argtext,
        argtext=argtext,
        required_props=required_args
    )


def generate_class_file(typename, props, description, namespace):
    """Generate a python class file (.py) given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    """
    import_string =\
        "# AUTO GENERATED FILE - DO NOT EDIT\n\n" + \
        "from dash.development.base_component import " + \
        "Component, _explicitize_args\n\n\n"
    class_string = generate_class_string(
        typename,
        props,
        description,
        namespace
    )
    file_name = "{:s}.py".format(typename)

    file_path = os.path.join(namespace, file_name)
    with open(file_path, 'w') as f:
        f.write(import_string)
        f.write(class_string)

    print('Generated {}'.format(file_name))


def generate_imports(project_shortname, components):
    with open(os.path.join(project_shortname, '_imports_.py'), 'w') as f:
        imports_string = '{}\n\n{}'.format(
            '\n'.join(
                'from .{0} import {0}'.format(x) for x in components),
            '__all__ = [\n{}\n]'.format(
                ',\n'.join('    "{}"'.format(x) for x in components))
        )

        f.write(imports_string)


def generate_classes_files(project_shortname, metadata, *component_generators):
    components = []
    for component_path, component_data in metadata.items():
        component_name = component_path.split('/')[-1].split('.')[0]
        components.append(component_name)

        for generator in component_generators:
            generator(
                component_name,
                component_data['props'],
                component_data['description'],
                project_shortname
            )

    return components


def generate_class(typename, props, description, namespace):
    """Generate a python class object given a class string.
    Parameters
    ----------
    typename
    props
    description
    namespace
    Returns
    -------
    """
    string = generate_class_string(typename, props, description, namespace)
    scope = {'Component': Component, '_explicitize_args': _explicitize_args}
    # pylint: disable=exec-used
    exec(string, scope)
    result = scope[typename]
    return result


def required_props(props):
    """Pull names of required props from the props object.
    Parameters
    ----------
    props: dict
    Returns
    -------
    list
        List of prop names (str) that are required for the Component
    """
    return [prop_name for prop_name, prop in list(props.items())
            if prop['required']]


def create_docstring(component_name, props, description):
    """Create the Dash component docstring.
    Parameters
    ----------
    component_name: str
        Component name
    props: dict
        Dictionary with {propName: propMetadata} structure
    description: str
        Component description
    Returns
    -------
    str
        Dash component docstring
    """
    # Ensure props are ordered with children first
    props = reorder_props(props=props)

    return (
        """A{n} {name} component.\n{description}
Keyword arguments:\n{args}"""
    ).format(
        n='n' if component_name[0].lower() in ['a', 'e', 'i', 'o', 'u']
        else '',
        name=component_name,
        description=description,
        args='\n'.join(
            create_prop_docstring(
                prop_name=p,
                type_object=prop['type'] if 'type' in prop
                else prop['flowType'],
                required=prop['required'],
                description=prop['description'],
                default=prop.get('defaultValue'),
                indent_num=0,
                is_flow_type='flowType' in prop and 'type' not in prop)
            for p, prop in list(filter_props(props).items())))


def prohibit_events(props):
    """Events have been removed. Raise an error if we see dashEvents or
    fireEvents.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Raises
    -------
    ?
    """
    if 'dashEvents' in props or 'fireEvents' in props:
        raise NonExistentEventException(
            'Events are no longer supported by dash. Use properties instead, '
            'eg `n_clicks` instead of a `click` event.')


def parse_wildcards(props):
    """Pull out the wildcard attributes from the Component props.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    list
        List of Dash valid wildcard prefixes
    """
    list_of_valid_wildcard_attr_prefixes = []
    for wildcard_attr in ["data-*", "aria-*"]:
        if wildcard_attr in props:
            list_of_valid_wildcard_attr_prefixes.append(wildcard_attr[:-1])
    return list_of_valid_wildcard_attr_prefixes


def reorder_props(props):
    """If "children" is in props, then move it to the front to respect dash
    convention.
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Dictionary with {propName: propMetadata} structure
    """
    if 'children' in props:
        # Constructing an OrderedDict with duplicate keys, you get the order
        # from the first one but the value from the last.
        # Doing this to avoid mutating props, which can cause confusion.
        props = OrderedDict([('children', '')] + list(props.items()))

    return props


def filter_props(props):
    """Filter props from the Component arguments to exclude:
        - Those without a "type" or a "flowType" field
        - Those with arg.type.name in {'func', 'symbol', 'instanceOf'}
    Parameters
    ----------
    props: dict
        Dictionary with {propName: propMetadata} structure
    Returns
    -------
    dict
        Filtered dictionary with {propName: propMetadata} structure
    Examples
    --------
    ```python
    prop_args = {
        'prop1': {
            'type': {'name': 'bool'},
            'required': False,
            'description': 'A description',
            'flowType': {},
            'defaultValue': {'value': 'false', 'computed': False},
        },
        'prop2': {'description': 'A prop without a type'},
        'prop3': {
            'type': {'name': 'func'},
            'description': 'A function prop',
        },
    }
    # filtered_prop_args is now
    # {
    #    'prop1': {
    #        'type': {'name': 'bool'},
    #        'required': False,
    #        'description': 'A description',
    #        'flowType': {},
    #        'defaultValue': {'value': 'false', 'computed': False},
    #    },
    # }
    filtered_prop_args = filter_props(prop_args)
    ```
    """
    filtered_props = copy.deepcopy(props)

    for arg_name, arg in list(filtered_props.items()):
        if 'type' not in arg and 'flowType' not in arg:
            filtered_props.pop(arg_name)
            continue

        # Filter out functions and instances --
        # these cannot be passed from Python
        if 'type' in arg:  # These come from PropTypes
            arg_type = arg['type']['name']
            if arg_type in {'func', 'symbol', 'instanceOf'}:
                filtered_props.pop(arg_name)
        elif 'flowType' in arg:  # These come from Flow & handled differently
            arg_type_name = arg['flowType']['name']
            if arg_type_name == 'signature':
                # This does the same as the PropTypes filter above, but "func"
                # is under "type" if "name" is "signature" vs just in "name"
                if 'type' not in arg['flowType'] \
                        or arg['flowType']['type'] != 'object':
                    filtered_props.pop(arg_name)
        else:
            raise ValueError

    return filtered_props


# pylint: disable=too-many-arguments
def create_prop_docstring(prop_name, type_object, required, description,
                          default, indent_num, is_flow_type=False):
    """Create the Dash component prop docstring.
    Parameters
    ----------
    prop_name: str
        Name of the Dash component prop
    type_object: dict
        react-docgen-generated prop type dictionary
    required: bool
        Component is required?
    description: str
        Dash component description
    default: dict
        Either None if a default value is not defined, or
        dict containing the key 'value' that defines a
        default value for the prop
    indent_num: int
        Number of indents to use for the context block
        (creates 2 spaces for every indent)
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    Returns
    -------
    str
        Dash component prop docstring
    """
    py_type_name = js_to_py_type(
        type_object=type_object,
        is_flow_type=is_flow_type,
        indent_num=indent_num + 1)
    indent_spacing = '  ' * indent_num

    if default is None:
        default = ''
    else:
        default = default['value']

    if default in ['true', 'false']:
        default = default.title()

    is_required = 'optional'
    if required:
        is_required = 'required'
    elif default and default not in ['null', '{}', '[]']:
        is_required = 'default {}'.format(
            default.replace('\n', '\n' + indent_spacing)
        )

    if '\n' in py_type_name:
        return '{indent_spacing}- {name} (dict; {is_required}): ' \
            '{description}{period}' \
            '{name} has the following type: {type}'.format(
                indent_spacing=indent_spacing,
                name=prop_name,
                type=py_type_name,
                description=description.strip().strip('.'),
                period='. ' if description else '',
                is_required=is_required)
    return '{indent_spacing}- {name} ({type}' \
        '{is_required}){description}'.format(
            indent_spacing=indent_spacing,
            name=prop_name,
            type='{}; '.format(py_type_name) if py_type_name else '',
            description=(
                ': {}'.format(description) if description != '' else ''
            ),
            is_required=is_required)


def map_js_to_py_types_prop_types(type_object):
    """Mapping from the PropTypes js type object to the Python type."""

    def shape_or_exact():
        return 'dict containing keys {}.\n{}'.format(
            ', '.join(
                "'{}'".format(t) for t in list(type_object['value'].keys())
            ),
            'Those keys have the following types:\n{}'.format(
                '\n'.join(
                    create_prop_docstring(
                        prop_name=prop_name,
                        type_object=prop,
                        required=prop['required'],
                        description=prop.get('description', ''),
                        default=prop.get('defaultValue'),
                        indent_num=1
                    ) for prop_name, prop in
                    list(type_object['value'].items())))
            )

    return dict(
        array=lambda: 'list',
        bool=lambda: 'boolean',
        number=lambda: 'number',
        string=lambda: 'string',
        object=lambda: 'dict',
        any=lambda: 'boolean | number | string | dict | list',
        element=lambda: 'dash component',
        node=lambda: 'a list of or a singular dash '
                     'component, string or number',

        # React's PropTypes.oneOf
        enum=lambda: 'a value equal to: {}'.format(
            ', '.join(
                '{}'.format(str(t['value']))
                for t in type_object['value'])),

        # React's PropTypes.oneOfType
        union=lambda: '{}'.format(
            ' | '.join(
                '{}'.format(js_to_py_type(subType))
                for subType in type_object['value']
                if js_to_py_type(subType) != '')),

        # React's PropTypes.arrayOf
        arrayOf=lambda: (
            "list" + (" of {}".format(
                js_to_py_type(type_object["value"]) + 's'
                if js_to_py_type(type_object["value"]).split(' ')[0] != 'dict'
                else js_to_py_type(type_object["value"]).replace(
                        'dict', 'dicts', 1
                )
            )
                      if js_to_py_type(type_object["value"]) != ""
                      else "")
        ),

        # React's PropTypes.objectOf
        objectOf=lambda: (
            'dict with strings as keys and values of type {}'
            ).format(
                js_to_py_type(type_object['value'])),

        # React's PropTypes.shape
        shape=shape_or_exact,
        # React's PropTypes.exact
        exact=shape_or_exact
    )


def map_js_to_py_types_flow_types(type_object):
    """Mapping from the Flow js types to the Python type."""

    return dict(
        array=lambda: 'list',
        boolean=lambda: 'boolean',
        number=lambda: 'number',
        string=lambda: 'string',
        Object=lambda: 'dict',
        any=lambda: 'bool | number | str | dict | list',
        Element=lambda: 'dash component',
        Node=lambda: 'a list of or a singular dash '
                     'component, string or number',

        # React's PropTypes.oneOfType
        union=lambda: '{}'.format(
            ' | '.join(
                '{}'.format(js_to_py_type(subType))
                for subType in type_object['elements']
                if js_to_py_type(subType) != '')),

        # Flow's Array type
        Array=lambda: 'list{}'.format(
            ' of {}s'.format(
                js_to_py_type(type_object['elements'][0]))
            if js_to_py_type(type_object['elements'][0]) != ''
            else ''),

        # React's PropTypes.shape
        signature=lambda indent_num: 'dict containing keys {}.\n{}'.format(
            ', '.join("'{}'".format(d['key'])
                      for d in type_object['signature']['properties']),
            '{}Those keys have the following types:\n{}'.format(
                '  ' * indent_num,
                '\n'.join(
                    create_prop_docstring(
                        prop_name=prop['key'],
                        type_object=prop['value'],
                        required=prop['value']['required'],
                        description=prop['value'].get('description', ''),
                        default=prop.get('defaultValue'),
                        indent_num=indent_num,
                        is_flow_type=True)
                    for prop in type_object['signature']['properties']))),
    )


def js_to_py_type(type_object, is_flow_type=False, indent_num=0):
    """Convert JS types to Python types for the component definition.
    Parameters
    ----------
    type_object: dict
        react-docgen-generated prop type dictionary
    is_flow_type: bool
        Does the prop use Flow types? Otherwise, uses PropTypes
    indent_num: int
        Number of indents to use for the docstring for the prop

Jump to: