666.
(a) Notwithstanding Section 490, every person who, having been convicted three or more times of petty theft, grand theft, a conviction pursuant to subdivision (d) or (e) of Section 368, auto theft under Section 10851 of the Vehicle Code, burglary, carjacking, robbery, or a felony violation of Section 496, and having served a term therefor in any penal institution or having been imprisoned therein as a condition of probation for that offense, and who is subsequently convicted of petty theft, is punishable by imprisonment in a county jail not exceeding one year, or imprisonment pursuant to subdivision (h) of Section 1170.(a) (b) Notwithstanding Section 490, any person described in subdivision (b) paragraph (1) who, having been convicted of petty theft, grand theft, a conviction pursuant to subdivision (d) or (e) of Section 368, auto theft under Section 10851 of the Vehicle Code, burglary, carjacking, robbery, or a felony violation of Section 496, and having served a term of imprisonment therefor in any penal institution or having been imprisoned therein as a condition of probation for that offense, and who is subsequently convicted of petty theft, is punishable by imprisonment in the county jail not exceeding one year, or in the state prison.
(b) (1) Subdivision (a) This subdivision shall apply to any person who is required to register pursuant to the Sex Offender Registration Act, or who has a prior violent or serious felony conviction, as specified in clause (iv) of subparagraph (C) of paragraph (2) of subdivision (e) of Section 667, or has a conviction pursuant to subdivision (d) or (e) of Section 368. subdivision (c) of Section 667.5 or subdivision (c) of Section 1192.7.
(c) (2) This section subdivision shall not be construed to preclude prosecution or punishment pursuant to subdivisions (b) to (i), inclusive, of Section 667, or Section 1170.12.
(c) (1) The court may, when it is in the interests of justice, order a person convicted of a felony violation of subdivision (a) or (b) to complete a licensed drug rehabilitation program in lieu of part or all of any term of imprisonment. As a condition of that sentence, the court may require the offender to pay all or a portion of the drug rehabilitation program, to the extent the offender is financially able to do so.
(2) Paragraph (1) does not prevent deferred entry of judgment or a defendant’s participation in a preguilty plea drug court program under Chapter 2.5 (commencing with Section 1000) of Title 6 of Part 2 unless the person is charged with violating subdivision (b) or (c) of Section 243.