How to use _reset method in tox

Best Python code snippet using tox_python

rgb_controlled_nested.py

Source:rgb_controlled_nested.py Github

copy

Full Screen

1# ----------------------------------------------------------------------------------------------------------------------2# - Package Imports -3# ----------------------------------------------------------------------------------------------------------------------4# General Packages5from __future__ import annotations6# Custom Library7# Custom Packages8from AthenaColor.models.color_system import RGB,HEX, normalize_rgb9from AthenaColor.functions.ansi_sequences import color_sequence_nested10from AthenaColor.models.console.styling.rgb_controlled import RgbControlled11# ----------------------------------------------------------------------------------------------------------------------12# - Code -13# ----------------------------------------------------------------------------------------------------------------------14NCS = color_sequence_nested # Done for slight speed increase15sep_=" "16# ----------------------------------------------------------------------------------------------------------------------17# - Support Code -18# ----------------------------------------------------------------------------------------------------------------------19class RgbControlledNested:20 __name__ = "RgbControlledNested"21 _inline_class:RgbControlled22 _reset:str23 __slots__ = ["_inline_class", "_reset"]24 def __init__(self, inline_class:RgbControlled, reset:str):25 self._inline_class = inline_class26 self._reset = reset27 # ------------------------------------------------------------------------------------------------------------------28 # - Methods -29 # ------------------------------------------------------------------------------------------------------------------30 def custom(self,*obj, color:RGB|HEX, sep=sep_) -> str:31 # Don't rely on init.stringSeparation as the ANSI code rely on it being a ';'32 return color_sequence_nested(obj, f"{self._inline_class.param_code}{';'.join(*color.export())}m", self._reset,33 sep=sep)34 def rgb(self, *obj, r:int,g:int,b:int, sep=sep_) -> str:35 # Don't rely on init.stringSeparation as the ANSI code rely on it being a ';'36 return color_sequence_nested(obj, f"{self._inline_class.param_code}{';'.join(*normalize_rgb(r, g, b))}m",37 self._reset, sep=sep)38 # ------------------------------------------------------------------------------------------------------------------39 # - HTML colors -40 # ------------------------------------------------------------------------------------------------------------------41 # No partial methods, as this was increase the speed impact 2-fold42 def Maroon(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Maroon,self._reset,sep)43 def DarkRed(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkRed,self._reset,sep)44 def Brown(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Brown,self._reset,sep)45 def Firebrick(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Firebrick,self._reset,sep)46 def Crimson(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Crimson,self._reset,sep)47 def Red(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Red,self._reset,sep)48 def Tomato(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Tomato,self._reset,sep)49 def Coral(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Coral,self._reset,sep)50 def IndianRed(self, *obj, sep=sep_): return NCS(obj,self._inline_class.IndianRed,self._reset,sep)51 def LightCoral(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightCoral,self._reset,sep)52 def DarkSalmon(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkSalmon,self._reset,sep)53 def Salmon(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Salmon,self._reset,sep)54 def LightSalmon(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightSalmon,self._reset,sep)55 def OrangeRed(self, *obj, sep=sep_): return NCS(obj,self._inline_class.OrangeRed,self._reset,sep)56 def DarkOrange(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkOrange,self._reset,sep)57 def Orange(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Orange,self._reset,sep)58 def Gold(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Gold,self._reset,sep)59 def DarkGoldenRod(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkGoldenRod,self._reset,sep)60 def GoldenRod(self, *obj, sep=sep_): return NCS(obj,self._inline_class.GoldenRod,self._reset,sep)61 def PaleGoldenRod(self, *obj, sep=sep_): return NCS(obj,self._inline_class.PaleGoldenRod,self._reset,sep)62 def DarkKhaki(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkKhaki,self._reset,sep)63 def Khaki(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Khaki,self._reset,sep)64 def Olive(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Olive,self._reset,sep)65 def Yellow(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Yellow,self._reset,sep)66 def YellowGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.YellowGreen,self._reset,sep)67 def DarkOliveGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkOliveGreen,self._reset,sep)68 def OliveDrab(self, *obj, sep=sep_): return NCS(obj,self._inline_class.OliveDrab,self._reset,sep)69 def LawnGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LawnGreen,self._reset,sep)70 def Chartreuse(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Chartreuse,self._reset,sep)71 def GreenYellow(self, *obj, sep=sep_): return NCS(obj,self._inline_class.GreenYellow,self._reset,sep)72 def DarkGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkGreen,self._reset,sep)73 def Green(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Green,self._reset,sep)74 def ForestGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.ForestGreen,self._reset,sep)75 def Lime(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Lime,self._reset,sep)76 def LimeGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LimeGreen,self._reset,sep)77 def LightGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightGreen,self._reset,sep)78 def PaleGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.PaleGreen,self._reset,sep)79 def DarkSeaGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkSeaGreen,self._reset,sep)80 def MediumSpringGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumSpringGreen,self._reset,sep)81 def SpringGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SpringGreen,self._reset,sep)82 def SeaGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SeaGreen,self._reset,sep)83 def MediumAquaMarine(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumAquaMarine,self._reset,sep)84 def MediumSeaGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumSeaGreen,self._reset,sep)85 def LightSeaGreen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightSeaGreen,self._reset,sep)86 def DarkSlateGray(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkSlateGray,self._reset,sep)87 def Teal(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Teal,self._reset,sep)88 def DarkCyan(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkCyan,self._reset,sep)89 def Aqua(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Aqua,self._reset,sep)90 def Cyan(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Cyan,self._reset,sep)91 def LightCyan(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightCyan,self._reset,sep)92 def DarkTurquoise(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkTurquoise,self._reset,sep)93 def Turquoise(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Turquoise,self._reset,sep)94 def MediumTurquoise(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumTurquoise,self._reset,sep)95 def PaleTurquoise(self, *obj, sep=sep_): return NCS(obj,self._inline_class.PaleTurquoise,self._reset,sep)96 def AquaMarine(self, *obj, sep=sep_): return NCS(obj,self._inline_class.AquaMarine,self._reset,sep)97 def PowderBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.PowderBlue,self._reset,sep)98 def CadetBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.CadetBlue,self._reset,sep)99 def SteelBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SteelBlue,self._reset,sep)100 def CornFlowerBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.CornFlowerBlue,self._reset,sep)101 def DeepSkyBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DeepSkyBlue,self._reset,sep)102 def DodgerBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DodgerBlue,self._reset,sep)103 def LightBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightBlue,self._reset,sep)104 def SkyBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SkyBlue,self._reset,sep)105 def LightSkyBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightSkyBlue,self._reset,sep)106 def MidnightBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MidnightBlue,self._reset,sep)107 def Navy(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Navy,self._reset,sep)108 def DarkBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkBlue,self._reset,sep)109 def MediumBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumBlue,self._reset,sep)110 def Blue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Blue,self._reset,sep)111 def RoyalBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.RoyalBlue,self._reset,sep)112 def BlueViolet(self, *obj, sep=sep_): return NCS(obj,self._inline_class.BlueViolet,self._reset,sep)113 def Indigo(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Indigo,self._reset,sep)114 def DarkSlateBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkSlateBlue,self._reset,sep)115 def SlateBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SlateBlue,self._reset,sep)116 def MediumSlateBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumSlateBlue,self._reset,sep)117 def MediumPurple(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumPurple,self._reset,sep)118 def DarkMagenta(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkMagenta,self._reset,sep)119 def DarkViolet(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkViolet,self._reset,sep)120 def DarkOrchid(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkOrchid,self._reset,sep)121 def MediumOrchid(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumOrchid,self._reset,sep)122 def Purple(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Purple,self._reset,sep)123 def Thistle(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Thistle,self._reset,sep)124 def Plum(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Plum,self._reset,sep)125 def Violet(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Violet,self._reset,sep)126 def Magenta(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Magenta,self._reset,sep)127 def Orchid(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Orchid,self._reset,sep)128 def MediumVioletRed(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MediumVioletRed,self._reset,sep)129 def PaleVioletRed(self, *obj, sep=sep_): return NCS(obj,self._inline_class.PaleVioletRed,self._reset,sep)130 def DeepPink(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DeepPink,self._reset,sep)131 def HotPink(self, *obj, sep=sep_): return NCS(obj,self._inline_class.HotPink,self._reset,sep)132 def LightPink(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightPink,self._reset,sep)133 def Pink(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Pink,self._reset,sep)134 def AntiqueWhite(self, *obj, sep=sep_): return NCS(obj,self._inline_class.AntiqueWhite,self._reset,sep)135 def Beige(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Beige,self._reset,sep)136 def Bisque(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Bisque,self._reset,sep)137 def BlanchedAlmond(self, *obj, sep=sep_): return NCS(obj,self._inline_class.BlanchedAlmond,self._reset,sep)138 def Wheat(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Wheat,self._reset,sep)139 def CornSilk(self, *obj, sep=sep_): return NCS(obj,self._inline_class.CornSilk,self._reset,sep)140 def LemonChiffon(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LemonChiffon,self._reset,sep)141 def LightGoldenRodYellow(self, *obj, sep=sep_):return NCS(obj,self._inline_class.LightGoldenRodYellow,self._reset,sep)142 def LightYellow(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightYellow,self._reset,sep)143 def SaddleBrown(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SaddleBrown,self._reset,sep)144 def Sienna(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Sienna,self._reset,sep)145 def Chocolate(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Chocolate,self._reset,sep)146 def Peru(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Peru,self._reset,sep)147 def SandyBrown(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SandyBrown,self._reset,sep)148 def BurlyWood(self, *obj, sep=sep_): return NCS(obj,self._inline_class.BurlyWood,self._reset,sep)149 def Tan(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Tan,self._reset,sep)150 def RosyBrown(self, *obj, sep=sep_): return NCS(obj,self._inline_class.RosyBrown,self._reset,sep)151 def Moccasin(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Moccasin,self._reset,sep)152 def NavajoWhite(self, *obj, sep=sep_): return NCS(obj,self._inline_class.NavajoWhite,self._reset,sep)153 def PeachPuff(self, *obj, sep=sep_): return NCS(obj,self._inline_class.PeachPuff,self._reset,sep)154 def MistyRose(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MistyRose,self._reset,sep)155 def LavenderBlush(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LavenderBlush,self._reset,sep)156 def Linen(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Linen,self._reset,sep)157 def OldLace(self, *obj, sep=sep_): return NCS(obj,self._inline_class.OldLace,self._reset,sep)158 def PapayaWhip(self, *obj, sep=sep_): return NCS(obj,self._inline_class.PapayaWhip,self._reset,sep)159 def WeaShell(self, *obj, sep=sep_): return NCS(obj,self._inline_class.WeaShell,self._reset,sep)160 def MintCream(self, *obj, sep=sep_): return NCS(obj,self._inline_class.MintCream,self._reset,sep)161 def SlateGray(self, *obj, sep=sep_): return NCS(obj,self._inline_class.SlateGray,self._reset,sep)162 def LightSlateGray(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightSlateGray,self._reset,sep)163 def LightSteelBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightSteelBlue,self._reset,sep)164 def Lavender(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Lavender,self._reset,sep)165 def FloralWhite(self, *obj, sep=sep_): return NCS(obj,self._inline_class.FloralWhite,self._reset,sep)166 def AliceBlue(self, *obj, sep=sep_): return NCS(obj,self._inline_class.AliceBlue,self._reset,sep)167 def GhostWhite(self, *obj, sep=sep_): return NCS(obj,self._inline_class.GhostWhite,self._reset,sep)168 def Honeydew(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Honeydew,self._reset,sep)169 def Ivory(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Ivory,self._reset,sep)170 def Azure(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Azure,self._reset,sep)171 def Snow(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Snow,self._reset,sep)172 def Black(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Black,self._reset,sep)173 def DimGray(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DimGray,self._reset,sep)174 def Gray(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Gray,self._reset,sep)175 def DarkGray(self, *obj, sep=sep_): return NCS(obj,self._inline_class.DarkGray,self._reset,sep)176 def Silver(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Silver,self._reset,sep)177 def LightGray(self, *obj, sep=sep_): return NCS(obj,self._inline_class.LightGray,self._reset,sep)178 def Gainsboro(self, *obj, sep=sep_): return NCS(obj,self._inline_class.Gainsboro,self._reset,sep)179 def WhiteSmoke(self, *obj, sep=sep_): return NCS(obj,self._inline_class.WhiteSmoke,self._reset,sep)...

