pydrepr/drepr/models/path.py
def to_lang_format(self, use_json_path: bool = False) -> Union[list, str]:
        """
        Convert this Path object into the path object in the D-REPR language

        :param use_json_path: whether we should use the JSONPath or our new notation
        :return:
        """
        if use_json_path:
            jpath = ["$"]
            for step in self.steps:
                if isinstance(step, RangeExpr):
                    if any(isinstance(v, Expr) for v in [step.start, step.end, step.step]):
                        raise NotImplementedError("Haven't supported JSONPath with expression yet")
                    jpath.append(f"[{step.start}:{step.end or ''}:{step.step}]")
                elif isinstance(step, IndexExpr):
                    if isinstance(step.val, str):
                        jpath.append(f"['{step.val}']")
                    else:
                        jpath.append(f"[{step.val}]")
                elif isinstance(step, SetIndexExpr):
                    raise NotImplementedError()
                else:
                    jpath.append(f".{step.value}")
            return "".join(jpath)

        path = []
        for step in self.steps:
            if isinstance(step, RangeExpr):
                start, end, step = [
                    "" if v is None else (
                        f"${{{v.expr}}}" if isinstance(v, Expr) else v
                    )
                    for v in [step.start, step.end, step.step]
                ]
                path.append(f"{start}..{end}:{step}")
            elif isinstance(step, IndexExpr):
                path.append(step.val)
            elif isinstance(step, SetIndexExpr):
                path.append(step.vals)
            elif isinstance(step, WildcardExpr):
                path.append(step.value)
            else:
                raise NotImplementedError()
        return path

        Convert this Path object into the path object in the D-REPR language

        :param use_json_path: whether we should use the JSONPath or our new notation
        :return:
        
Convert this Path object into the path object in the D-REPR language
Convert this Path object into the path object in the D - REPR language
def to_lang_format(self, use_json_path: bool = False) -> Union[list, str]:
        if use_json_path:
            jpath = ["$"]
            for step in self.steps:
                if isinstance(step, RangeExpr):
                    if any(isinstance(v, Expr) for v in [step.start, step.end, step.step]):
                        raise NotImplementedError("Haven't supported JSONPath with expression yet")
                    jpath.append(f"[{step.start}:{step.end or ''}:{step.step}]")
                elif isinstance(step, IndexExpr):
                    if isinstance(step.val, str):
                        jpath.append(f"['{step.val}']")
                    else:
                        jpath.append(f"[{step.val}]")
                elif isinstance(step, SetIndexExpr):
                    raise NotImplementedError()
                else:
                    jpath.append(f".{step.value}")
            return "".join(jpath)
        path = []
        for step in self.steps:
            if isinstance(step, RangeExpr):
                start, end, step = [
                    "" if v is None else (
                        f"${{{v.expr}}}" if isinstance(v, Expr) else v
                    )
                    for v in [step.start, step.end, step.step]
                ]
                path.append(f"{start}..{end}:{step}")
            elif isinstance(step, IndexExpr):
                path.append(step.val)
            elif isinstance(step, SetIndexExpr):
                path.append(step.vals)
            elif isinstance(step, WildcardExpr):
                path.append(step.value)
            else:
                raise NotImplementedError()
        return path
def to_lang_format ( self , use_json_path : bool = False ) -> Union [ list , str ] : if use_json_path : jpath = [ "$" ] for step in self . steps : if isinstance ( step , RangeExpr ) : if any ( isinstance ( v , Expr ) for v in [ step . start , step . end , step . step ] ) : raise NotImplementedError ( "Haven't supported JSONPath with expression yet" ) jpath . append ( f"[{step.start}:{step.end or ''}:{step.step}]" ) elif isinstance ( step , IndexExpr ) : if isinstance ( step . val , str ) : jpath . append ( f"['{step.val}']" ) else : jpath . append ( f"[{step.val}]" ) elif isinstance ( step , SetIndexExpr ) : raise NotImplementedError ( ) else : jpath . append ( f".{step.value}" ) return "" . join ( jpath ) path = [ ] for step in self . steps : if isinstance ( step , RangeExpr ) : start , end , step = [ "" if v is None else ( f"${{{v.expr}}}" if isinstance ( v , Expr ) else v ) for v in [ step . start , step . end , step . step ] ] path . append ( f"{start}..{end}:{step}" ) elif isinstance ( step , IndexExpr ) : path . append ( step . val ) elif isinstance ( step , SetIndexExpr ) : path . append ( step . vals ) elif isinstance ( step , WildcardExpr ) : path . append ( step . value ) else : raise NotImplementedError ( ) return path
Convert this Path object into the path object in the D-REPR language
Convert this Path object into the path object in the D - REPR language
"""
        Convert this Path object into the path object in the D-REPR language

        :param use_json_path: whether we should use the JSONPath or our new notation
        :return:
        """
None
self
use_json_path
bool
whether we should use the JSONPath or our new notation
whether we should use the JSONPath or our new notation