Full Screen

Full Screen

grammar_parser.py

Source:grammar_parser.py Github

copy

Full Screen

...44 and45 (_endmarker := self.expect('ENDMARKER'))46 ):47 return grammar48 self._reset(mark)49 return None50 @memoize51 def grammar(self) -> Optional[Grammar]:52 # grammar: metas rules | rules53 mark = self._mark()54 if (55 (metas := self.metas())56 and57 (rules := self.rules())58 ):59 return Grammar ( rules , metas )60 self._reset(mark)61 if (62 (rules := self.rules())63 ):64 return Grammar ( rules , [] )65 self._reset(mark)66 return None67 @memoize68 def metas(self) -> Optional[MetaList]:69 # metas: meta metas | meta70 mark = self._mark()71 if (72 (meta := self.meta())73 and74 (metas := self.metas())75 ):76 return [meta] + metas77 self._reset(mark)78 if (79 (meta := self.meta())80 ):81 return [meta]82 self._reset(mark)83 return None84 @memoize85 def meta(self) -> Optional[MetaTuple]:86 # meta: "@" NAME NEWLINE | "@" NAME NAME NEWLINE | "@" NAME STRING NEWLINE87 mark = self._mark()88 if (89 (literal := self.expect("@"))90 and91 (name := self.name())92 and93 (_newline := self.expect('NEWLINE'))94 ):95 return ( name . string , None )96 self._reset(mark)97 if (98 (literal := self.expect("@"))99 and100 (a := self.name())101 and102 (b := self.name())103 and104 (_newline := self.expect('NEWLINE'))105 ):106 return ( a . string , b . string )107 self._reset(mark)108 if (109 (literal := self.expect("@"))110 and111 (name := self.name())112 and113 (string := self.string())114 and115 (_newline := self.expect('NEWLINE'))116 ):117 return ( name . string , literal_eval ( string . string ) )118 self._reset(mark)119 return None120 @memoize121 def rules(self) -> Optional[RuleList]:122 # rules: rule rules | rule123 mark = self._mark()124 if (125 (rule := self.rule())126 and127 (rules := self.rules())128 ):129 return [rule] + rules130 self._reset(mark)131 if (132 (rule := self.rule())133 ):134 return [rule]135 self._reset(mark)136 return None137 @memoize138 def rule(self) -> Optional[Rule]:139 # rule: rulename memoflag? ":" alts NEWLINE INDENT more_alts DEDENT | rulename memoflag? ":" NEWLINE INDENT more_alts DEDENT | rulename memoflag? ":" alts NEWLINE140 mark = self._mark()141 if (142 (rulename := self.rulename())143 and144 (opt := self.memoflag(),)145 and146 (literal := self.expect(":"))147 and148 (alts := self.alts())149 and150 (_newline := self.expect('NEWLINE'))151 and152 (_indent := self.expect('INDENT'))153 and154 (more_alts := self.more_alts())155 and156 (_dedent := self.expect('DEDENT'))157 ):158 return Rule ( rulename [0] , rulename [1] , Rhs ( alts . alts + more_alts . alts ) , memo = opt )159 self._reset(mark)160 if (161 (rulename := self.rulename())162 and163 (opt := self.memoflag(),)164 and165 (literal := self.expect(":"))166 and167 (_newline := self.expect('NEWLINE'))168 and169 (_indent := self.expect('INDENT'))170 and171 (more_alts := self.more_alts())172 and173 (_dedent := self.expect('DEDENT'))174 ):175 return Rule ( rulename [0] , rulename [1] , more_alts , memo = opt )176 self._reset(mark)177 if (178 (rulename := self.rulename())179 and180 (opt := self.memoflag(),)181 and182 (literal := self.expect(":"))183 and184 (alts := self.alts())185 and186 (_newline := self.expect('NEWLINE'))187 ):188 return Rule ( rulename [0] , rulename [1] , alts , memo = opt )189 self._reset(mark)190 return None191 @memoize192 def rulename(self) -> Optional[RuleName]:193 # rulename: NAME annotation | NAME194 mark = self._mark()195 if (196 (name := self.name())197 and198 (annotation := self.annotation())199 ):200 return ( name . string , annotation )201 self._reset(mark)202 if (203 (name := self.name())204 ):205 return ( name . string , None )206 self._reset(mark)207 return None208 @memoize209 def memoflag(self) -> Optional[str]:210 # memoflag: '(' "memo" ')'211 mark = self._mark()212 if (213 (literal := self.expect('('))214 and215 (literal_1 := self.expect("memo"))216 and217 (literal_2 := self.expect(')'))218 ):219 return "memo"220 self._reset(mark)221 return None222 @memoize223 def alts(self) -> Optional[Rhs]:224 # alts: alt "|" alts | alt225 mark = self._mark()226 if (227 (alt := self.alt())228 and229 (literal := self.expect("|"))230 and231 (alts := self.alts())232 ):233 return Rhs ( [alt] + alts . alts )234 self._reset(mark)235 if (236 (alt := self.alt())237 ):238 return Rhs ( [alt] )239 self._reset(mark)240 return None241 @memoize242 def more_alts(self) -> Optional[Rhs]:243 # more_alts: "|" alts NEWLINE more_alts | "|" alts NEWLINE244 mark = self._mark()245 if (246 (literal := self.expect("|"))247 and248 (alts := self.alts())249 and250 (_newline := self.expect('NEWLINE'))251 and252 (more_alts := self.more_alts())253 ):254 return Rhs ( alts . alts + more_alts . alts )255 self._reset(mark)256 if (257 (literal := self.expect("|"))258 and259 (alts := self.alts())260 and261 (_newline := self.expect('NEWLINE'))262 ):263 return Rhs ( alts . alts )264 self._reset(mark)265 return None266 @memoize267 def alt(self) -> Optional[Alt]:268 # alt: items '$' action | items '$' | items action | items269 mark = self._mark()270 if (271 (items := self.items())272 and273 (literal := self.expect('$'))274 and275 (action := self.action())276 ):277 return Alt ( items + [NamedItem ( None , NameLeaf ( 'ENDMARKER' ) )] , action = action )278 self._reset(mark)279 if (280 (items := self.items())281 and282 (literal := self.expect('$'))283 ):284 return Alt ( items + [NamedItem ( None , NameLeaf ( 'ENDMARKER' ) )] , action = None )285 self._reset(mark)286 if (287 (items := self.items())288 and289 (action := self.action())290 ):291 return Alt ( items , action = action )292 self._reset(mark)293 if (294 (items := self.items())295 ):296 return Alt ( items , action = None )297 self._reset(mark)298 return None299 @memoize300 def items(self) -> Optional[NamedItemList]:301 # items: named_item items | named_item302 mark = self._mark()303 if (304 (named_item := self.named_item())305 and306 (items := self.items())307 ):308 return [named_item] + items309 self._reset(mark)310 if (311 (named_item := self.named_item())312 ):313 return [named_item]314 self._reset(mark)315 return None316 @memoize317 def named_item(self) -> Optional[NamedItem]:318 # named_item: NAME annotation '=' ~ item | NAME '=' ~ item | item | forced_atom | lookahead319 mark = self._mark()320 cut = False321 if (322 (name := self.name())323 and324 (annotation := self.annotation())325 and326 (literal := self.expect('='))327 and328 (cut := True)329 and330 (item := self.item())331 ):332 return NamedItem ( name . string , item , annotation )333 self._reset(mark)334 if cut: return None335 cut = False336 if (337 (name := self.name())338 and339 (literal := self.expect('='))340 and341 (cut := True)342 and343 (item := self.item())344 ):345 return NamedItem ( name . string , item )346 self._reset(mark)347 if cut: return None348 if (349 (item := self.item())350 ):351 return NamedItem ( None , item )352 self._reset(mark)353 if (354 (forced := self.forced_atom())355 ):356 return NamedItem ( None , forced )357 self._reset(mark)358 if (359 (it := self.lookahead())360 ):361 return NamedItem ( None , it )362 self._reset(mark)363 return None364 @memoize365 def forced_atom(self) -> Optional[Forced]:366 # forced_atom: '&' '&' ~ atom367 mark = self._mark()368 cut = False369 if (370 (literal := self.expect('&'))371 and372 (literal_1 := self.expect('&'))373 and374 (cut := True)375 and376 (atom := self.atom())377 ):378 return Forced ( atom )379 self._reset(mark)380 if cut: return None381 return None382 @memoize383 def lookahead(self) -> Optional[LookaheadOrCut]:384 # lookahead: '&' ~ atom | '!' ~ atom | '~'385 mark = self._mark()386 cut = False387 if (388 (literal := self.expect('&'))389 and390 (cut := True)391 and392 (atom := self.atom())393 ):394 return PositiveLookahead ( atom )395 self._reset(mark)396 if cut: return None397 cut = False398 if (399 (literal := self.expect('!'))400 and401 (cut := True)402 and403 (atom := self.atom())404 ):405 return NegativeLookahead ( atom )406 self._reset(mark)407 if cut: return None408 if (409 (literal := self.expect('~'))410 ):411 return Cut ( )412 self._reset(mark)413 return None414 @memoize415 def item(self) -> Optional[Item]:416 # item: '[' ~ alts ']' | atom '?' | atom '*' | atom '+' | atom '.' atom '+' | atom417 mark = self._mark()418 cut = False419 if (420 (literal := self.expect('['))421 and422 (cut := True)423 and424 (alts := self.alts())425 and426 (literal_1 := self.expect(']'))427 ):428 return Opt ( alts )429 self._reset(mark)430 if cut: return None431 if (432 (atom := self.atom())433 and434 (literal := self.expect('?'))435 ):436 return Opt ( atom )437 self._reset(mark)438 if (439 (atom := self.atom())440 and441 (literal := self.expect('*'))442 ):443 return Repeat0 ( atom )444 self._reset(mark)445 if (446 (atom := self.atom())447 and448 (literal := self.expect('+'))449 ):450 return Repeat1 ( atom )451 self._reset(mark)452 if (453 (sep := self.atom())454 and455 (literal := self.expect('.'))456 and457 (node := self.atom())458 and459 (literal_1 := self.expect('+'))460 ):461 return Gather ( sep , node )462 self._reset(mark)463 if (464 (atom := self.atom())465 ):466 return atom467 self._reset(mark)468 return None469 @memoize470 def atom(self) -> Optional[Plain]:471 # atom: '(' ~ alts ')' | NAME | STRING472 mark = self._mark()473 cut = False474 if (475 (literal := self.expect('('))476 and477 (cut := True)478 and479 (alts := self.alts())480 and481 (literal_1 := self.expect(')'))482 ):483 return Group ( alts )484 self._reset(mark)485 if cut: return None486 if (487 (name := self.name())488 ):489 return NameLeaf ( name . string )490 self._reset(mark)491 if (492 (string := self.string())493 ):494 return StringLeaf ( string . string )495 self._reset(mark)496 return None497 @memoize498 def action(self) -> Optional[str]:499 # action: "{" ~ target_atoms "}"500 mark = self._mark()501 cut = False502 if (503 (literal := self.expect("{"))504 and505 (cut := True)506 and507 (target_atoms := self.target_atoms())508 and509 (literal_1 := self.expect("}"))510 ):511 return target_atoms512 self._reset(mark)513 if cut: return None514 return None515 @memoize516 def annotation(self) -> Optional[str]:517 # annotation: "[" ~ target_atoms "]"518 mark = self._mark()519 cut = False520 if (521 (literal := self.expect("["))522 and523 (cut := True)524 and525 (target_atoms := self.target_atoms())526 and527 (literal_1 := self.expect("]"))528 ):529 return target_atoms530 self._reset(mark)531 if cut: return None532 return None533 @memoize534 def target_atoms(self) -> Optional[str]:535 # target_atoms: target_atom target_atoms | target_atom536 mark = self._mark()537 if (538 (target_atom := self.target_atom())539 and540 (target_atoms := self.target_atoms())541 ):542 return target_atom + " " + target_atoms543 self._reset(mark)544 if (545 (target_atom := self.target_atom())546 ):547 return target_atom548 self._reset(mark)549 return None550 @memoize551 def target_atom(self) -> Optional[str]:552 # target_atom: "{" ~ target_atoms? "}" | "[" ~ target_atoms? "]" | NAME "*" | NAME | NUMBER | STRING | "?" | ":" | !"}" !"]" OP553 mark = self._mark()554 cut = False555 if (556 (literal := self.expect("{"))557 and558 (cut := True)559 and560 (atoms := self.target_atoms(),)561 and562 (literal_1 := self.expect("}"))563 ):564 return "{" + ( atoms or "" ) + "}"565 self._reset(mark)566 if cut: return None567 cut = False568 if (569 (literal := self.expect("["))570 and571 (cut := True)572 and573 (atoms := self.target_atoms(),)574 and575 (literal_1 := self.expect("]"))576 ):577 return "[" + ( atoms or "" ) + "]"578 self._reset(mark)579 if cut: return None580 if (581 (name := self.name())582 and583 (literal := self.expect("*"))584 ):585 return name . string + "*"586 self._reset(mark)587 if (588 (name := self.name())589 ):590 return name . string591 self._reset(mark)592 if (593 (number := self.number())594 ):595 return number . string596 self._reset(mark)597 if (598 (string := self.string())599 ):600 return string . string601 self._reset(mark)602 if (603 (literal := self.expect("?"))604 ):605 return "?"606 self._reset(mark)607 if (608 (literal := self.expect(":"))609 ):610 return ":"611 self._reset(mark)612 if (613 self.negative_lookahead(self.expect, "}")614 and615 self.negative_lookahead(self.expect, "]")616 and617 (op := self.op())618 ):619 return op . string620 self._reset(mark)621 return None622 KEYWORDS = ()623 SOFT_KEYWORDS = ('memo',)624if __name__ == '__main__':625 from pegen.parser import simple_parser_main...

Full Screen

Full Screen

ansi.py

Source:ansi.py Github

copy

Full Screen

1def _esc(val):2 return f'\033[{val}'34class ansi:56 CLEARLINE = _esc('2K')7 CURSOR_UP = _esc('1A')8 HIDE_CURSOR = _esc('?25l')9 SHOW_CURSOR = _esc('?25h')1011 _reset = _esc('0m')12 _bold = _esc('1m')13 _italic = _esc('3m')14 _underline = _esc('4m')1516 class fg:17 black = _esc('30m')18 red = _esc('31m')19 green = _esc('32m')20 yellow = _esc('33m')21 blue = _esc('34m')22 magenta = _esc('35m')23 cyan = _esc('36m')24 white = _esc('37m')2526 def rgb(r, g, b):27 return _esc(f'38;2;{r};{g};{b}m')2829 class bg:30 black = _esc('40m')31 red = _esc('41m')32 green = _esc('42m')33 yellow = _esc('43m')34 blue = _esc('44m')35 magenta = _esc('45m')36 cyan = _esc('46m')37 white = _esc('47m')3839 def rgb(r, g, b):40 return _esc(f'48;2;{r};{g};{b}m')4142 def __init__(self, string):43 self._string = string4445 def __str__(self):46 return self._string4748 def __add__(self, other):49 return self._string + other5051 def bold(self):52 return ansi._bold + self._string + ansi._reset5354 def italic(self):55 return ansi._italic + self._string + ansi._reset5657 def underline(self):58 return ansi._underline + self._string + ansi._reset5960 def rgb(self, r=0, g=0, b=0, bg=False):61 if bg:62 return ansi.bg.rgb(r, g, b) + self._string + ansi._reset6364 return ansi.fg.rgb(r, g, b) + self._string + ansi._reset6566 def black(self, fg=True):67 if fg:68 return ansi.fg.black + self._string + ansi._reset69 70 return ansi.bg.black + self._string + ansi._reset7172 def red(self, fg=True):73 if fg:74 return ansi.fg.red + self._string + ansi._reset75 76 return ansi.bg.red + self._string + ansi._reset7778 def green(self, fg=True):79 if fg:80 return ansi.fg.green + self._string + ansi._reset81 82 return ansi.bg.green + self._string + ansi._reset8384 def yellow(self, fg=True):85 if fg:86 return ansi.fg.yellow + self._string + ansi._reset87 88 return ansi.bg.yellow + self._string + ansi._reset8990 def blue(self, fg=True):91 if fg:92 return ansi.fg.blue + self._string + ansi._reset93 94 return ansi.bg.blue + self._string + ansi._reset9596 def magenta(self, fg=True):97 if fg:98 return ansi.fg.magenta + self._string + ansi._reset99 100 return ansi.bg.magenta + self._string + ansi._reset101102 def cyan(self, fg=True):103 if fg:104 return ansi.fg.cyan + self._string + ansi._reset105 106 return ansi.bg.cyan + self._string + ansi._reset107108 def white(self, fg=True):109 if fg:110 return ansi.fg.white + self._string + ansi._reset111 112 return ansi.bg.white + self._string + ansi._reset113114 def gray(self, fg=True):115 if fg:116 return self.rgb(150, 150, 150)117 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful